Page 55 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 55

Unit 3: Implementing Line Algorithm



               •  Subscript k takes integer values starting from 1, for the first point and increment by 1   Notes
                 until the final end point is reached.
               •  m->any real numbers between 0 and 1
               •  Calculate y values must be rounded to the nearest integer

            Step 2
            If the slope is greater than 1, the roles of x any y at the unit y intervals Dy = 1 and compute
            each successive y values.
                              Dy = 1
                              m = Dy / Dx
                              m = 1/ (x 2  – x 1 )
                              m = 1 / (x k  + 1 – x k )

                           x k  + 1 = x k  + (1/m)                                    (7)
               •  Equation 6 and Equation 7 that the lines are to be processed from left end point to the
                 right end point.

            Step 3
            If the processing is reversed, the starting point at the right
                              Dx = – 1

                              m = Dy / Dx
                              m = ( y 2  – y 1  ) / – 1
                           y k  + 1 = y k  – m                                       (8)
            Intervals Dy = 1 and compute each successive y values.
            Step 4

            Here,             Dy = – 1
                              m = Dy / Dx
                              m = – 1 / (x 2  – x 1 )
                              m = –1 / (x k  + 1 – x k )

                            x k + 1 = x k  + ( 1 / m )                               (9)
            Equation 6 and Equation 9 used to calculate pixel position along a line with –ve slope.
            Advantage
            Faster method for calculating pixel position then the equation of a pixel position.

                               Y = mx + b
            Disadvantage
            The accumulation of round of error is successive addition of the floating point increments is
            used to find the pixel position but it take lot of time to compute the pixel position.
            Algorithm: A naïve line-drawing algorithm
                              d  x     =     x  2  – x 1
                              d  y     =     y  2  – y 1
                          for x from x 1  to x 2
                          {

                                             LOVELY PROFESSIONAL UNIVERSITY                                    49
   50   51   52   53   54   55   56   57   58   59   60