DDA Line Algorithm
Dr. Snehlata Barde
Profesor & HoD, MSIT
MATS University,Raipur
 In Computer Graphics the first basic line drawing
algorithm is Digital Differential Analyzer (DDA)
Algorithm.
 A line connects two points. It is a basic element in
graphics. To draw a line, you need two points
between which you can draw a line.
 In computer graphics, a digital differential analyzer
(DDA) is hardware or software used for
interpolation of variables over an interval between
start and end point. DDAs are used for rasterization
of lines, triangles and polygons.
DIGITAL DIFFERENTIAL ANALYZER (DDA) ALGORITHM.
COMPUTER HAS TO TAKE CARE OF 2 THINGS:
 Pixels
- Which pixels to plot.
 Computations
- Computations required to calculate pixel positions
SLOPE INTERCEPT LINE EQ:
 y = mx + b
 m = slope
 b = is the y intercept, is called as “slope intercept line
equation.”
 Therefore
 Slope(m) = dy/dx
 Slope(m) = - /-
(DDA) ALGORITHM
 Step 1 Input the coordinates of the Two end
points A(x1, y1) and B(x2, y2) for the line AB
respectively. Note that points A and B are not
equal. (If they are equal, then it is a point. Plot
the point and return.)
 Step 2: [Calculate dx and dy]
dx = (x2 — x1) and dy = (y2— y1)
 Step 3: [Calculate the length L]
If (abs (x2 — x1) >abs (y2 — yl)) then
L = abs(x2 — x1)
Else L = abs (y2 — y1)
(DDA) ALGORITHM
 Step 4: [Calculate the increment factor]
 ∆x = (x2— x1)/L and ∆y = (y2 — y1)/L
This step makes either ∆x or ∆y equal to 1, because L is
either |x2 - x1| or |y2 — y1| Therefore, a step increment
in x or y direction is equal to 1.
 Step 5: [Initialize the initial point on the line and plot]
=x1 + 0.5 and = + 0.5
 Plot (Integer (), Integer ())
The values are rounded using the factor of 0.5 rather
than truncating, so that the central pixel addressing is
handled correctly. Moreover, the sign function given
makes the algorithm work in all the quadrants.
(DDA) ALGORITHM
 step 6: [Obtain the new pixel on the line and plot the
same]
 Initialize i to 1
 While (i<= L){
 = + ∆ x
= + ∆ y
 Plot (Integer(), Integer())
i = i + 1}
 Step 7: Finish
ADVANTAGES
 1. It is the simplest algorithm and it does not require
special skills for implementation.
 2. It is a faster method for calculating pixel positions
than the direct use of equation y=mx + b. It
eliminates the multiplication in the equation by
making use of raster characteristics, so that
appropriate increments are applied in the x or y
direction to find the pixel positions along the line
path.
DISVANTANGES
 1. Floating point arithmetic in DDA algorithm is still
time-consuming.
 2. The algorithm is orientation dependent. Hence
end point accuracy is poor.

dda-line-algorithm.pptx of computer graphics

  • 1.
    DDA Line Algorithm Dr.Snehlata Barde Profesor & HoD, MSIT MATS University,Raipur
  • 2.
     In ComputerGraphics the first basic line drawing algorithm is Digital Differential Analyzer (DDA) Algorithm.  A line connects two points. It is a basic element in graphics. To draw a line, you need two points between which you can draw a line.  In computer graphics, a digital differential analyzer (DDA) is hardware or software used for interpolation of variables over an interval between start and end point. DDAs are used for rasterization of lines, triangles and polygons. DIGITAL DIFFERENTIAL ANALYZER (DDA) ALGORITHM.
  • 3.
    COMPUTER HAS TOTAKE CARE OF 2 THINGS:  Pixels - Which pixels to plot.  Computations - Computations required to calculate pixel positions
  • 4.
    SLOPE INTERCEPT LINEEQ:  y = mx + b  m = slope  b = is the y intercept, is called as “slope intercept line equation.”  Therefore  Slope(m) = dy/dx  Slope(m) = - /-
  • 5.
    (DDA) ALGORITHM  Step1 Input the coordinates of the Two end points A(x1, y1) and B(x2, y2) for the line AB respectively. Note that points A and B are not equal. (If they are equal, then it is a point. Plot the point and return.)  Step 2: [Calculate dx and dy] dx = (x2 — x1) and dy = (y2— y1)  Step 3: [Calculate the length L] If (abs (x2 — x1) >abs (y2 — yl)) then L = abs(x2 — x1) Else L = abs (y2 — y1)
  • 6.
    (DDA) ALGORITHM  Step4: [Calculate the increment factor]  ∆x = (x2— x1)/L and ∆y = (y2 — y1)/L This step makes either ∆x or ∆y equal to 1, because L is either |x2 - x1| or |y2 — y1| Therefore, a step increment in x or y direction is equal to 1.  Step 5: [Initialize the initial point on the line and plot] =x1 + 0.5 and = + 0.5  Plot (Integer (), Integer ()) The values are rounded using the factor of 0.5 rather than truncating, so that the central pixel addressing is handled correctly. Moreover, the sign function given makes the algorithm work in all the quadrants.
  • 7.
    (DDA) ALGORITHM  step6: [Obtain the new pixel on the line and plot the same]  Initialize i to 1  While (i<= L){  = + ∆ x = + ∆ y  Plot (Integer(), Integer()) i = i + 1}  Step 7: Finish
  • 8.
    ADVANTAGES  1. Itis the simplest algorithm and it does not require special skills for implementation.  2. It is a faster method for calculating pixel positions than the direct use of equation y=mx + b. It eliminates the multiplication in the equation by making use of raster characteristics, so that appropriate increments are applied in the x or y direction to find the pixel positions along the line path.
  • 9.
    DISVANTANGES  1. Floatingpoint arithmetic in DDA algorithm is still time-consuming.  2. The algorithm is orientation dependent. Hence end point accuracy is poor.