Page 48 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 48

Lab on Computer Graphics



                   Notes         and
                                                    m = −1024 (∆x (1 − 0.125) − ∆y (1 − 0.75))
                                                      = −1024 (3.55(1 − 0.125) − 2.55(1 − 0.75)
                                                      = −1024 (2.6625 − .6375)

                                                      = −2073.6
                                 And so we initialize the integer quantity  Œ  = −2073 and the algorithm proceeds as follows:
                                 Thus the integer version for Bresenham’s algorithm with arbitrary endpoints is constructed as
                                 follows:
                                 Integer Bresenham’s Algorithm

                                 The points (x 1 , y 1 ) and (x 2 , y 2 ) are assumed not equal and have arbitrary real coordinates  Œ  is
                                          (x, y)      Œ            description
                                          (0, 0)     –2073         illuminate pixel (0, 0)
                                                     538           increment ε by 2611
                                          (1, 0)                   increment x by 1
                                          (1, 0)     538           illuminate pixel (1, 0)
                                                                   since  Œ  > 0
                                          (1, 1)                      increment y by 1
                                                     –3097            decrement  Œ by 3635
                                                     –486          increment ε by 2611
                                          (2, 1)                   increment x by 1
                                          (2, 1)     –486          illuminate pixel (2, 1)
                                                     2125          increment ε by 2611
                                          (3, 1)                   increment x by 1
                                          (3, 1)     2125          illuminate pixel (3, 1)
                                                                   since  Œ  > 0
                                          (3, 2)                      increment y by 1
                                                     –1510            decrement  Œ  by 3635
                                                     1101          increment ε by 2611
                                          (4, 2)                   increment x by 1
                                          (4, 2)     1101          illuminate pixel (4, 2)

                                 assumed to be integer valued.
                                 Let   ∆x = m (x 2  – x 1 )
                                 Let   ∆y = m (y 2  – y 1 )
                                 Let   i 1  =   x Í Î  1 ˙ ˚
                                           x Í Î
                                 Let  i 2  =   2 ˙ ˚
                                 Let  j  =  y Í Î  1 ˙ ˚
                                 Let   Œ  =  Dy (1 -  x (  1 - i) - Dx(1 - y -  j)˙ ˚
                                           Í
                                           Î
                                                               1
                                               i
                                      for   i  =   1  to i 2
                                      illuminate (x, y)
                                      if ( Œ  ≥ 0)
                                         y +   = 1


        42                                LOVELY PROFESSIONAL UNIVERSITY
   43   44   45   46   47   48   49   50   51   52   53