Professional Documents
Culture Documents
Lecture6-6 - 16827 - Line Scan Conversion
Lecture6-6 - 16827 - Line Scan Conversion
Z
Y
m=∞
m = -4 m=4
m = -2 m=2
m = -1 m=1
m = - 1 /2 m = 1/2
m = -1/3 m = 1/3
– Take unit step increment along direction having more rate of change, and
compute the coordinates for the other position to maximize the number of
points to be computed along the path of line and avoid discontinuities
xi 1 : xi 1
yi 1 : yi m 0 m 1
or Why?
yi 1 : yi 1
1
xi 1 : xi 1 m
m
January 19, 2021 Computer Graphics discontinuity !! 26
DDA Algorithm - Generic solution
– What is m<0 ?
– We must see the sign of x and y
Various x>0 x>0 x<0 x<0
Cases y>0 y<0 y>0 y<0
xi+1 = xi + 1 xi+1 = xi + 1 xi+1 = xi - 1 xi+1 = xi - 1
|m|<1 yi+1 = yi + m yi+1 = yi - m yi+1 = yi + m yi+1 = yi – m
(or swap
points)
xi+1 = xi + 1/m xi+1 = xi + 1/m xi+1 = xi - 1/m xi+1 = xi - 1/m
|m|>1 yi+1 = yi + 1 yi+1 = yi - 1 yi+1 = yi + 1 yi+1 = yi – 1
(or swap
– Or can we have simple solution??????? points)
January 19, 2021 Computer Graphics 27
DDA Algorithm
1. Input (x1,y1) and (x2,y2)
2. Compute
dx = x2-x1 and dy = y2-y1
m = dx/dy
3. If abs(dx)>abs(dy)
step = abs(dx)
else
step = abs(dy)
4. Compute xinc = dx/step
yinc = dy/step
5. Initialize x = x1 and y = y1
6. Draw pixel (x, y)
7. For k = 1 to steps do //we reach the other endpoint
{
x = x + xinc;
y = y + yinc;
Draw pixel (ROUND(x), ROUND(y));
}
January 19, 2021 Computer Graphics 28
DDA Algorithm
8. Limitations
– Rounding integers takes time
– e.g. if m=.333 …
Specified
Line Path
0 m 1
Specified
Line Path
Q2
yk 1 d2
yk 2 y Q
yk 1 Q2 d1
Q
y mx b yk Q1
yk P Q1 P
xk 1
xk xk 1 xk 2
0 m 1, xk xl , k l
k pk (xk+1, yk+1)
k pk (xk+1, yk+1)
0 3
1 1 (14, 12)
2 -1 (15, 12)
3 7 (16, 13)
4 5 (17, 14)
January 19, 2021 Computer Graphics 46
Bresenham’s Line Algorithm
5. Exercise: Trace for (20,10) to (30,18)
k pk (xk+1,yk+1)
18
17
16
15
14
13
12
11
10
20 21 22 23 24 25 26 27 28 29 30
January 19, 2021 Computer Graphics 47
Bresenham’s Line Algorithm
Answer k pk (xk+1,yk+1)
18
0 6 (21,11)
17 1 2 (22,12)
16 2 -2 (23,12)
15 3 14 (24,13)
14 4 10 (25,14)
13 5 6 (26,15)
12 6 2 (27,16)
11 7 -2 (28,16)
10 8 14 (29,17)
20 21 22 23 24 25 26 27 28 29 30 9 10 (30,18)
January 19, 2021 Computer Graphics 48