Unit II Line and Circle Drawing
Unit II Line and Circle Drawing
DDA line drawing algorithm, Bresenham’s Line algorithm, Circle and elipse generating
algorithms- Midpoint Circle Algorithm, Midpoint Elipse Algorithm, Polynomials and spline
curves, Filling-Filed - Area Primitives, Scan-Line Polygon File Algorithm, Inside-Outside
Tests, Scan-Line File of Curved Boundary Areas, Boundary-File Algorithm, Flood-File
Algorithm.
= = = = = = == = == = = == = = = = = = = = = = = = = = = = == = = = = = = = = = = = = =
DDA line drawing algorithm (Digital Differential Analyzer)
DDA stands for Digital Differential Analyzer.
It is scanning conversion method to draw line.
DDA (Digital Differential Analyzer) is a line drawing algorithm used in computer
graphics to generate a line segment between two specified endpoints.
It is a simple and efficient algorithm that works by using the incremental difference
between the x-coordinates and y-coordinates of the two endpoints to plot the line.
To draw a line between A and B intermediate floating-point value is used. That is
intermediate pixel.
The straight-line equation is y=mx+b . Here m is the slope.
Line has two end points namely A ( x 1 , y 1 ) and B ( x2 , y 2 ).
y −y
Slope of the line is m= x 2−x 1
2 1
∆y d
m=
∆x
or m= d y
x
Step 3: Depending upon absolute value of∆ x , ∆ y ; choose number of steps to put pixel
between start point and end point
if |( ∆ x )|>|( ∆ y )|
steps=|(∆ x )|
else
steps=|(∆ y )|
Step 4: current point is ( x p , y p ) and next point is ( x p+ 1 , y p+1 )
Find the next point by following 3 cases:
Case 1: If m<1 Case 2: if m=1 Case 2: if m>1
1
x p+1=1+ x p x p+1=1+ x p x p+1= +x
m p
y p +1=m+ y p y p +1=1+ y p y p +1=1+ y p
Step 5: Repeat Step 4 until it reaches end -point.
The DDA algorithm is faster than the direct use of the line equation since it calculates points
on the line without any floating-point multiplication.
Example:
Start point (5,6) and End point (8,12)
∆ x = X n−X 0 ⟹ 8−5=3
∆ y =Y n −Y 0 ⟹ 12−6=6
∆y 6
m= ⟹ =2
∆x 3
Therefore m=2
Choose number of steps to put pixel between start point and end point
Therefore |( ∆ x )|<|( ∆ y )|=3<6
Steps=∆ y =6
Example 2
= = = = = = = = = == = = = = = = = = = = == = = = = = = = = = = = = = = = = = = = = = =
Step 2: Calculate ∆ x , ∆ y
∆ x = X n−X 0
∆ y =Y n −Y 0
Step 3: Calculate the decision parameter (to find exact point to draw a line)
pk =2 ∆ y −∆ x
Step 4: Suppose the current point is ( x k , y k ) and the next point is ( x k+ 1 , y k+ 1) . To find the next
point depending on value of decision parameter pk .
Case 1: if pk <0 ; pk +1= pk +2 ∆ y (next decision parameter)
x k+1 =x k +1
y k +1= y k
Case 2: if pk ≥ 0; the next decision parameter is: ; pk +1= pk +2 ∆ y −2 ∆ x
x k+1 =x k +1
y k +1= y k +1
Step 5: Repeat Step 4 until end point is reached.
Example
Step 1: Start coordinate value (X 0 , Y 0 ) = (9,18) and End point(X n , Y n ) = (14,22)
Step 2: Calculate ∆ x , ∆ y
∆ x = X n−X 0 ⟹ 14−9=5
∆ y =Y n −Y 0 ⟹ 22−18=4
Step 3: Calculate the decision parameter
pk =2 ∆ y −∆ x ⟹ 2∗4−5=3
Now pk =3
pk +1= pk +2 ∆ y −2 ∆ x
¿ 3+2∗4−2∗5
¿ 11−10=1
x k+1 =x k +1 ⟹ 9+1=10 // starting x-coordinate value
pk +1= pk +2 ∆ y −2 ∆ x
¿ 1+2∗4−2∗5
¿ 9−10=−1
x k+1 =x k +1 ⟹ 10+1=11 // 10 is present x-coordinate value
x k+1 =x k +1
¿ 11+1=12
y k +1= y k =20
pk +1= pk +2 ∆ y −2 ∆ x
¿ 7+2∗4−2∗5
¿ 15−10=5
x k+1 =x k +1 ⟹ 12+1=13 // 12 is present x-coordinate value
pk +1= pk +2 ∆ y −2 ∆ x
¿ 5+2∗4−2∗5
¿ 13−10=3
x k+1 =x k +1 ⟹ 13+1=14 //13 is present x-coordinate value
Process no pk pk +1 x k+1 y k +1
Initial 9 18
1 3 1 10 19
2 1 -1 11 20
3 -1 7 12 20
4 7 5 13 21
5 5 3 14 22
= = = = = == = = = = = == = = = = = = = = = = == = = = = = = = = = = = = = == ======