2D and 3D Geometric Transformations, Viewing and Rendering

This chapter closes Unit 3's Computer Graphics content with everything downstream of a raw drawn primitive: the matrix machinery (homogeneous coordinates) that lets 2D and 3D transformations compose uniformly, the viewing pipeline that maps a defined world onto a screen, clipping algorithms that discard what falls outside the view, and 3D-specific topics — surface representation, spline curves, illumination models and rendering. None of this has a GATE CS equivalent.

2D Transforms, Matrix Representation and Homogeneous Coordinates

The four basic 2D transforms
TransformEffect
TranslationShifts every point by a fixed (tx, ty) — cannot be expressed as a 2x2 linear matrix multiply on (x, y) alone, which is exactly the problem homogeneous coordinates solve.
ScalingMultiplies x and y by sx, sy about the origin — uniform if sx = sy, else the shape distorts.
RotationRotates about the origin by angle θ using cos θ / sin θ entries — a rigid transform, preserving lengths and angles.
Reflection / ShearReflection flips about an axis (negating one coordinate); shear slides one coordinate proportionally to the other, distorting a square into a parallelogram.
🎯 Why homogeneous coordinates exist: to make translation a matrix multiply too
Scaling and rotation are LINEAR (expressible as a 2x2 matrix times (x, y)), but translation is AFFINE, not linear — it adds a constant rather than scaling the input, and no 2x2 matrix can produce that addition from (x, y) alone. Homogeneous coordinates add a third coordinate, representing a 2D point as (x, y, 1), which lets translation ALSO be written as a 3x3 matrix multiply — and once every transform is a matrix, composing several of them (rotate then translate then scale) becomes a single matrix multiplication of all three matrices together, applied once.
⚠️ Composite transform order is not commutative
Matrix multiplication does not commute in general, so 'rotate then translate' and 'translate then rotate' produce genuinely different results — rotating an off-origin object first spins it about the ORIGIN before it is moved, while translating first moves it away from the origin and rotating then spins it about the origin along a different arc. The order the matrices are applied in must match the order the transforms are intended to happen in.

The Viewing Pipeline, Window-to-Viewport, and Clipping

A scene is defined in WORLD coordinates, but a program picks a window — a rectangular region of world coordinates it wants to display — and maps it to a viewport — a rectangular region of the actual screen/device it appears in. The window-to-viewport transform is itself a composite transform: translate the window's corner to the origin, scale by the ratio of viewport size to window size, then translate to the viewport's actual screen position — the classic worked example of composing several basic transforms into one useful matrix. Clipping then discards whatever falls outside the window BEFORE this mapping (clipping in world/window coordinates is more efficient than clipping every pixel after mapping to the screen).

  • Cohen-Sutherland line clipping: assigns each endpoint a 4-bit OUTCODE recording which of the window's four boundaries it lies beyond; a line is trivially ACCEPTED if both outcodes are 0000, trivially REJECTED if the bitwise AND of the two outcodes is non-zero (both endpoints share a violated boundary, so the whole segment must lie outside it), and otherwise clipped iteratively against one boundary at a time.
  • Sutherland-Hodgman polygon clipping: clips a polygon against one window edge at a time, processing the polygon's vertices in order and outputting 0, 1 or 2 vertices per input vertex depending on whether it and its predecessor are inside/outside that edge — repeating for all four window edges in turn correctly clips even a concave polygon.

3D Object Representation: Polygon and Quadric Surfaces, Splines

  • Polygon surfaces (meshes): a 3D solid is approximated by a mesh of flat polygonal faces (usually triangles), each stored as a list of vertex coordinates plus connectivity — the standard representation for arbitrary, irregular shapes and the format most rendering hardware is built around.
  • Quadric surfaces: described by a single second-degree (quadratic) equation in x, y, z — spheres, ellipsoids, cylinders, cones and paraboloids are all quadrics, and being described by one compact equation rather than a mesh of many polygons is exactly what makes them cheap to represent and test exactly (no polygon-approximation error).
  • Bezier curves: defined by n+1 control points via Bernstein polynomial blending; the curve passes through the FIRST and LAST control points only (interpolating them) while the interior control points merely INFLUENCE its shape (approximating it), and the whole curve lies within the convex hull of its control points — moving any one control point affects the ENTIRE curve's shape (no local control).
  • B-spline curves: generalise Bezier curves with a KNOT VECTOR that gives each control point only LOCAL influence — moving one control point changes only a bounded neighbourhood of the curve, unlike a Bezier curve, which is the single most-tested distinction between the two in this sub-item.

Illumination Models, Polygon Rendering and Projections

A basic illumination (lighting) model sums three components: AMBIENT light (a constant approximation of indirect, scattered light with no direction), DIFFUSE reflection (depends on the angle between the surface normal and the light direction via Lambert's cosine law — brightest when the light is head-on, zero when it grazes the surface, but scattered equally in every viewing direction), and SPECULAR reflection (the bright highlight that depends additionally on the VIEWER's direction, tightest and brightest for a shiny surface and modelled by the Phong model as a high power of the cosine between the reflected-light direction and the viewer direction).

  • Polygon rendering methods: CONSTANT (flat) shading colours a whole polygon face uniformly using one normal per face — fast, but visibly faceted; GOURAUD shading interpolates COLOUR values computed at each vertex across the face — smoother, but can miss a sharp specular highlight that falls between vertices; PHONG shading interpolates the surface NORMAL itself across the face and computes lighting per pixel — the most accurate and most expensive, capturing highlights the other two miss.
  • Projection transforms: PARALLEL (orthographic) projection preserves relative proportions regardless of distance from the viewer (parallel lines stay parallel) and is used for technical/engineering drawing; PERSPECTIVE projection converges parallel lines toward vanishing points and makes distant objects appear smaller, matching how human vision and cameras actually work, at the cost of distorting exact measurements.

Key takeaways

  • Homogeneous coordinates turn translation into a matrix multiply too, letting several transforms compose into one matrix — but composite order is not commutative.
  • Window-to-viewport mapping is itself a composite transform; clipping (Cohen-Sutherland for lines via outcodes, Sutherland-Hodgman for polygons edge by edge) happens before this mapping.
  • Bezier curves interpolate only their first/last control points with global influence; B-splines generalise this with local control via a knot vector.
  • Illumination sums ambient, diffuse (Lambert, direction-independent for the viewer) and specular (Phong, viewer-direction-dependent) components.
  • Flat shading is fastest but faceted; Gouraud interpolates vertex colours; Phong interpolates normals per pixel and is the most accurate but most expensive.

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.

  1. Homogeneous coordinates are introduced in 2D graphics chiefly because:

    1. Translation is affine, not linear, and cannot be expressed as a 2x2 matrix multiply on (x, y) alone
    2. They make rotation impossible to compute
    3. They are required only for 1D graphics
    4. They eliminate the need for a viewport entirely
    Show answer

    Answer: A — Translation is affine, not linear, and cannot be expressed as a 2x2 matrix multiply on (x, y) alone

    Adding a third coordinate lets translation, like scaling and rotation, be expressed as a matrix multiply, so a sequence of transforms can be composed into one matrix rather than applied as separate operations of different kinds.
  2. Rotating an off-origin object and then translating it, compared to translating it first and then rotating:

    1. Generally produces a different final result, since matrix multiplication does not commute
    2. Always produces exactly the same result
    3. Is undefined behaviour
    4. Only differs for 3D objects, never for 2D ones
    Show answer

    Answer: A — Generally produces a different final result, since matrix multiplication does not commute

    Rotating first spins the object about the origin before it moves; translating first moves it away from the origin so a subsequent rotation swings it through a different arc — the order genuinely changes the outcome.
  3. In Cohen-Sutherland line clipping, a line is trivially rejected when:

    1. The bitwise AND of the two endpoints' outcodes is non-zero
    2. The bitwise OR of the two endpoints' outcodes is zero
    3. Both endpoints are inside the window
    4. The line is exactly horizontal
    Show answer

    Answer: A — The bitwise AND of the two endpoints' outcodes is non-zero

    A non-zero AND means both endpoints lie beyond the same boundary, so the entire segment must lie on the outside of that boundary and can be discarded with no further clipping computation; a zero OR (both outcodes 0000) is instead the trivial-ACCEPT case.
  4. A quadric surface, such as a sphere or a cylinder, is best described as:

    1. A surface described by a single second-degree equation in x, y, z
    2. Always represented by thousands of small triangles with no equation
    3. A one-dimensional curve, not a surface
    4. Definable only in two dimensions
    Show answer

    Answer: A — A surface described by a single second-degree equation in x, y, z

    Quadrics are compactly described by one quadratic equation, which is exactly what lets them be represented and rendered exactly rather than approximated by a polygon mesh with its attendant approximation error.
  5. The key difference between a Bezier curve and a B-spline curve is:

    1. A B-spline gives each control point only local influence, via a knot vector; moving a Bezier control point affects the whole curve
    2. A Bezier curve is always a straight line
    3. A B-spline cannot be drawn on a raster display
    4. There is no difference; the two terms are synonyms
    Show answer

    Answer: A — A B-spline gives each control point only local influence, via a knot vector; moving a Bezier control point affects the whole curve

    A Bezier curve's control points each influence the ENTIRE curve's shape (global control); a B-spline's knot vector restricts each control point's influence to a bounded neighbourhood (local control) — the single most commonly tested distinction between the two.
  6. Diffuse reflection in the basic illumination model depends on:

    1. The angle between the surface normal and the light source direction, but not the viewer's direction
    2. Only the viewer's direction, not the light's
    3. Neither the light's direction nor the viewer's
    4. The object's mass
    Show answer

    Answer: A — The angle between the surface normal and the light source direction, but not the viewer's direction

    Lambert's cosine law makes diffuse reflection depend only on the angle between the surface normal and the incoming light direction, scattering equally in every viewing direction — it is specular reflection, not diffuse, that additionally depends on the viewer's own direction.
  7. Which of the following are true of Phong shading compared to Gouraud shading? (More than one option may be correct.)

    1. Phong interpolates the surface normal per pixel; Gouraud interpolates colour values computed at the vertices
    2. Phong is generally more computationally expensive
    3. Phong can capture a sharp specular highlight that falls between vertices, which Gouraud may miss
    4. Both produce identical output in every case
    Show answer

    Answer: A — Phong interpolates the surface normal per pixel; Gouraud interpolates colour values computed at the vertices; B — Phong is generally more computationally expensive; C — Phong can capture a sharp specular highlight that falls between vertices, which Gouraud may miss

    Phong's per-pixel normal interpolation and lighting computation is more accurate and more expensive than Gouraud's per-vertex colour interpolation, and this accuracy is exactly what lets it capture highlights Gouraud's coarser colour interpolation smooths away.
  8. Name the type of projection that converges parallel lines toward vanishing points and makes distant objects appear smaller, matching how human vision actually works.

    Numerical answer — type the value.

    Show answer

    Answer: perspective

    Perspective projection distorts exact parallel/proportional relationships (unlike orthographic/parallel projection) in exchange for matching natural depth perception, which is why it is used for realistic rendering rather than technical drawing.