UNIT - 2 Line Drawing Algorithm
UNIT - 2 Line Drawing Algorithm
com
Line Drawing
1
https://genuinenotes.com
2
https://genuinenotes.com
Pixel Position
• Pixel position: referenced by scan line number and column
number
DDA Algorithm
Digital Differential Analyzer
Scan-conversion line – algorithm based on calculating either
5
https://genuinenotes.com
CASE 1
Positive Slope
(Y always increase when X increases and
Y always Decreases when X decrease)
Positive Slope
1. Slope less than 1 ( |M| < 1 ) and
moving Left to Right
M=1
7
X1 X2
CASE 1 https://genuinenotes.com
Positive Slope
2. Slope less than 1 ( |M| < 1 ) and
moving Right to Left
M=1
8
X2 X1
CASE 1 https://genuinenotes.com
Positive Slope
3. Slope greater than 1 ( |M| > 1 ) and
moving Left to Right
M=1
Y2
X1 X2 9
CASE 1 https://genuinenotes.com
Positive Slope
4. Slope Greater than 1 ( |M| > 1 ) and
moving Right to Left
M=1
Y2
X1 X2 10
CASE 2
https://genuinenotes.com
Negative Slope
1. Slope less than 1 ( |M| < 1 ) and
moving Left to Right
M=-1
X2 11
X1
CASE 2
https://genuinenotes.com
Negative Slope
2. Slope less than 1 ( |M| < 1 ) and
moving Right to Left
M=-1
X2 12
X1
CASE 2
https://genuinenotes.com
Negative Slope
3. Slope greater than 1 ( |M| > 1 ) and
moving Left to Right
M=-1
X1 X2 13
CASE 2
https://genuinenotes.com
Negative Slope
4. Slope Greater than 1 ( |M| > 1 ) and
moving Right to Left
M=-1
X1 X2 14
DDA
https://genuinenotes.com
Q.> Digitize a Line with end point A(3,2) and B(8,4) , using DDA
17
https://genuinenotes.com
DDA Final Exercise
1. Digitize the line from A(1,1) to B(10,8) using scan conversion line
algorithm.
2. Draw a line with two end point P(5,3) and Q(1,2) using DDA
3. Digitize the line with endpoints A(1,7) and B(6,3) using digital
differential analyzer line drawing algorithm. Show all necessary
steps. (TU) .
+1 +1
+1 +1 20
https://genuinenotes.com
Let us assume that pixel (xk, yk) is already
plotted assuming that the sampling direction is
along X-axis i.e. (xk+1, yk) or (xk+1, yk+1). Thus, the
common equation of the line is
y = m(xk+1) + c
Now,
21
https://genuinenotes.com
Here,
Pk+1- Pk = 2 Δy Xk+1+2 Δy + 2 Δx c - 2 Δx yk+1 – Δx – {2 Δy Xk+2
Δy + 2 Δx c - 2 Δx yk – Δx }
23
Pk+1 = Pk +2 Δy(Xk+1 – Xk)- 2 Δx(Yk+1– Yk)
https://genuinenotes.com
Case 1
If Pk < 0 (i.e. d1-d2 is Negative )
then,
Xk+1 = Xk+1
Yk+1 = Yk
Pk+1 = Pk + 2 Δy
Pk+1 = Pk + 2 Δy -2Δx 24
https://genuinenotes.com
Initial Decision Parameter (P0)
y = m(xk+1) + c
Let, X0 = 0 , Y0 = 0 then C = 0
P0 = 2 Δy - Δx
25
https://genuinenotes.com
Example-1: Digitize the line with end points (20, 10) and (30, 18)
using BLA.
Solution :
Here, Starting point of line = (x1, y1) = (20, 10) and
Ending point of line = (x2, y2) = (30, 18)
Thus, slope of line, m = Δy / Δx = y2-y1 / x2-x1
= (18-10) / (30-20)
26
Thus, https://genuinenotes.com
The initial decision parameter (P0) = 2Δy - Δx = 2*8 – 10 = 6
Since, for the Bresenham’s Line drawing Algorithm of slope, |m| ≤ 1, we have
+1 +1
+1 +1
30
+1 +1
https://genuinenotes.com
d1 = X - Xk = {yk +1 – c}/m - xk
and
d2 = (Xk +1)- X = xk+1– {yk+1 – c}/m 31
https://genuinenotes.com
So,
d1 - d2 = [{yk +1 – c}/m - xk] -[xk+1–
{{yk+1 – c}/m }]
Or,
d1 - d2 = 2/m* (yk+1) - 2c/m – 2xk -1
Pk+1 = Pk + 2 Δx
d2
d2
Y
Y
d1
Case 1
If Pk < 0 (i.e. d1-d2 is Negative )
then,
Xk+1 = Xk - 1
Yk+1 = Yk
Pk+1 = Pk + 2 Δy
d1 d2 d1
d2
Pk = Pk + 2 Δx
if Pk < 0 If Pk ≥ 0 If Pk < 0 If Pk ≥ 0
Xk+1 = Xk+1 Xk+1 = Xk+1 Xk+1 = Xk Xk+1 = Xk+1
Yk+1 = Yk Yk+1 = Yk+1 Yk+1 = Yk+1 Yk+1 = Yk+1
Pk = Pk + 2 Δy Pk = Pk + 2 Δy -2Δx Pk = Pk + 2 Δx Pk = Pk + 2 Δx -2Δy
P0 = 2 Δy - Δx P0 = 2 Δx - Δy
If Pk < 0 If Pk ≥ 0 If Pk < 0 If Pk ≥ 0
Xk+1 = Xk - 1 Xk+1 = Xk - 1 Xk+1 = Xk Xk+1 = Xk - 1
Yk+1 = Yk Yk+1 = Yk +1 Yk+1 = Yk +1 Yk+1 = Yk +1
Pk = Pk + 2 Δy Pk = Pk + 2 Δy -2Δx Pk = Pk + 2 Δx Pk = Pk+ 2Δx - 2 Δy 55
P0 = 2 Δy - Δx P0 = 2 Δx - Δy
Circle Algorithm
https://genuinenotes.com
What is Circle ?
• Similarly to the case with lines, there is an incremental
algorithm for drawing circles – the mid-point circle algorithm
• In the mid-point circle algorithm we use eight-way symmetry
so only ever calculate the points for the top right eighth of a
circle, and then use symmetry to get the rest of the points
Pk<0
Pk≥0 (Xk+1,Yk-1/2)
Pk< 0 Pk ≥ 0
XK+1 = Xk+1 XK+1 = Xk+1
57
YK+1 = Yk YK+1 = Yk-1
https://genuinenotes.com
(Xk+1,Yk)
(Xk,Yk)
Pk<0
Case 1 : Pk < 0
Xk+1 = Xk +1
Yk+1 = Yk
Pk≥0 (Xk+1,Yk-1/2)
Pk+1 = Pk + 2(Xk+1) + 1
Pk+1 = Pk + 2Xk+1 + 1
Now, (1,r-1)
P0 = 12+(r-1/2 )2 – r2
= 1 + r 2- r + ¼ - r 2
= 5/4 – r
P0 ≈ 1-r
62
P0 ≈ 1-r
https://genuinenotes.com
Example : Digitize a circle with radius 10 at center (0,0)
Solution
Here, the initial decision parameter (P0) =1 – r = 1-10 = - 9
Since, for the Midpoint Circle Algorithm of initial point(0, r) &
center at origin (0, 0) rotating at clockwise direction, we have
Initial point (x0,y0) = (0,10)
P0=1-r = 1-10 = -9
68
https://genuinenotes.com
Pk<0
(Xk-1,Yk-1/2) Pk ≥ 0
Pk< 0 Pk ≥ 0
XK+1 = Xk-1 XK+1 = Xk-1
70
YK+1 = Yk YK+1 = Yk-1
Here, https://genuinenotes.com
Decision parameter(Pk) = Fcircle (Xk -1,Yk-1/2)
= (Xk -1)2 + (Yk-1/2)2 - r2
Then, K+1th term is,
Pk+1= (Xk+1 -1)2 + (Yk+1 - 1/2)2 - r2
Now,
Pk+1 – Pk = (Xk+1 -1)2 + (Yk+1 - 1/2)2 - r2 – {(Xk -1)2 + (Yk-1/2)2 - r2}
= -2(xk-1)+(Y2k+1-Y2k) – (Yk+1 – Yk) + 1
i.e.,
(x0,y0) = (0,r)
(-1,r-1/2)
Here ,
Now, (-1,r-1)
P0 = (-1)2+(r-1/2 )2 – r2
= 1 + r 2- r + ¼ - r 2
= 5/4 – r
P0 ≈ 1-r
72
P0 ≈ 1-r
https://genuinenotes.com
74
https://genuinenotes.com
Midpoint Ellipse Algorithm (cont..)
79
https://genuinenotes.com
86
https://genuinenotes.com
89
https://genuinenotes.com
Example
• One can sketch a figure outline, and pick an interior point.
• The figure interior is then painted in the fill color as shown in
these Figures
91
https://genuinenotes.com
92
https://genuinenotes.com
95
https://genuinenotes.com
101
https://genuinenotes.com
102
https://genuinenotes.com
• This occurs because the algorithm checks next pixels both for
104
https://genuinenotes.com
105
https://genuinenotes.com
107
https://genuinenotes.com
108
https://genuinenotes.com
109
https://genuinenotes.com
Example
• In this example, we first process scan lines
successively from the start line to the top
boundary.
• After all upper scan lines are processed, we fill in
Example
• In (a) of this figure, the initial span has been filled, and starting
positions 1 and 2 for spans on the next scan lines (below and
above) are stacked.
Example
• In Fig.(b), position 2 has been unstacked and processed to
produce the filled span shown, and the starting pixel (position
3) for the single span on the next scan line has been stacked.
Example
• After position 3 is processed, the filled spans and stacked
positions are as shown in Fig. (c).
Example
• And Fig.(d) shows the filled pixels after processing all spans in
the upper right of the specified area.
Example
• Position 5 is next processed, and spans are filled in the upper
left of the region; then position 4 is picked up to continue the
processing for the lower scan lines.
Example
•Finish up the upper scan lines.
Example
•Start the bottom scan lines.
Example
•Finish up the bottom scan lines.
Example
•Finish up the bottom scan lines.
Chapter 2