Page 44 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 44

Lab on Computer Graphics



                   Notes
                                              (x, y)         Œ      description

                                              (0, 0)         –2     illuminate pixel (0, 0)
                                                              1     increment ε by ∆y
                                              (1, 0)                increment x by 1
                                              (1, 0)          1     illuminate pixel (1, 0)
                                                                    since  Œ  > 0
                                              (1, 1)                   increment y by 1
                                                             –4        decrement  Œ  by 5
                                                             –1     increment ε by ∆y
                                              (2, 1)                increment x by 1

                                              (2, 1)         –1     illuminate pixel (2, 1)
                                                              2     increment ε by ∆y
                                              (3, 1)                increment x by 1

                                              (3, 1)          2     illuminate pixel (3, 1)
                                                                    since  Œ  > 0
                                              (3, 2)                    increment y by 1
                                                             –3        decrement  Œ  by 5
                                                              0     increment ε by ∆y
                                              (4, 2)                increment x by 1
                                              (4, 2)          0     illuminate pixel (4, 2)


                                 for    i  =   1  to x 2  – 1
                                          x
                                      illuminate (i, j)
                                      if ( ≥ 0)
                                         j + = 1
                                         –
                                          –  = ∆x
                                         end if
                                      i + = 1
                                      –
                                       +  = ∆y
                                      next i
                                 finish
                                 3.2.3 Bresenham’s Algorithm for Lines with Arbitrary Endpoints

                                 Bresenham’s algorithm is limited by the detail that the lines to be drawn have endpoints with
                                 integer coordinates. Now we consider a version of Bresenham’s algorithm for lines that have
                                 endpoints with real coordinates. The only problem to conquer is the initial setting of the error.
                                 Once this is done, the algorithm proceeds as before.
                                 Consider a line with initial point (x 1 , y 1 ) and terminal point (x 2 , y 2 ) in device space, where we
                                 assume the points are not the same. To calculate the correct in this case, we refer to the following
                                 figure.



        38                                LOVELY PROFESSIONAL UNIVERSITY
   39   40   41   42   43   44   45   46   47   48   49