DDA (digital deferential analyzer)
plot(Interger(x)= Integer (y))
x=x+dx
y= y+dy
i=i+1
}
8. stop.
Example of DDA line drawing algorithm.
Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8).
num steps= 12-2=10
x inc = 10/10=1.0
y inc = 5/10= 0.5
- Read the line points (x1,y1 , x2,y2) such that they are not equal (if they are equal then plot that point and exit).
- dx= |x2-x1| , dy = |y2-y1|
- if dx >= dy then length= dx else length = dy
- dx= (x2-x1)/length , dy= (y2-y1)/length this makes either dx or dy=1.
- x=x1+0.5*sign(dx) , y=y1+0.5*sign(dy).
- i=1(begins the loop) . In this loop points are poltted.
- while(i<=length)
plot(Interger(x)= Integer (y))
x=x+dx
y= y+dy
i=i+1
}
8. stop.
Example of DDA line drawing algorithm.
Suppose we want to draw a line starting at pixel (2,3) and ending at pixel (12,8).
num steps= 12-2=10
x inc = 10/10=1.0
y inc = 5/10= 0.5
t
|
x
|
R(x)
|
R(y)
|
0
|
2
|
2
|
3
|
1
|
3
|
3
|
4
|
2
|
4
|
4
|
4
|
3
|
5
|
5
|
5
|
5
|
7
|
7
|
6
|
6
|
8
|
8
|
6
|
7
|
9
|
9
|
7
|
8
|
10
|
10
|
7
|
9
|
11
|
11
|
8
|
10
|
12
|
12
|
8
|
DDA line algorithm |line drawing algorithm