Coming Soon

Coming Soon

Coming Soon

Coming Soon
Coming Soon

DDA Line Drawing Algorithm (Digital Differential Analyzer)

The DDA (Digital Differential Analyzer) algorithm is a line drawing algorithm used in computer graphics to generate a straight line between two given points. It works on the principle of incremental calculations, meaning it calculates intermediate points step by step rather than solving the line equation repeatedly.

In DDA, a line is generated by incrementing one coordinate (x or y) in small steps and calculating the corresponding value of the other coordinate using the slope of the line.


Principle of DDA Algorithm

A straight line between two points is mathematically defined as:

y = mx + c

But instead of directly using this equation, DDA uses incremental changes:

  • If slope (m) ≤ 1 → increment x
  • If slope (m) > 1 → increment y

This ensures smooth line generation.


Steps of DDA Algorithm

Input two points:

  • (x1, y1), 
  • (x2, y2)

Step 1: Calculate Differences

  • ΔX = X2 − X1, ΔY = Y2 − Y1 
  • m = ΔY / ΔX
  • Slope (m) determines which case to apply.

Step 2: Determine Number of Steps

steps = {|ΔX| if |ΔX| > |ΔY|, |ΔY| otherwise 

This ensures:

  • More changes → more steps
  • Covers all types of lines (horizontal, vertical, steep, gentle)

Step 3: Find Next Points (ALL CASES)

Let current point = (Xp, Yp)

Case 1: |m| < 1 (Gentle Slope)

  • X increases by 1
  • Y increases by slope

Xp+1 = Xp+1 Yp+1 ​= Yp​+m

Used when ∣ΔX∣>∣ΔY∣

Case 2: m = 1

  • Equal increments

Xp+1 = Xp+1  and Yp+1​ = Yp​+1

Straight diagonal line

Case 3: |m| > 1 (Steep Slope)

  • Y increases by 1
  • X increases slowly

Xp+1 = Xp + 1/m and Yp+1​ = Yp​+1

Used when |ΔY| > |ΔX|

Case 4: Negative Slope

  • Same formulas apply
  • Values decrease automatically

Xinc, Yinc become negative

Case 5: Vertical Line

  • ΔX = 0

X = constant, and Y = Y + 1 

Case 6: Horizontal Line

  • ΔY = 0

X = X + 1, and Y=constant

Step 4: Repeat

  • Continue until:
    • End point is reached OR
    • Generated points = steps

Key Characteristics

  • Uses floating point calculations
  • Simple and easy to implement
  • Less efficient than Bresenham
  • Produces smooth lines but slightly slower

Advantages and Disadvantages

Advantages:

  • Easy to understand
  • Works for all slopes
  • Simple incremental method

Disadvantages:

  • Uses floating point arithmetic
  • Rounding errors occur
  • Slower compared to integer-based algorithms

Solved Numerical Example 

Case 1: Gentle Slope (|m| < 1)

From (2, 3) → (10, 6)

  • dx = 8, dy = 3
  • steps = 8
  • Xinc = 1, Yinc ​= 0.375

Table:

StepxyRound(x,y)
02.0003.000(2, 3)
13.0003.375(3, 3)
24.0003.750(4, 4)
35.0004.125(5, 4)
46.0004.500(6, 5)
57.0004.875(7, 5)
68.0005.250(8, 5)
79.0005.625(9, 6)
810.0006.000(10, 6)

Case 2: Steep Slope (|m| > 1)

From (2, 2) → (5, 10)

  • dx = 3, dy = 8
  • steps = 8
  • Xinc = 0.375, Yinc​ = 1

Table:

StepxyRound(x,y)
02.0002.000(2, 2)
12.3753.000(2, 3)
22.7504.000(3, 4)
33.1255.000(3, 5)
43.5006.000(4, 6)
53.8757.000(4, 7)
64.2508.000(4, 8)
74.6259.000(5, 9)
85.00010.000(5, 10)

Case 3: m = 1 (Perfect Diagonal)

From (1, 1) → (6, 6)

  • dx = dy = 5
  • steps = 5
  • Xinc = 1, Yinc​ = 1

Table:

StepxyPlot
011(1, 1)
122(2, 2)
233(3, 3)
344(4, 4)
455(5, 5)
566(6, 6)

Case 4: Negative Slope

From (10, 5) → (5, 2)

  • dx = -5, dy = -3
  • steps = 5
  • Xinc = −1, Yinc​= −0.6

Table:

StepxyRound(x,y)
010.05.0(10, 5)
19.04.4(9, 4)
28.03.8(8, 4)
37.03.2(7, 3)
46.02.6(6, 3)
55.02.0(5, 2)

Case 5: Vertical Line

From (4, 2) → (4, 8)

  • dx = 0, dy = 6
  • steps = 6
  • Xinc = 0, Yinc​ = 1

Table:

StepxyPlot
042(4, 2)
143(4, 3)
244(4, 4)
345(4, 5)
446(4, 6)
547(4, 7)
648(4, 8)

Case 6: Horizontal Line

From (3, 5) → (8, 5)

  • dx = 5, dy = 0
  • steps = 5
  • Xinc=1, Yinc​=0

Table:

StepxyPlot
035(3, 5)
145(4, 5)
255(5, 5)
365(6, 5)
475(7, 5)
585(8, 5)

Practice Problems

Try solving these:

  1. Draw line from (0,0) to (5,5)
  2. Draw line from (2,3) to (5,6)
  3. (1,2) to (7,5)
  4. (3,3) to (8,10)
  5. Calculate the points between the starting point (5, 6) and ending point (8, 12).
  6. Calculate the points between the starting point (5, 6) and ending point (13, 10).
  7. Calculate the points between the starting point (1, 7) and ending point (11, 17).

Summary

DDA is a simple line drawing algorithm that works by incrementally calculating intermediate points using slope-based increments. Although easy to implement, it is less efficient than Bresenham’s algorithm due to floating-point calculations.