COMPUTER GRAPHICS
DDA Algorithm
By: Ms. Rachana Marathe
DDA algorithm
dx= x2-x1;
dy= y2-y1;
if (dx) > (dy) then steps = (dx)
else steps= (dy);
x_inc = dx/steps;
y_inc = dy/steps;
x=x1;
y=y1;
for= 1 to steps do
x= x+x_inc;
y =y+y_inc;
Example 1: x1,y1= 2,2 x2,y2= 4,4
Algorithm:
dx= x2-x1;
dy= y2-y1;
if (dx) > (dy)
then steps = (dx)
else steps= (dy);
x_inc = dx/steps;
y_inc = dy/steps;
x=x1;
y=y1;
for= 1 to steps do
x= x+x_inc;
y =y+y_inc;
Solution:
dx= 4-2 =2
dy= 4-2 =2
true
steps = 2
x_inc = 2/2= 1
y_inc = 2/2= 1
x=2;
y=2;
for= 1 to 2 do (for loop 2 times)
(first loop)
x= 2+1=3
y= 2+1=3
Therefore the pixels are
(2,2) (3,3) (4,4)
Example 2: x1, y1= 1, 2 x2, y2= 4, 6
dx= x2-x1;
dy= y2-y1;
if (dx) > (dy)
then steps = (dx)
else steps= (dy);
x_inc = dx/steps;
y_inc = dy/steps;
x=x1;
y=y1;
for= 1 to steps do
x= x+x_inc;
y =y+y_inc;
Solution:
dx= 4-1 =3
dy= 6-2 =4
false
steps = 4
x_inc = 3/4= 0.75
y_inc = 4/4= 1
x=1;
y=2;
for= 1 to 4 do (for loop 4 times)
(first loop)
x= 1+0.75= 1.75 = 2 (round off)
Therefore the pixels are
(1,2) (2,3) (3,4) (3,5) (4,6)
Reference
Hearn,Baker - Computer Graphics - C Version 2nd Ed
http://edu.uokufa.edu.iq/staff/dr.nidhal/compressed%20comp.book/H
earn,Baker%20-%20Computer%20Graphics%20-
%20C%20Version%202nd%20Ed.pdf

Comuter graphics dda algorithm

  • 1.
  • 2.
    DDA algorithm dx= x2-x1; dy=y2-y1; if (dx) > (dy) then steps = (dx) else steps= (dy); x_inc = dx/steps; y_inc = dy/steps; x=x1; y=y1; for= 1 to steps do x= x+x_inc; y =y+y_inc;
  • 3.
    Example 1: x1,y1=2,2 x2,y2= 4,4 Algorithm: dx= x2-x1; dy= y2-y1; if (dx) > (dy) then steps = (dx) else steps= (dy); x_inc = dx/steps; y_inc = dy/steps; x=x1; y=y1; for= 1 to steps do x= x+x_inc; y =y+y_inc; Solution: dx= 4-2 =2 dy= 4-2 =2 true steps = 2 x_inc = 2/2= 1 y_inc = 2/2= 1 x=2; y=2; for= 1 to 2 do (for loop 2 times) (first loop) x= 2+1=3 y= 2+1=3
  • 4.
    Therefore the pixelsare (2,2) (3,3) (4,4)
  • 5.
    Example 2: x1,y1= 1, 2 x2, y2= 4, 6 dx= x2-x1; dy= y2-y1; if (dx) > (dy) then steps = (dx) else steps= (dy); x_inc = dx/steps; y_inc = dy/steps; x=x1; y=y1; for= 1 to steps do x= x+x_inc; y =y+y_inc; Solution: dx= 4-1 =3 dy= 6-2 =4 false steps = 4 x_inc = 3/4= 0.75 y_inc = 4/4= 1 x=1; y=2; for= 1 to 4 do (for loop 4 times) (first loop) x= 1+0.75= 1.75 = 2 (round off)
  • 6.
    Therefore the pixelsare (1,2) (2,3) (3,4) (3,5) (4,6)
  • 7.
    Reference Hearn,Baker - ComputerGraphics - C Version 2nd Ed http://edu.uokufa.edu.iq/staff/dr.nidhal/compressed%20comp.book/H earn,Baker%20-%20Computer%20Graphics%20- %20C%20Version%202nd%20Ed.pdf