Page 46 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 46

Lab on Computer Graphics



                   Notes
                                              (x, y)               description
                                              (0, 0)     –0.57042   illuminate pixel (0, 0)
                                                         0.14789    increment  by 0.71831
                                              (1, 0)                increment x by 1
                                              (1, 0)     0.14789    illuminate pixel (1, 0)
                                                                    since ε > 0
                                              (1, 1)                   increment y by 1
                                                         –0.85211       decrement ε by 1
                                                         –0.1338    increment ε by 0.71831
                                              (2, 1)                increment x by 1
                                              (2, 1)     –0.1338    illuminate pixel (2, 1)
                                                         0.58451    increment ε by 0.71831
                                              (3, 1)                increment x by 1
                                              (3, 1)     0.58451    illuminate pixel (3, 1)
                                                                    since ε > 0
                                              (3, 2)                   increment y by 1
                                                         –0.41549       decrement ε by 1
                                                         0.30282    increment ε by 0.71831
                                              (4, 2)                increment x by 1
                                              (4, 2)     0.30282    illuminate pixel (4, 2)

                                 Assuming that the DA is the x-axis, the algorithmic description of Bresenham’s algorithm for
                                 lines with arbitrary endpoints is as follows:
                                 Bresenham’s Algorithm
                                 The points (x 1 , y 1 ) and (x 2 , y 2 ) are assumed not equal

                                 And have arbitrary real coordinates is assumed to be real.
                                 Let   ∆x = x 2  – x 1

                                 Let   ∆y = y 2  – y 1
                                           Dy
                                 Let   m  =
                                           Dx
                                 Let   i 1  =   y Í Î  1 ˙ ˚


                                 Let   j  =   y Í Î  1 ˙ ˚

                                 Let  i 2  =   2 ˙ ˚
                                           x Í Î
                                                                   ))
                                           Ê           D  ( y  1 - (x  - i 1 ˆ
                                 Let    = – 1 - (y 1  - ) -  D x 1  ˜ ¯
                                                    j
                                           Á
                                           Ë
                                 for   i  =   1  to i 2
                                          i
                                      illuminate (i, j)
                                      if ( ≥ 0)
                                      j + =  1
                                      – =  1.0


        40                                LOVELY PROFESSIONAL UNIVERSITY
   41   42   43   44   45   46   47   48   49   50   51