Scan Converting a Straight LineA straight line may be defined by two endpoints & an equation. In fig the two endpoints are described by (x_{1},y_{1}) and (x_{2},y_{2}). The equation of the line is used to determine the x, y coordinates of all the points that lie between these two endpoints. Using the equation of a straight line, y = mx + b where m = & b = the y interrupt, we can find values of y by incrementing x from x =x_{1}, to x = x_{2}. By scanconverting these calculated x, y values, we represent the line as a sequence of pixels. Properties of Good Line Drawing Algorithm:1. Line should appear Straight: We must appropriate the line by choosing addressable points close to it. If we choose well, the line will appear straight, if not, we shall produce crossed lines. The lines must be generated parallel or at 45° to the x and yaxes. Other lines cause a problem: a line segment through it starts and finishes at addressable points, may happen to pass through no another addressable points in between. 2. Lines should terminate accurately: Unless lines are plotted accurately, they may terminate at the wrong place. 3. Lines should have constant density: Line density is proportional to the no. of dots displayed divided by the length of the line. To maintain constant density, dots should be equally spaced. 4. Line density should be independent of line length and angle: This can be done by computing an approximating linelength estimate and to use a linegeneration algorithm that keeps line density constant to within the accuracy of this estimate. 5. Line should be drawn rapidly: This computation should be performed by specialpurpose hardware. Algorithm for line Drawing:
Direct use of line equation:It is the simplest form of conversion. First of all scan P_{1} and P_{2} points. P_{1} has coordinates (x_{1}',y_{1}') and (x_{2}' y_{2}' ). Then m = (y_{2}',y_{1}')/( x_{2}',x_{1}') and b = If value of m≤1 for each integer value of x. But do not consider If value of m>1 for each integer value of y. But do not consider Example: A line with starting point as (0, 0) and ending point (6, 18) is given. Calculate value of intermediate points and slope of line. Solution: P_{1} (0,0) P_{7} (6,18) x_{1}=0 We know equation of line is put value of x from initial point in equation (1), i.e., (0, 0) x =0, y=0 put b = 0 in equation (1) Now calculate intermediate points So points are P_{1} (0,0) Algorithm for drawing line using equation:Step1: Start Algorithm Step2: Declare variables x_{1},x_{2},y_{1},y_{2},dx,dy,m,b, Step3: Enter values of x_{1},x_{2},y_{1},y_{2}. Step4: Calculate dx = x_{2} x_{1} Step5: Calculate dy = y_{2}y_{1} Step6: Calculate m = Step7: Calculate b = y_{1}m* x_{1} Step8: Set (x, y) equal to starting point, i.e., lowest point and x_{end}equal to largest value of x. If dx < 0 Step9: Check whether the complete line has been drawn if x=x_{end}, stop Step10: Plot a point at current (x, y) coordinates Step11: Increment value of x, i.e., x = x+1 Step12: Compute next value of y from equation y = mx + b Step13: Go to Step9. Program to draw a line using LineSlope MethodOUTPUT: Enter Starting and End Points Enter (X1, Y1, X2, Y2) 200 100 300 200
Next TopicDDA Algorithm
