Digital Differential Analyzer (DDA) Algorithm

1. Read the line endpoints (x1, y1) and (x2, y2)
2. Δx=| x2 – x1 |
Δy=| y2 – y1 |
3. if(Δx≥ Δy) then
length=Δx
else
length=Δy
4. Select the raster unit,
Δx= (x2 – x1)/length
Δy= (y2 – y1)/length
5. x= x+0.5*sign(Δx)
y= y+0.5*sign(Δy)
Sign function algorithm work in all quotient. It returns (-1,0) depending on whether it agreement is
< 0, =0, > 0 respectively.
6. Now plot the points i=1,
while(i≤ length)
{
Plot(integer(x), integer(y))
x=x+Δx
y=y+Δy
i=i+1
}
7. STOP