Computer Graphics and Animation
Comprehensive exam revision notes for BCA-305N Unit 3 (Scan Conversion Algorithms for Primitives & Curves). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.
Computer Graphics and Animation
Scan Conversion Algorithms for Primitives & Curves
Core Definitions & Key Concepts
What is Scan Conversion
Scan Conversion (or rasterization) is the algorithmic process of digitizing continuous mathematical geometric descriptions of graphics primitives (lines, circles, polygons) into discrete pixel coordinate arrays in the frame buffer.
State the core formulation of the DDA (Digital Differential Analyzer) Line Algorithm
DDA calculates differential increments \Delta x and \Delta y. For slope |m| ≤ 1: step \Delta x = 1, and y_{k+1} = y_k + m. For |m| > 1: step \Delta y = 1, and x_{k+1} = x_k + \frac{1}{m}.
Why is Bresenham's Line Algorithm superior to DDA
DDA uses floating-point additions and round() operations at each pixel step. Bresenham's algorithm uses pure integer arithmetic and fast bit-shift additions without any floating-point calculations or rounding.
What is the initial decision parameter p_0 in Bresenham's Line Algorithm
For line from (x_1, y_1) to (x_2, y_2) with \Delta x = x_2 - x_1 and \Delta y = y_2 - y_1 (0 ≤ m ≤ 1): $p_0 = 2\Delta y - \Delta x$
The 8-way symmetry of a Circle
If a point (x, y) lies on a circle centered at origin x^2 + y^2 = r^2, seven other symmetric points can be generated without recalculation: (y, x), (-y, x), (-x, y), (-x, -y), (-y, -x), (y, -x), (x, -y).
What is the initial decision parameter in the Midpoint Circle Algorithm
Evaluating circle function at midpoint (1, r - 1/2): $p_0 = \frac{5}{4} - r ≈ 1 - r \quad (for integer radii)$
What is the difference between Boundary Fill and Flood Fill algorithms
- Boundary Fill: Paints pixels until a specified boundary color edge is encountered.
- Flood Fill: Replaces all connected pixels of an existing target interior color with a new replacement color (used when boundaries are multi-colored).
What is 4-connected vs 8-connected polygon fill
- 4-connected: Only tests adjacent horizontal and vertical neighbors (x\pm 1, y), (x, y\pm 1).
- 8-connected: Tests horizontal, vertical, and all four diagonal neighbors, preventing leakages across diagonally touching boundaries.
What is the parity rule in Scanline Polygon Fill
A scanline counts how many polygon edges it intersects from left to right. Starting outside (odd/even parity initialized to even), parity inverts at each edge intersection: Odd = Inside (fill pixels), Even = Outside (do not fill).
What is the Midpoint Ellipse Algorithm's two regions
The first quadrant of an ellipse is divided into: Region 1 where slope |dy/dx| < 1 (step in x), and Region 2 where |dy/dx| ≥ 1 (step in y).
Conceptual & Architectural Analysis
Compare DDA Line Algorithm vs Bresenham's Line Algorithm
| Attribute | DDA Algorithm | Bresenham's Algorithm |
|---|---|---|
| Arithmetic | Floating-point additions & divisions | Pure integer additions and subtractions |
| Rounding | Requires explicit round() per pixel | No rounding needed; exact decision variable |
| Speed | Slower due to floating-point unit | Blazing fast, hardware-implementable |
| Accuracy | Cumulative rounding errors can drift | Exact, mathematically optimal line path |
| Multiplication | Division \frac{1}{m} or multiplication | Only multiplication by 2 (bit-shift << 1) |
The Midpoint Circle Generation Decision Rules
At step k, with current pixel (x_k, y_k), test midpoint between candidate pixels E(x_k+1, y_k) and SE(x_k+1, y_k-1):
- Decision parameter p_k = f_{circle}(x_k + 1, y_k - 1/2).
- If $p_k < 0$: Midpoint is inside circle \implies Choose East pixel (x_{k+1} = x_k + 1, y_{k+1} = y_k).
$p_{k+1} = p_k + 2x_{k+1} + 1$
- If $p_k \ge 0$: Midpoint is outside/on circle \implies Choose South-East pixel (x_{k+1} = x_k + 1, y_{k+1} = y_k - 1).
$p_{k+1} = p_k + 2x_{k+1} + 1 - 2y_{k+1}$
The Recursive Boundary Fill Algorithm
1void boundaryFill4(int x, int y, int fillColor, int boundaryColor) {2 int current = getPixel(x, y);3 if (current != boundaryColor && current != fillColor) {4 setPixel(x, y, fillColor);5 boundaryFill4(x + 1, y, fillColor, boundaryColor); // Right6 boundaryFill4(x - 1, y, fillColor, boundaryColor); // Left7 boundaryFill4(x, y + 1, fillColor, boundaryColor); // Up8 boundaryFill4(x, y - 1, fillColor, boundaryColor); // Down9 }10}- Uses recursion to explore neighbors; high stack memory consumption on large regions.
The Edge Table (ET) and Active Edge Table (AET) in Scanline Polygon Filling
- Edge Table (ET): Stores all non-horizontal polygon edges sorted by their minimum y-coordinate (y_{\min}). Contains y_{\max}, current x, and slope inverse 1/m.
- Active Edge Table (AET): Stores edges intersecting the current scanline y. Edges are sorted by current x. Pixels are filled in pairs between consecutive edges; x is updated as x_{k+1} = x_k + 1/m.
Antialiasing Techniques in Scan Conversion
- Supersampling (Post-filtering): Render scene at higher internal resolution (e.g., 4×) and average subpixel color intensities into the display pixel.
- Area Sampling (Pre-filtering): Calculate the exact geometric fractional area of the pixel box covered by the primitive line/polygon and scale the pixel intensity proportionally.
In-Depth Analysis & Implementation
Provide the Complete Mathematical Derivation of Bresenham's Line Drawing Algorithm for 0 ≤ m ≤ 1 with a Worked Numerical Problem
Derivation of Bresenham's Integer Line Algorithm
y-axis
^
| Line Equation: y = m(x+1) + c
| *
| (x_k+1, y_k+1) [ Pixel T ] d2
| +-------+
| | |
| ---------+-------+---------- Actual Line Point (y)
| | |
| (x_k+1, y_k) [ Pixel S ] d1
+-------------------------------------------> x-axis
x_k x_k+11. Geometric Distances Formulation:
At step x_{k+1} = x_k + 1, the vertical line coordinate is y = m(x_k + 1) + c. Candidate pixels are S(x_k + 1, y_k) and T(x_k + 1, y_k + 1):
- Distance d_1 = y - y_k = m(x_k + 1) + c - y_k
- Distance d_2 = (y_k + 1) - y = y_k + 1 - m(x_k + 1) - c
2. Difference Between Distances:
$d_1 - d_2 = 2m(x_k + 1) - 2y_k + 2c - 1 Substitute slope m = \frac{\Delta y}{\Delta x} and multiply by \Delta x to eliminate fractions: p_k = \Delta x (d_1 - d_2) = 2\Delta y \cdot x_k - 2\Delta x \cdot y_k + C Where constant C = 2\Delta y + \Delta x (2c - 1)$.
3. Recurrence Relation for Subsequent Step:
$p_{k+1} - p_k = 2\Delta y (x_{k+1} - x_k) - 2\Delta x (y_{k+1} - y_k) Since x{k+1} - xk = 1: p_{k+1} = p_k + 2\Delta y - 2\Delta x (y_{k+1} - y_k)$
- If $p_k < 0$: Pixel S is closer (d_1 < d_2). Choose y_{k+1} = y_k:
$p_{k+1} = p_k + 2\Delta y$
- If $p_k \ge 0$: Pixel T is closer. Choose y_{k+1} = y_k + 1:
$p_{k+1} = p_k + 2\Delta y - 2\Delta x$
4. Initial Parameter p_0:
At start point (x_0, y_0) with c = y_0 - m x_0: $p_0 = 2\Delta y - \Delta x$
5. Worked Numerical Example:
- Rasterize line from (20, 10) to (30, 18):
- \Delta x = 30 - 20 = 10, \quad \Delta y = 18 - 10 = 8
- 2\Delta y = 16, \quad 2\Delta y - 2\Delta x = 16 - 20 = -4
- p_0 = 2(8) - 10 = \mathbf{6}
| k | p_k | Chosen (x_{k+1}, y_{k+1}) | Next p_{k+1} |
|---|---|---|---|
| 0 | 6 (≥ 0) | (21, 11) | 6 + (-4) = 2 |
| 1 | 2 (≥ 0) | (22, 12) | 2 + (-4) = -2 |
| 2 | -2 (< 0) | (23, 12) | -2 + 16 = 14 |
| 3 | 14 (≥ 0) | (24, 13) | 14 + (-4) = 10 |
| 4 | 10 (≥ 0) | (25, 14) | 10 + (-4) = 6 |
| 5 | 6 (≥ 0) | (26, 15) | 6 + (-4) = 2 |
| 6 | 2 (≥ 0) | (27, 16) | 2 + (-4) = -2 |
| 7 | -2 (< 0) | (28, 16) | -2 + 16 = 14 |
| 8 | 14 (≥ 0) | (29, 17) | 14 + (-4) = 10 |
| 9 | 10 (≥ 0) | (30, 18) | Target Reached! |
Derive and Implement the Midpoint Circle Generation Algorithm in Python
1def midpoint_circle(radius, xc=0, yc=0):2 """Midpoint Circle Generation Algorithm."""3 x = 04 y = radius5 p = 1 - radius # Initial decision parameter for integer radius6 7 pixels = []8 9 def add_symmetric_points(cx, cy, px, py):10 return [11 (cx + px, cy + py), (cx - px, cy + py),12 (cx + px, cy - py), (cx - px, cy - py),13 (cx + py, cy + px), (cx - py, cy + px),14 (cx + py, cy - px), (cx - py, cy - px)15 ]16 17 pixels.extend(add_symmetric_points(xc, yc, x, y))18 19 while x < y:20 x += 121 if p < 0:22 p += 2 * x + 123 else:24 y -= 125 p += 2 * (x - y) + 126 pixels.extend(add_symmetric_points(xc, yc, x, y))27 28 return sorted(list(set(pixels)))29
30# Calculate points for Circle radius 8 centered at (0,0)31circle_pts = midpoint_circle(8)32print(f"Generated {len(circle_pts)} unique pixel points for radius 8 circle.")33print("First Octant Points:", [pt for pt in circle_pts if 0 <= pt[0] <= pt[1] and pt[1] > 0][:5])The Scanline Polygon Fill Algorithm with Full Edge Table Structure and Parity Handling
Scanline Polygon Fill Architecture
Scanline y=6 --------+=============+--------------------> (Inverts Parity: OUT -> IN -> OUT)
| POLYGON |
Scanline y=4 ----+===+=============+===+----------------> (4 Intersections: OUT -> IN -> OUT -> IN -> OUT)
| |Data Structures:
- Edge Tuple:
(ymax, x_with_ymin, 1/m) - Edge Table (ET): Linked list array indexed from y_{\min} to y_{\max} of the polygon bounding box.
- Active Edge Table (AET): Dynamic list of edges intersecting current scanline y, sorted strictly by ascending x.
Algorithm Execution Steps:
- Construct ET by inserting non-horizontal edges at
ET[ymin]. - Initialize empty AET. Set current scanline y to smallest non-empty index in ET.
- While AET or ET is not empty:
a. Move edges whose y_{\min} = y from ET to AET. b. Remove edges from AET whose y_{\max} = y (expired edges). c. Sort AET edges by x-coordinate. d. Pair consecutive edges (e_1, e_2), (e_3, e_4) and fill all pixels from x_1 to x_2 on scanline y. e. Increment y by 1. f. For each edge remaining in AET, update x = x + 1/m.
Important Exam Points & Quick Revision
Examiners frequently ask: Bresenham Line derivation with step-by-step numerical table (10-15 marks), Midpoint Circle algorithm, and Scanline Polygon fill parity rule.
100% left on this page — finishing it closes the gap for Scan Conversion Algorithms for Primitives & Curves.
Scan Conversion Algorithms for Primitives & Curves still counts as a weak topic until you finish this note and answer its questions.
Practise this unitTest Your Understanding
Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.