SCAN CONVERTING A STRAIGHT LINE .


A straight line can be drawn by plotting discrete point’s b\w the two end points. A device is then directed to fill in these position b\w the end points. These discrete points along the path of the line are calculated from equation of the line but the problem with scan converting straight line is that the pixel positions on the screen are reference with integer values.
This means every point (x, y) along the line path should have integer value of x and y coordinates so the plotted position may be approximation of the points on the actual line segment.
E.g. actual line is (15.21, 21.57) then we just do not have a position corresponding to these values on the raster screen. These points calculated from equation can be bounded off to (15, 21) which can plotted on screen.

ALGORITHM OF DIRECT METHOD FOR DRAWING A LINE

1. Input the two end point of the line (xi,yi) and (xf,yf)
2. Compute slope of the line , m= (yf –yi) / (xf- xi)
3. Compute y intercept of the line b= yi –mx
4. Set initial values of x and y as x=xi and y=yi
5. Plot the first point , plot pixel (x ,y)
6. if/m/<1 then 7. while (x

Comments are closed.