Computer Graphics Ā· Unit 3
Line and Circle Drawing Algorithms
Exam-focused notes for Line and Circle Drawing Algorithms (Computer Graphics, BIT304): what the TU syllabus asks and how it has actually been tested, with 7 solved past questions from this unit.
Line and Circle Drawing Algorithms in short
Lines and circles are the most basic shapes in a drawing. Because the screen is a grid of pixels, we need fast algorithms that pick the pixels closest to the true shape.
What this unit covers
- DDA line drawing algorithm
- Bresenham's line drawing algorithm
- Comparison of line drawing algorithms
- Midpoint circle drawing algorithm
- Bresenham's circle drawing algorithm
- Decision parameters for circle generation
DDA line drawing algorithm
2082 Ā· 10 marks
Bresenham's Circle Drawing Algorithm & DDA Line Algorithm Trace [10]
Show solved answerHide answer
Model Answer: Bresenham's Circle Drawing Algorithm & DDA Line Trace [10 marks]
Given Data (Extracted)
Part B (numeric):
- Start point: $(x_1, y_1) = (2, 2)$
- End point: $(x_2, y_2) = (6, 6)$
Part A is descriptive (no numeric inputs required).
Part A: Bresenham's Circle Drawing Algorithm [5 marks]
Definition: Bresenham's circle drawing algorithm is an efficient scan-conversion technique that plots the pixels closest to a true circle using only integer arithmetic. It uses the eight-way symmetry of a circle, so it computes points only for one octant ($0°$ to $45°$) and reflects them to the other seven.
Eight-Way Symmetry: For a point $(x, y)$ on a circle centered at origin, the following also lie on the circle:
$$(x, y),\ (-x, y),\ (x, -y),\ (-x, -y),\ (y, x),\ (-y, x),\ (y, -x),\ (-y, -x)$$
Algorithm Steps:
- Input radius $r$ and center $(x_c, y_c)$.
- Initialize starting point: $x = 0,\ y = r$.
- Compute initial decision parameter: $p_0 = 3 - 2r$.
- At each step, test $p_k$:
- If $p_k < 0$: next point is $(x_k + 1,\ y_k)$ and $p_{k+1} = p_k + 4x_k + 6$
- If $p_k \ge 0$: next point is $(x_k + 1,\ y_k - 1)$ and $p_{k+1} = p_k + 4(x_k - y_k) + 10$
- Plot all 8 symmetric points, translated by adding $(x_c, y_c)$.
- Repeat steps 4-5 until $x \ge y$.
Advantages:
- Uses only integer addition/subtraction (no multiplication or trigonometry)
- Fast and hardware-friendly
- Produces smooth, symmetric circles
Part B: DDA Algorithm Trace - Line from $(2, 2)$ to $(6, 6)$ [5 marks]
Step 1: Compute differences: $$dx = x_2 - x_1 = 6 - 2 = 4$$ $$dy = y_2 - y_1 = 6 - 2 = 4$$
Step 2: Number of steps: $$steps = \max(|dx|, |dy|) = \max(4, 4) = 4$$
Step 3: Increments: $$x_{inc} = \frac{dx}{steps} = \frac{4}{4} = 1, \qquad y_{inc} = \frac{dy}{steps} = \frac{4}{4} = 1$$
Step 4: Iteration Table:
| Step | $x$ | $y$ | Pixel Plotted $(\text{round}(x), \text{round}(y))$ |
|---|---|---|---|
| 0 | 2.0 | 2.0 | (2, 2) |
| 1 | 3.0 | 3.0 | (3, 3) |
| 2 | 4.0 | 4.0 | (4, 4) |
| 3 | 5.0 | 5.0 | (5, 5) |
| 4 | 6.0 | 6.0 | (6, 6) |
Explanation: Slope $m = \dfrac{dy}{dx} = \dfrac{4}{4} = 1$ (a $45°$ line). Both $x$ and $y$ increase by exactly 1 each step, giving a perfect diagonal.
Result: Pixels plotted: $(2,2), (3,3), (4,4), (5,5), (6,6)$ - five pixels forming a continuous diagonal line.
Midpoint circle drawing algorithm
2081 Ā· 5 marks
Digitize circle with center (0, 0) and radius = 6. [5]
Bresenham's line drawing algorithm
2080 Ā· 10 marks
Write the algorithm for Bresenham's line drawing? Digitize a line with end points A(6, 9) and B(10,5) using Bresenham's line drawing algorithm.[10]
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).[10]
Show solved answerHide answer
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.
0 Ā· 5 marks
Derive the Bresenham's decision parameter to draw a line with negative slope. [5]
Decision parameters for circle generation
2079 Ā· 10 marks
How decision parameter can be used to draw circle? Calculate the points to draw a circle having radius 5 and center as (10, 5).[10]
Make Unit 3 stick
Practice BIT304 with flashcards & quizzes