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

Line Drawing Algorithm

A line drawing algorithm is an algorithm for approximating a line segment on discrete graphical media, such as pixel-based displays and printers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
0% found this document useful (0 votes)
44 views

Line Drawing Algorithm

A line drawing algorithm is an algorithm for approximating a line segment on discrete graphical media, such as pixel-based displays and printers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
You are on page 1/ 4

13

(x1 , y1) (x2 , y2) 12


11
(2 , 2) (9, 2) 10
9

Δ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

Algorithm DDA (x1, y1, x2, y2)


{
dx = x2-x1
dy = y2-y1

if(abs(dx) > abs(dy))


steps =abs (dy)

xincc = dx/step

yincc = dy/step

for (i=1;i<=step;i++)
{
Putpixel(x1, y1)
x1 = x1+ xincc
y1 = y1 + yincc
}
}

You might also like