Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

raster-algorithms

The document outlines algorithms for drawing lines, circles, and ellipses using the DDA line algorithm, Bresenham's line algorithm, and midpoint algorithms for circles and ellipses. It provides step-by-step procedures for calculating pixel positions based on input coordinates and decision parameters. The algorithms include symmetry considerations for efficient plotting in graphics programming.

Uploaded by

lanusha820
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

raster-algorithms

The document outlines algorithms for drawing lines, circles, and ellipses using the DDA line algorithm, Bresenham's line algorithm, and midpoint algorithms for circles and ellipses. It provides step-by-step procedures for calculating pixel positions based on input coordinates and decision parameters. The algorithms include symmetry considerations for efficient plotting in graphics programming.

Uploaded by

lanusha820
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Procedure for DDA line algorithm.

Void lineDDA (int xa, int ya, int xb, int yb)
{
int dx = xb – xa, dy = yb – ya, steps, k;
float xincrement, yincrement, x = xa, y = ya;
if (abs(dx)>abs(dy))
{
Steps = abs (dx);
}
else
{
Steps = abs (dy);
}
xincrement = dx/(float) steps;
yincrement = dy/(float) steps;

setpixel (ROUND (x), ROUND (y));


for(k=0;k<steps;k++)
{
x += xincrement;
y += yincrement;
setpixel (ROUND (x), ROUND (y));
}
}
Step 8. if ∆x>∆y(i.e. |m|<1)
BLA Algorithm calculate pk = 2∆y-∆x
for(k=0; k< ∆x; k++)
• Step 1. Start
if (pk<0)
• Step 2. Declare variables x1,y1,x2,y2, xk = xk+l
lx,ly,∆x, ∆y, pk yk = yk
pk = pk+2∆y
• Step 3. Read values of x1, y1,x2,y2 else
• Step 4. Calculate ∆x = absolute(x2-x1) xk = xk+l
yk = yk+l
∆y = absolute(y2-y1) pk = pk+2∆y-2∆x
• Step 5. if (x2>x1) plot(xk, yk)
else
assign lx = 1 calculate pk = 2∆x-∆y
else for(k=0; k< ∆x; k++)
if(pk<0)
assign lx = -1 xk = xk
• Step 6. if (y2-y1) yk = yk+l
pk = pk+2∆x
assign ly = 1 else
else xk = xk+l
yk = yk+l
assign ly = -1
pk = pk+2∆x2∆y
• Step 7. Plot (x1, y1) Plot(xk,yk)
Step 9. Stop
Algorithm for Midpoint Circle Generation
1. Input radius r and circle center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on the
circumference of a circle centered on the origin as
𝑥0 , 𝑦0 = (0, 𝑟)
2. calculate the initial value of the decision parameter as
𝑝0 = 1 − 𝑟
3. At each 𝑥𝑘 position, starting at 𝑘 = 0, perform the following test:
If 𝑝𝑘 < 0, the next point along the circle centered on (0, 0) is 𝑥𝑘 + 1, 𝑦𝑘 &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1
Otherwise, the next point along the circle is 𝑥𝑘 + 1, 𝑦𝑘 − 1 &
𝑝𝑘+1 = 𝑝𝑘 + 2𝑥𝑘+1 + 1 − 2𝑦𝑘+1
4. Determine symmetry points in the other seven octants.
5. Move each calculated pixel position (𝑥, 𝑦) onto the circular path centered on
(𝑥𝑐 , 𝑦𝑐 ) and plot the coordinate values:
𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐
6. Repeat steps 3 through 5 until 𝑥 ≥ 𝑦.
Algorithm for Midpoint Ellipse Generation
1. Input 𝑟𝑥 , 𝑟𝑦 and ellipse center (𝑥𝑐 , 𝑦𝑐 ), and obtain the first point on an ellipse
centered on the origin as
𝑥0 , 𝑦0 = (0, 𝑟𝑦 )

2. Calculate the initial value of the decision parameter in region 1 as


1
𝑝10 = 𝑟𝑦 2 − 𝑟𝑥 2 𝑟𝑦 + 𝑟𝑥 2
4

3. At each 𝑥𝑘 position in region 1, starting at 𝑘 = 0, perform the following test:


If 𝑝1𝑘 < 0, than the next point along the ellipse is (𝑥𝑘+1 , 𝑦𝑘 ) and
𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2

Otherwise, the next point along the ellipse is (𝑥𝑘+1 , 𝑦𝑘 − 1) and


𝑝1𝑘+1 = 𝑝1𝑘 + 2𝑟𝑦 2 𝑥𝑘+1 + 𝑟𝑦 2 − 2𝑟𝑥 2 𝑦𝑘+1
With
2𝑟𝑦 2 𝑥𝑘+1 = 2𝑟𝑦 2 𝑥𝑘 + 2𝑟𝑦 2 , 2𝑟𝑥 2 𝑦𝑘+1 = 2𝑟𝑥 2 𝑦𝑘 − 2𝑟𝑥 2
And continue until 2𝑟𝑦 2 𝑥 ≤ 2𝑟𝑥 2 𝑦
Contd.
4. Calculate the initial value of the decision parameter in region 2 using the last
point 𝑥0 , 𝑦0 calculated in region 1 as
2 1 2
𝑝20 = 𝑟𝑦 𝑥0 + + 𝑟𝑥 2 𝑦0 − 1 2 − 𝑟𝑥 2 𝑟𝑦 2
2

5. At each 𝑦𝑘 position in region-2, starting at 𝑘 = 0, perform the following test:


If 𝑝2𝑘 > 0, the next point along the ellipse is (𝑥𝑘 , 𝑦𝑘 − 1) and
𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2

Otherwise, the next point along the ellipse is (𝑥𝑘 + 1, 𝑦𝑘 − 1) and


𝑝2𝑘+1 = 𝑝2𝑘 − 2𝑟𝑥 2 𝑦𝑘+1 + 𝑟𝑥 2 + 2𝑟𝑦 2 𝑥𝑘+1
Using the same incremental calculations for 𝑥 and 𝑦 as in region 1.

6. Determine symmetry points in the other three quadrants.

7. Move each calculated pixel position (𝑥, 𝑦) onto the elliptical path centered on
(𝑥𝑐 , 𝑦𝑐 ) and plot the coordinate values:
𝑥 = 𝑥 + 𝑥𝑐 , 𝑦 = 𝑦 + 𝑦𝑐

8. Repeat the steps for region 2 until 𝑦𝑘 ≥ 0.

You might also like