Algorithm
#define ROUND(a) ((int)(a+0.5))
voidlineDDA (int xa, int ya, int
xb, int yb)
{
int dx = xb - xa, dy = yb - ya,
steps, k;
floatxIncrement, yIncrement, x =
xa, y = ya;
if (abs (dx) > abs (dy) steps
= abs (dx) ;
else steps = abs dy);
xIncrement = dx / (float) steps;
yIncrement = dy / (float) steps
setpixel (ROUND(x), ROUND(y) ) :
for (k=0; k<steps; k++)
{
x += xIncrement;
y += yIncrement;
setpixel (ROUND(x), ROUND(y));
}
}
Algorithm
Description:
Step 1 :Accept Input as two endpoint pixel positions
Step 2: Horizontal and vertical differences between the endpoint
positions are assigned to parameters dx and dy (Calculate dx=xb-xa and
dy=yb-ya).
Step 3:The difference with the greater magnitude determines the value of
parameter steps.
Step 4 :Starting with pixel position (xa, ya), determine the offset needed
at each step to generate the next pixel position along the line path.
Step 5: loop the following process for steps number of times
a. Use a unit of increment or decrement
in the x and y direction
b. if xa is less than xb the values of
increment in the x and y directions are 1 and m
c. if xa is greater
than xb then the decrements -1 and – m are used.