Computer Graphics Fundamentals
Line-Drawing Algorithms
- DDA (Digital Differential Analyzer): for slope m = Δy/Δx with |m| ≤ 1, step x by 1 each iteration and accumulate y += m, rounding to the nearest pixel — simple, but its floating-point accumulation is slower and accumulates rounding error over a long line.
- Bresenham's algorithm: reformulates the same decision using only INTEGER arithmetic by tracking a decision variable that measures which of two candidate next pixels is closer to the true line — this avoids floating point entirely, is exact (no accumulated rounding drift) and is the standard production algorithm for exactly that reason.
Midpoint Circle and Ellipse Algorithms
- Midpoint circle algorithm: exploits EIGHT-WAY (octant) symmetry — computing pixels for just one 45° octant and reflecting them into the other seven — and at each step tests a decision parameter based on the midpoint between two candidate pixels to choose which one is closer to the true circle, again with pure integer updates.
- Midpoint ellipse algorithm: the same idea, but with only FOUR-WAY (quadrant) symmetry, since an ellipse's two radii differ, and it is split into TWO REGIONS (where the curve's slope is above versus below −1, i.e. where it is 'more horizontal' versus 'more vertical'), with a separate stepping rule and decision parameter for each region.
Scan-Line Polygon Fill, Boundary-Fill and Flood-Fill
- Scan-line polygon fill: for each horizontal scan line, find its intersections with the polygon's edges, sort them by x, and fill the pixels between each PAIR of intersections (using the even-odd or nonzero winding rule to decide interior versus exterior when the polygon is concave or self-intersecting).
- Boundary-fill and flood-fill: both start from a seed pixel inside a region and spread to neighbours (4-connected or 8-connected). Boundary-fill stops spreading at pixels matching a specific BOUNDARY colour; flood-fill instead replaces every pixel matching the region's OLD interior colour with a new one, regardless of any separately-defined boundary — the right choice depends on whether the region is bounded by one consistent colour or defined by its own current fill colour.
Key takeaways
- A raster-scan display refreshes a full frame buffer at a fixed rate and handles filled areas naturally; a random-scan (vector) display steers a beam along outlines and is prone to flicker with a long display list.
- Bresenham's line algorithm uses pure integer arithmetic and is exact, unlike DDA's floating-point accumulation which drifts over a long line.
- The midpoint circle algorithm uses eight-way symmetry; the midpoint ellipse algorithm uses only four-way symmetry and splits into two slope regions, since the two radii differ.
- Scan-line polygon fill fills between pairs of edge-intersections per row; the winding rule decides interior/exterior for concave or self-intersecting polygons.
- Boundary-fill stops at a defined boundary colour; flood-fill replaces every pixel of the old interior colour — the right choice depends on how the region is defined.
Practice questions (8)
Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.
A raster-scan display, compared to a random-scan (vector) display:
Show answer
Answer: A — Handles filled areas naturally since every pixel in the frame buffer can be individually coloured
A raster display refreshes its whole pixel grid regardless of content, so filled regions are just as natural as outlines; the other three options describe a random-scan (vector) display instead.Bresenham's line-drawing algorithm is preferred over DDA chiefly because it:
Show answer
Answer: A — Uses only integer arithmetic and is exact, with no accumulated rounding drift
Bresenham reformulates the pixel-choice decision as integer addition/subtraction on a decision variable, avoiding both the speed cost and the cumulative rounding error of DDA's floating-point accumulation.The midpoint circle algorithm exploits symmetry to compute pixels for only:
Show answer
Answer: A — One octant (45°), reflecting the rest into the other seven
A circle's eight-way symmetry means computing one 45° octant's pixels and reflecting them (swapping and negating x/y coordinates appropriately) gives all eight octants for free.The midpoint ellipse algorithm needs two separate regions (unlike the circle algorithm's single octant), chiefly because:
Show answer
Answer: A — An ellipse has only four-way (quadrant) symmetry since its two radii differ, and its slope crosses −1 within one quadrant
With unequal radii, an ellipse's octant-level symmetry breaks down to only quadrant-level, and within one quadrant the curve's slope still crosses −1, requiring a different stepping direction (and decision parameter) on either side of that crossing.Scan-line polygon filling fills pixels between:
Show answer
Answer: A — Each pair of consecutive edge-intersections on a scan line, sorted by x
For each scan line, the edge-intersections are sorted by x-coordinate and interior spans alternate with exterior spans between consecutive intersections — filling between each pair is what produces the correct interior, including for concave shapes.Flood-fill, compared to boundary-fill, decides where to stop spreading by:
Show answer
Answer: A — Replacing every pixel matching the region's old interior colour, regardless of any separately-defined boundary
Boundary-fill is defined against a fixed boundary colour; flood-fill instead uses the region's own current (old) interior colour as the criterion, replacing every matching pixel with the new colour — which is why it works even on regions with no single consistently-coloured boundary.Which of the following are true of random-scan (vector) displays? (More than one option may be correct.)
Show answer
Answer: A — The electron beam is steered directly along the outlines to be drawn; B — They can flicker if the display list is too long to redraw within the persistence time
The first two describe random-scan displays correctly; the last two describe raster-scan displays instead — a frame buffer and natural handling of filled areas are raster properties, not vector ones.Name the line-drawing algorithm that reformulates the pixel-choice decision using only integer arithmetic, avoiding the accumulated rounding drift of the DDA method.
Numerical answer — type the value.
Show answer
Answer: Bresenham
Bresenham's algorithm is the standard integer-only, exact line-drawing method, and its decision-variable technique generalises to the midpoint circle and ellipse algorithms as well.