DDA algorithm which scan and converts lines with acceptable approximation in sufficiently less time. Assume that a line is to be rasterized between given endpoints (xstart, ystart) and (xend, yend).
Now let us consider the equation of the line as:
where m represents the slope of the line and c is the y intercept. This slope can be expressed as-
m= (yend – ystart)/(xend – ystart)
1. Read the line endpoints (x1, y1) and (x2, y2)
2. Δx=| x2 – x1 | Δy=| y2 – y1 |
3. if(Δx≥ Δy) then
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,
Plot(integer(x), integer(y)) x=x+Δx y=y+Δy