Unit 3: 2D transformations and clipping
Computer Graphics notes · PTU syllabus (BSIT603/BSBC602)
On this page
- Unit summary
- Cartesian and homogeneous coordinates
- Translation, scaling and rotation
- Reflection and shearing
- Composite transformations
- 2D viewing transformation
- Line clipping: Cohen–Sutherland
- Line clipping: Liang–Barsky
- Polygon clipping: Sutherland–Hodgman
- Text clipping
- Key terms
- Quick revision
- Important questions
Unit summary
Transformations move, resize and rotate objects; clipping removes what lies outside the view. This unit covers Cartesian and homogeneous coordinates, translation, scaling, rotation, reflection and shearing, the 2D viewing transformation, line, polygon and text clipping, and the Cohen–Sutherland, Sutherland–Hodgman and Liang–Barsky algorithms.
After this unit you can
- Use homogeneous coordinates and transformation matrices
- Apply and compose 2D transformations
- Explain the window-to-viewport transformation
- Apply line, polygon and text clipping algorithms
PTU syllabus topics
- Cartesian and homogeneous coordinate systems
- geometric transformations (translation, scaling, rotation, reflection, shearing)
- 2D viewing transformation
- line/polygon/text clipping
- Cohen-Sutherland
- Sutherland-Hodgeman and Liang-Barsky clipping algorithms
Translation
x' = x + tx, y' = y + ty
Scaling
x' = sx · x, y' = sy · y
Rotation
x' = x cosθ − y sinθ, y' = x sinθ + y cosθ
Reflection about x-axis
x' = x, y' = −y
Shear in x
x' = x + shx · y
Topic 1
Cartesian and homogeneous coordinates
- Cartesian coordinates (x, y) locate points relative to perpendicular axes.
- Homogeneous coordinates write a 2D point as (x, y, 1), or (xh, yh, h) with x = xh ÷ h. This lets all transformations, including translation, be written as 3 × 3 matrix multiplications, so a sequence of transformations combines into one matrix.
Topic 2
Translation, scaling and rotation
Translation
x′ = x + tx, y′ = y + ty
Scaling about the origin
x′ = sx·x, y′ = sy·y
Rotation about the origin by θ (anticlockwise)
x′ = x cos θ − y sin θ, y′ = x sin θ + y cos θ
| Transformation | Row 1 | Row 2 | Row 3 |
|---|---|---|---|
| Translation T | 1 0 tx | 0 1 ty | 0 0 1 |
| Scaling S | sx 0 0 | 0 sy 0 | 0 0 1 |
| Rotation R | cos θ −sin θ 0 | sin θ cos θ 0 | 0 0 1 |
Example
Rotate point (4, 2) by 90° about the origin: x′ = 4·0 − 2·1 = −2, y′ = 4·1 + 2·0 = 4 → (−2, 4).
Topic 3
Reflection and shearing
- Reflection about the x-axis
- (x, y) → (x, −y)
- Reflection about the y-axis
- (x, y) → (−x, y)
- Reflection about the origin
- (x, y) → (−x, −y)
- Reflection about the line y = x
- (x, y) → (y, x)
- X-shear
- x′ = x + shx·y, y′ = y
- Y-shear
- x′ = x, y′ = y + shy·x
Topic 4
Composite transformations
- 1Translate the point to the origin: T(−xr, −yr)
- 2Rotate by θ: R(θ)
- 3Translate back: T(xr, yr)
- 4Composite matrix M = T(xr, yr) · R(θ) · T(−xr, −yr)
Example
Scale the square (2,2), (4,2), (4,4), (2,4) by 2 about its corner (2, 2): translate by (−2, −2), scale by 2, translate back → (2,2), (6,2), (6,6), (2,6).
- Matrix multiplication is not commutative, so the order of transformations matters.
Topic 5
2D viewing transformation
- Window: the region of the world (in world coordinates) chosen for display. Viewport: the area of the screen (device coordinates) where it is shown.
x-scale
sx = (xvmax − xvmin) ÷ (xwmax − xwmin)
y-scale
sy = (yvmax − yvmin) ÷ (ywmax − ywmin)
Mapping
xv = xvmin + (xw − xwmin)·sx; yv = yvmin + (yw − ywmin)·sy
- 1Model coordinates
- 2World coordinates
- 3Clip to the window
- 4Normalised device coordinates
- 5Map to the viewport (device coordinates)
Topic 6
Line clipping: Cohen–Sutherland
- Each endpoint gets a 4-bit region code — bit 1 left, bit 2 right, bit 3 below, bit 4 above the window.
- 1Assign region codes to both endpoints
- 2Both codes 0000
Line fully inside — accept
- 3Logical AND of codes non-zero
Fully outside — reject
- 4Otherwise
Find the intersection with a window edge for an outside endpoint
- 5Replace that endpoint and repeat
With a vertical edge x = xb
y = y1 + m (xb − x1)
With a horizontal edge y = yb
x = x1 + (yb − y1) ÷ m
Example
Window (0,0)–(10,10); line (−5, 5) to (5, 5): codes 0001 and 0000; intersect x = 0 → (0, 5); clipped line (0,5)–(5,5).
Topic 7
Line clipping: Liang–Barsky
- Uses the parametric line x = x1 + t·Δx, y = y1 + t·Δy, 0 ≤ t ≤ 1, and computes entry and exit values of t directly — fewer intersection calculations than Cohen–Sutherland.
p and q values
p1 = −Δx, q1 = x1 − xwmin; p2 = Δx, q2 = xwmax − x1; p3 = −Δy, q3 = y1 − ywmin; p4 = Δy, q4 = ywmax − y1
Rule
If pk = 0 and qk < 0 the line is outside; for pk < 0, t1 = max(0, qk ÷ pk); for pk > 0, t2 = min(1, qk ÷ pk)
Result
If t1 > t2 reject; else clipped endpoints at t1 and t2
Topic 8
Polygon clipping: Sutherland–Hodgman
- 1Clip the polygon against one window edge at a time — left, right, bottom, top
- 2For each edge from vertex S to vertex P apply four cases
- 3Output of one stage is input to the next
- Both inside
- Output P
- Inside to outside
- Output the intersection I
- Outside to outside
- Output nothing
- Outside to inside
- Output I and P
- Limitation: concave polygons may produce extra connecting edges; the Weiler–Atherton algorithm handles them correctly.
Topic 9
Text clipping
All-or-none string
Keep the whole string only if completely inside
Fastest, least accurate
All-or-none character
Keep only characters completely inside
Moderate
Individual character components
Clip parts of characters like lines (stroke fonts) or pixels (bitmap fonts)
Most accurate, slowest
Key terms
- Homogeneous coordinates
- Representation (x, y, 1) allowing matrix translation
- Composite transformation
- Single matrix combining several transformations
- Viewport
- Screen area where the window contents are displayed
- Region code
- 4-bit code locating a point relative to the window
- Clipping
- Removing parts of a picture outside the window
Quick revision
- Homogeneous coordinates and 3 × 3 matrices.
- Translation, scaling, rotation, reflection, shear; fixed-point rotation and scaling; order matters.
- Window-to-viewport mapping.
- Cohen–Sutherland region codes; Liang–Barsky parametric clipping.
- Sutherland–Hodgman four cases; Weiler–Atherton; text clipping strategies.
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.Why are homogeneous coordinates used?
- Q2.Write the rotation matrix for angle θ.
- Q3.Reflect (3, 5) about the line y = x.
- Q4.Distinguish a window and a viewport.
- Q5.What do region codes 0000 for both endpoints indicate?
- Q6.Name the four cases in Sutherland–Hodgman clipping.
Long-answer questions
- Q1.Explain 2D transformations with matrices.
- Q2.Derive the composite matrix for rotation about a fixed point.
- Q3.Explain the Cohen–Sutherland and Liang–Barsky line clipping algorithms.
- Q4.Explain polygon and text clipping.
Stuck on this unit?
Message SBS on WhatsApp for help with Computer Graphics, or to ask about studying B.Sc IT at Synetic.
