Unit 2: Scan conversion and area filling
Computer Graphics notes · PTU syllabus (BSIT603/BSBC602)
On this page
Unit summary
Every line, circle and filled shape on a raster screen is turned into pixels by scan conversion. This unit covers the process of scan conversion, line, circle and ellipse algorithms, Bresenham's algorithms with derivations, the midpoint circle algorithm, area filling and flood fill, and character generation.
After this unit you can
- Explain scan conversion
- Apply DDA and Bresenham's line algorithms
- Apply midpoint and Bresenham circle and ellipse algorithms
- Fill areas and generate characters
PTU syllabus topics
- Process of scan conversion
- line/circle/ellipse scan conversion algorithms
- Bresenham's algorithms with derivations
- midpoint circle algorithm
- area filling and flood fill techniques
- character generation
Arithmetic
Floating point
Integer only
Speed
Slower
Faster
Accuracy
Rounding errors possible
More accurate
Uses
Simple to understand
Used in practice
Topic 1
The process of scan conversion
- Scan conversion (rasterisation): converting a geometric object defined by continuous coordinates into a set of discrete pixels that best approximate it.
- Problems: aliasing (staircase or jagged edges), unequal brightness of lines at different slopes, and speed; anti-aliasing smooths edges by varying pixel intensities.
Topic 2
Line drawing: direct method and DDA
Slope–intercept form
y = m x + c, where m = (y2 − y1) ÷ (x2 − x1)
Direct method
For each x, compute y = m x + c and round — needs floating-point multiplication
DDA increments
steps = max(abs(Δx), abs(Δy)); x increment = Δx ÷ steps; y increment = Δy ÷ steps
- 1Read endpoints (x1, y1) and (x2, y2)
- 2Compute Δx, Δy and steps
- 3Compute x and y increments
- 4Plot (round(x), round(y))
- 5Add increments and repeat steps times
Example
Line from (2, 3) to (8, 6): Δx = 6, Δy = 3, steps = 6, x increment 1, y increment 0.5. Points: (2,3), (3,3.5→4), (4,4), (5,4.5→5), (6,5), (7,5.5→6), (8,6).
- DDA: simpler than the direct method, but uses floating-point addition and rounding, so errors accumulate.
Topic 3
Bresenham's line algorithm
- Uses only integer addition and subtraction; at each step chooses between two candidate pixels using a decision parameter.
Initial decision parameter
p0 = 2Δy − Δx
If pk < 0
Next pixel (xk + 1, yk); pk+1 = pk + 2Δy
If pk ≥ 0
Next pixel (xk + 1, yk + 1); pk+1 = pk + 2Δy − 2Δx
- Derivation outline: at x = xk + 1 the true y is m(xk + 1) + c. Distances to the two candidates are d1 = y − yk and d2 = (yk + 1) − y. pk = Δx (d1 − d2) = 2Δy·xk − 2Δx·yk + constant has the same sign as d1 − d2, so its sign picks the nearer pixel; subtracting pk from pk+1 gives the update rules above.
Example
Line (20, 10) to (30, 18): Δx = 10, Δy = 8, p0 = 6. Pixels: (21,11) p = 2; (22,12) p = −2; (23,12) p = 14; (24,13) p = 10; (25,14) p = 6; (26,15) p = 2; (27,16) p = −2; (28,16) p = 14; (29,17) p = 10; (30,18).
Topic 4
Circle drawing: polynomial and trigonometric methods
Polynomial
y = ± square root of (r² − x²) for each x
Square roots are slow; gaps where the slope is steep
Trigonometric
x = r cos θ, y = r sin θ for θ in small steps
Trigonometric functions are slow
- Eight-way symmetry: compute one octant and plot (±x, ±y) and (±y, ±x), so only 1/8 of the circle is calculated.
Topic 5
Midpoint and Bresenham's circle algorithms
Start
(0, r); p0 = 1 − r (or 5/4 − r)
If pk < 0
Next (xk + 1, yk); pk+1 = pk + 2xk+1 + 1
Else
Next (xk + 1, yk − 1); pk+1 = pk + 2xk+1 + 1 − 2yk+1
Stop
When x ≥ y
- Derivation idea: f(x, y) = x² + y² − r² is negative inside the circle, zero on it and positive outside. Evaluate f at the midpoint (xk + 1, yk − ½) between the two candidate pixels; its sign tells which pixel is closer.
Example
r = 10: p0 = −9 → (1,10) p = −6 → (2,10) p = −1 → (3,10) p = 6 → (4,9) p = −3 → (5,9) p = 8 → (6,8) p = 5 → (7,7), and the octant is complete.
- Bresenham's circle: d0 = 3 − 2r; if d < 0 then d = d + 4x + 6, else d = d + 4(x − y) + 10 and y decreases.
Topic 6
Ellipse drawing
- Midpoint (Bresenham) ellipse algorithm: uses four-way symmetry and divides the first quadrant into two regions — region 1 where the slope magnitude is less than 1 (step in x) and region 2 where it is greater than 1 (step in y).
Region 1 start
(0, ry); p1 = ry² − rx² ry + rx²/4
Region 1 update
If p1 < 0: p1 = p1 + 2ry² x + ry²; else y decreases and p1 = p1 + 2ry² x − 2rx² y + ry²
Switch to region 2
When 2ry² x ≥ 2rx² y
Region 2
Step y down; decision p2 chooses whether x increases
Topic 7
Area filling
Scan-line polygon fill
For each scan line, find intersections with edges, sort them, fill between pairs
Polygons defined by vertices
Boundary fill
From a seed, colour neighbours until the boundary colour is reached
Regions with one boundary colour
Flood fill
From a seed, replace all connected pixels of the old interior colour
Regions with multi-coloured boundaries; paint bucket tool
cvoid floodFill(int x, int y, int oldColor, int newColor) {
if (getpixel(x, y) == oldColor) {
putpixel(x, y, newColor);
floodFill(x + 1, y, oldColor, newColor); /* 4-connected */
floodFill(x - 1, y, oldColor, newColor);
floodFill(x, y + 1, oldColor, newColor);
floodFill(x, y - 1, oldColor, newColor);
}
}- 4-connected fill checks four neighbours; 8-connected also checks diagonals. Recursion can overflow the stack for large areas, so scan-line seed fill with an explicit stack is used in practice.
Topic 8
Character generation
Bitmap (dot-matrix) method
Each character as a grid of pixels, e.g., 5 × 7 or 8 × 8
Fast, simple; poor scaling
Stroke (vector) method
Sequence of line and curve segments
Scales and rotates well
Outline fonts
Curves (Bézier or B-splines) filled at display time
TrueType and OpenType; high quality at any size
Key terms
- Scan conversion
- Converting geometric shapes into pixels
- Aliasing
- Jagged appearance of lines on a raster display
- Decision parameter
- Integer value deciding the next pixel in Bresenham's algorithms
- Eight-way symmetry
- Property used to plot a circle from one octant
- Flood fill
- Filling all connected pixels of an interior colour from a seed
Quick revision
- Scan conversion, aliasing, anti-aliasing.
- Direct method; DDA with increments; Bresenham's line p0 = 2Δy − Δx.
- Circle by polynomial and trig; eight-way symmetry; midpoint p0 = 1 − r; Bresenham d0 = 3 − 2r.
- Midpoint ellipse with two regions.
- Scan-line, boundary and flood fill; 4- and 8-connected; bitmap, stroke and outline characters.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.What is scan conversion?
- Q2.State one drawback of the DDA algorithm.
- Q3.Write the initial decision parameter of Bresenham's line algorithm.
- Q4.What is eight-way symmetry?
- Q5.Distinguish boundary fill and flood fill.
- Q6.Distinguish bitmap and stroke fonts.
Long-answer questions
- Q1.Explain and compare the DDA and Bresenham's line algorithms with an example.
- Q2.Derive Bresenham's line algorithm.
- Q3.Explain the midpoint circle algorithm with an example.
- Q4.Explain area filling algorithms and character generation.
Stuck on this unit?
Message SBS on WhatsApp for help with Computer Graphics, or to ask about studying B.Sc IT at Synetic.
