Line Drawing Algorithm
Line Drawing Algorithm
Δx = 9-2=7 8
7
6
Δy =2-2=0 y 5
4
m=dx / dy = 0 / 7= 0 3
2
x increment c = 7 / 7=1 1
y increment c =0 / 7 =0 0 1 2 3 4 5 6 7 8 9 10 11 12
X y
2 2
3 2
4 2
5 2
6 2
7 2
8 2
9 2
13
(x1 , y1) (x2 , y2) 12
11
(2 , 5) (2, 12) 10
9
Δx = 2-2=0 8
7
6
Δy =12-5=7 y 5
4
m= dy / dx = 7 / 0= (∞) infinity 3
2
x increment c = 0 / 7=0 1
y increment c = 7/ 7 =1 0 1 2 3 4 5 6 7 8 9 10 11 12
X y
2 5
2 6
2 7
2 8
2 9
2 10
2 11
2 12
When slope less than 1 13
12
(x1 , y1) (x2 , y2) 11
10
(5 , 4) (12, 7) 9
8
Δx = 12-5=7 7
6
5
Δy =7- 4=3 y 4
3
m= dy / dx = 3 / 7 2
1
x increment c = 7 / 7=1 0 1 2 3 4 5 6 7 8 9 10 11 12
y increment c = 3/ 7 =0.42
X y
5 4 4
6 4.4 4
7 4.8 5
8 5.2 5
9 5.6 6
10 6 6
11 6.4 6
12 6.8 7
DDA Line Drawing Algorithm
xincc = dx/step
yincc = dy/step
for (i=1;i<=step;i++)
{
Putpixel(x1, y1)
x1 = x1+ xincc
y1 = y1 + yincc
}
}