Monday, July 30, 2012

Abinash Bishoyi’s line drawing algorithm(for any m)

1. Input the two end points (xi, yi) and (xf, yf).
2. Check the value of m=|(yf – yi)/(xf – xi)|.
3. If m>1, then swap (xi, yi) and swap (xf, yf).
4. If xi>xf, then swap (xi, xf) and swap (yi, yf).
5. Calculate the constants Δx = xf –xi, Δy = yf –yi, 2Δy, (2Δy-2Δx) and obtain the starting value of decision parameter as po=2Δy-Δx.
6. If yi7. If m>1then plot (yk, xk) else plot (xk, yk).
8. Plot the first point, that is xo=xi and yo=yi.
9. At xk , starting k=0 , perform the following test
If pk < 0, then xk+1=xk+1, yk+1=yk, pk+1=pk+2Δy
Otherwise xk+1=xk+1, yk+1=yk + ys, pk+1=pk+2Δy-2Δx.
10. Repeat the step 9, Δx times.

No comments:

Post a Comment