BIT304 ยท 2079 ยท 10 marks
List the major differences between DDA and Bresenham's algorithm. Illustrate the Bresenham's algorithm to the line with end points(10, 6) and (12, 1).
List the major differences between DDA and Bresenham's algorithm. Illustrate the Bresenham's algorithm to the line with end points(10, 6) and (12, 1).[10]
DDA vs Bresenham's Algorithm & Numerical Illustration
Given
- Endpoint 1: $(x_1, y_1) = (10, 6)$
- Endpoint 2: $(x_2, y_2) = (12, 1)$
Major Differences between DDA and Bresenham's Algorithm
| Feature | DDA Algorithm | Bresenham's Algorithm |
|---|---|---|
| Computation | Uses floating-point arithmetic | Uses only integer arithmetic |
| Speed | Slower (floating-point operations) | Faster (integer operations) |
| Rounding | Requires rounding each step | No rounding needed |
| Accuracy | Less accurate (rounding errors) | More accurate |
| Operations | Multiplication and division | Only addition and subtraction |
| Decision Parameter | None used | Uses decision parameter $p_k$ |
| Efficiency | Less efficient | More efficient |
| Hardware | Difficult to implement | Easy to implement |
STEP 2 - Bresenham's Line: (10, 6) to (12, 1)
Calculate parameters
$$dx = x_2 - x_1 = 12 - 10 = 2$$ $$dy = y_2 - y_1 = 1 - 6 = -5$$ $$|dx| = 2, \quad |dy| = 5$$
Since $|dy| > |dx|$, the line is steep ($|m| > 1$). Drive the algorithm along the y-axis. Here $y$ decreases (6 โ 1) so $y$ steps by $-1$; $x$ increases since $x_2 > x_1$.
Initialize decision parameter
$$p_0 = 2|dx| - |dy| = 2(2) - 5 = -1$$
Constants: $$2|dx| = 4, \qquad 2|dx| - 2|dy| = 4 - 10 = -6$$
Decision rule (steep line, y-axis driven)
- If $p_k < 0$: next point $(x_k,\ y_k - 1)$, and $p_{k+1} = p_k + 2|dx|$
- If $p_k \ge 0$: next point $(x_k + 1,\ y_k - 1)$, and $p_{k+1} = p_k + 2|dx| - 2|dy|$
Iteration Table
| Step $k$ | $p_k$ | Condition | Point $(x, y)$ | $p_{k+1}$ |
|---|---|---|---|---|
| 0 | -1 | $p_0 < 0$ | (10, 6) | $-1 + 4 = 3$ |
| 1 | 3 | $p_1 \ge 0$ | (11, 5) | $3 - 6 = -3$ |
| 2 | -3 | $p_2 < 0$ | (11, 4) | $-3 + 4 = 1$ |
| 3 | 1 | $p_3 \ge 0$ | (12, 3) | $1 - 6 = -5$ |
| 4 | -5 | $p_4 < 0$ | (12, 2) | $-5 + 4 = -1$ |
| 5 | - | - | (12, 1) | - |
Final Plotted Pixels
$$(10, 6) \to (11, 5) \to (11, 4) \to (12, 3) \to (12, 2) \to (12, 1)$$
Conclusion
Bresenham's algorithm avoids floating-point arithmetic, using only integer addition/subtraction and a decision parameter, making it faster, more accurate, and easier to implement in hardware than DDA.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.