Thursday 3 April 2014

DDA (digital deferential analyzer)
  1.  Read the line points (x1,y1 , x2,y2) such that they are not equal (if they are equal then plot that point and exit).
  2.  dx= |x2-x1| , dy = |y2-y1|
  3.  if dx >= dy then length= dx else length = dy
  4.  dx= (x2-x1)/length , dy= (y2-y1)/length this makes either dx or dy=1.
  5.  x=x1+0.5*sign(dx) , y=y1+0.5*sign(dy).
  6.  i=1(begins the loop) . In this loop points are poltted.
  7.  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














0 comments:

Post a Comment