DDA Algorithm
The digital drflerential analyzer (DDA) is a scan-conversion line algorithm.
This algorithm is summarized in the following procedure
Accept the two end points pixel positions as input.
A(x1, y1)
B(x2, y2)Horizontal and vertical differences between the endpoint positions are assigned to parameters dx and dy.
dx = x2 - x1
dy = y2 - y1The difference with the greater magnitude determines the value of parameter
steps
.if |dx| > |dy| (compare absolute values of dx and dy)
steps = dx
else
steps = dyWe determine the Incremental Factor needed at each step to generate the next pixel position along the line path.
Δx = dx ⁄ steps
Δy = dy ⁄ stepsPlot the initial points on the line
xnew = x1
ynew = y1setPixel ( xnew , ynew )
Generate new pixel on line by incrementing x and y, we repeat the process
steps
times.for (k = 0; k < steps; k++)
xnew = xnew + Δx
ynew = ynew + ΔysetPixel ( xnew , ynew )