0% found this document useful (0 votes)
2 views

Unit II Line and Circle Drawing

The document discusses various algorithms for line and circle drawing in computer graphics, including the DDA and Bresenham's line algorithms, as well as circle and ellipse generation methods. It outlines the steps involved in each algorithm, their advantages, and disadvantages. Additionally, it provides examples to illustrate the application of these algorithms in generating pixel positions for drawing lines and shapes.

Uploaded by

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

Unit II Line and Circle Drawing

The document discusses various algorithms for line and circle drawing in computer graphics, including the DDA and Bresenham's line algorithms, as well as circle and ellipse generation methods. It outlines the steps involved in each algorithm, their advantages, and disadvantages. Additionally, it provides examples to illustrate the application of these algorithms in generating pixel positions for drawing lines and shapes.

Uploaded by

Barbara Duplessi
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

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

 That is the slope of the line is difference in y-coordinate and difference in x-


coordinate.

 DDA algorithm is based on the calculation of value of ∆ x and ∆ y .


 Given line has slope +ve (m>0 ¿ or -ve (m<0 ¿. If +ve, the ∆ x and ∆ y values are

increased (m>0 ¿ else ∆ x and ∆ y values are decreased (m<0 ¿.


Case 1: If m<1 Case 2: if m=1 Case 3: if m>1
1
x n=1+ x n x n=1+ x 1 x n= +x
m n
y n=m+ y n y n=1+ y1 y n=1+ y n
Algorithm
Step 1: Consider one point of the line as (X 0 , Y 0 ) and the second point of the line as (X n , Y n ).
Step 2: Calculate ∆ x , ∆ y , m
∆ x = X n−X 0
∆ y =Y n −Y 0
∆y
m=
∆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

As m>1; Case 3 is satisfied,


1
x p+1= +x
m p
y p +1=1+ y p
x0 , y0 x p+1 y p +1 Round off
5,6 5.5 7 6,7

Example 2

The coordinates of drawn line areP1 = (2, 8)


P2 = (3, 9)
P3 = (4, 10)
P4 = (5, 11)
P5 = (6, 12)
P6 = (7, 13)
P7 = (8, 14)
P8 = (9, 15)
P9 = (10, 16)
P10 = (11, 17)

Advantages of DDA Algorithm


1. Itis the simplest algorithm and it does not require special skills for implementation.
2. It is a faster method for calculating pixel positions than the direct use of equation
y=mx+b .
3. It eliminates the multiplication in the equation by making use of raster characteristics,
so that appropriate increments are applied in the x or v direction to find the pixel
positions along the line path.
Disadvantages of DDA Algorithm
1. Floating point arithmetic in DDA algorithm is still time-consuming.
2. The algorithm is orientation dependent. Hence endpoint accuracy is poor

= = = = = = = = = == = = = = = = = = = = == = = = = = = = = = = = = = = = = = = = = = =

Bresenham’s Line algorithm


It determines the point of n-dimensional raster that should be selected in order to form a close
approximation towards a straight line between two points. Line has two end points namely
A ( x 1 , y 1 ) and B ( x2 , y 2 ). It is efficient because it only performed integer addition, integer
subtraction and integer multiplication operation. These operations performed rapidly so the
lines can be generated quickly.
Algorithm
Step 1: Consider one point of the line as (X 0 , Y 0 ) and the second point of the line as (X n , Y n ).

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

Step 4: pk =3 is pk ≥ 0; Case 2 is satisfied

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

y k +1= y k +1 ⟹18+1=19 // starting y-coordinate value

Repeat Step 4; do process no 2


pk =1 is pk ≥ 0; Case 2 is satisfied

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

y k +1= y k +1 ⟹19+1=20 // 19 is present y-coordinate value

Repeat Step 4; do process no 3


pk =1 is pk <0 ; Case 1 is satisfied
pk +1= pk +2 ∆ y
¿−1+2∗4=7

x k+1 =x k +1

¿ 11+1=12

y k +1= y k =20

Repeat Step 4; do process no 4


pk =7 is pk ≥ 0; Case 2 is satisfied

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

y k +1= y k +1 ⟹20+ 1=21 // 20 is present y-coordinate value

Repeat Step 4; do process no 5


pk =5 is pk ≥ 0; Case 2 is satisfied

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

y k +1= y k +1 ⟹21+1=22 // 21 is present y-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

= = = = = == = = = = = == = = = = = = = = = = == = = = = = = = = = = = = = == ======

You might also like