2080 1

CSC214 ยท 2080 ยท 10 marks

What is a Digital Differential Analyzer (DDA)? How can you draw the line using this algorithm? Trace the points on the line path between A (1,3) and B (6,7) using Bresenham's line drawing algorithm.

What is a Digital Differential Analyzer (DDA)? How can you draw the line using this algorithm? Trace the points on the line path between A (1,3) and B (6,7) using Bresenham's line drawing algorithm.[10]

Computer GraphicsChapter 2: Scan Conversion AlgorithmScan Converting a Point and a straight LineNumerical: Bresenham's line algorithm

Digital Differential Analyzer (DDA) and Bresenham's Line Drawing

Part 1: What is DDA?

A Digital Differential Analyzer (DDA) is an incremental scan-conversion line drawing algorithm. It computes points along a line by sampling the line at unit intervals in one coordinate and calculating the corresponding value of the other coordinate using the line's slope. It uses floating-point arithmetic and rounding.

Drawing a line using DDA

For endpoints $(x_1, y_1)$ and $(x_2, y_2)$:

  1. Compute $dx = x_2 - x_1$, $dy = y_2 - y_1$.
  2. Determine steps: $$\text{steps} = \max(|dx|, |dy|)$$
  3. Compute increments: $$x_{inc} = \frac{dx}{\text{steps}}, \quad y_{inc} = \frac{dy}{\text{steps}}$$
  4. Start at $(x_1, y_1)$. Repeatedly add increments: $$x = x + x_{inc}, \quad y = y + y_{inc}$$
  5. Plot $(\text{round}(x), \text{round}(y))$ at each step until all steps done.

DDA is simple but slower and prone to rounding error accumulation because of floating-point operations.


Part 2: Bresenham's Line Drawing Algorithm

Bresenham's algorithm uses only integer addition, subtraction and comparison, avoiding floating point. It chooses the next pixel using a decision parameter.

For a line with $0 \le m \le 1$:

  1. $dx = x_2 - x_1$, $dy = y_2 - y_1$
  2. Initial decision parameter: $p_0 = 2dy - dx$
  3. Plot $(x_1, y_1)$
  4. At each step:
    • If $p_k < 0$: $x_{k+1} = x_k + 1$, $y_{k+1} = y_k$, and $p_{k+1} = p_k + 2dy$
    • If $p_k \ge 0$: $x_{k+1} = x_k + 1$, $y_{k+1} = y_k + 1$, and $p_{k+1} = p_k + 2dy - 2dx$
  5. Repeat $dx$ times.

Part 3: Tracing A(1,3) to B(6,7) using Bresenham

Given

  • $(x_1, y_1) = (1, 3)$
  • $(x_2, y_2) = (6, 7)$

Step 1: Compute dx, dy

$$dx = 6 - 1 = 5, \quad dy = 7 - 3 = 4$$

Slope $m = 4/5 = 0.8$, so $0 \le m \le 1$; step along x. Total steps $= dx = 5$.

Step 2: Initial decision parameter

$$p_0 = 2dy - dx = 2(4) - 5 = 8 - 5 = 3$$

Step 3: Constants

$$2dy = 8, \quad 2dy - 2dx = 8 - 10 = -2$$

Step 4: Iteration table

Plot starting point $(1,3)$.

k$p_k$Condition$x_{k+1}$$y_{k+1}$$p_{k+1}$
03$\ge 0$24$3 - 2 = 1$
11$\ge 0$35$1 - 2 = -1$
2-1$< 0$45$-1 + 8 = 7$
37$\ge 0$56$7 - 2 = 5$
45$\ge 0$67$5 - 2 = 3$

Step 5: Final plotted points

$$\boxed{(1,3),\ (2,4),\ (3,5),\ (4,5),\ (5,6),\ (6,7)}$$

Six pixels are plotted, ending exactly at B(6,7). โœ“

Grid visualization

7 |                     * B(6,7)
6 |                *
5 |         *   *
4 |     *
3 | * A(1,3)
  +----------------------
    1   2   3   4   5   6

The verification confirms the endpoint (6,7) is reached correctly.

Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.