Page 54 - DCAP313_LAB_ON_COMPUTER_GRAPHICS
P. 54

Lab on Computer Graphics



                   Notes         The line drawing algorithm using the Digital Differential Analyses (DDA) method. Select any
                                 two points on the pseudo screen with mouse clicks. The ‘ideal line’ is first drawn as thin blue
                                 straight line between the two selected points. Determining suitable intermediate pixels using
                                 the DDA algorithm enables the line to be drawn. Click ‘clear’ to refresh the screen, and to select
                                 a new pair of points.
                                 Line Equation

                                 The Cartesiand slop-intercept equation for a straight line is:
                                                     y = mx + b                                            (1)
                                 with
                                                    m-> slope

                                                     b-> y intercept
                                 The 2 end points of a line segment are specified at a position(x 1 , y 1 )
                                 Determine the values for the slope m and y intercept b with the following calculation.

                                 Here, slope m:
                                                    m = ( y 2  – y 1 ) / ( x 2  – x 1  )
                                                    m = Dy / Dx                                            (2)
                                 y intercept b
                                                     b = y 1  – mx 1                                       (3)

                                    •  Algorithms for displaying straight line based on this equation
                                    •  y interval Dy from the equation
                                                    m = Dy / Dx
                                                   Dy = m Dx                                               (4)

                                 Similarly x interval Dx from the equation
                                                    m = Dy / Dx
                                                   Dx = Dy /m                                              (5)

                                 3.3.1 Line DDA Algorithm
                                    •  The  digital  differential  analyzer  (DDA)  is  a  scan  conversion  line  algorithm  based  on
                                      calculation either Dy or Dx.
                                    •  The line at unit intervals is one coordinate and determine corresponding integer values
                                      nearest line for the other coordinate.
                                    •  Consider first a line with positive slope.
                                 Step 1
                                 If the slope is less than or equal to 1, the unit x intervals Dx = 1 and compute each successive
                                 y values.
                                                   Dx = 1
                                                    m = Dy / Dx

                                                    m = ( y 2  – y 1  ) / 1
                                                    m = (y k  + 1 – y k  ) /1
                                                 y k  + 1 = y k  + m                                       (6)

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