Unit 2: 2D transformations and viewing
Computer Graphics notes · PTU syllabus (PGCA1919)
On this page
Unit summary
Transformations move, resize and orient objects and map them from the world to the screen. This unit covers the window-to-viewport transformation, scaling, translation, rotation, reflection and shear, homogeneous coordinates and composite transformations.
After this unit you can
- Map a window to a viewport
- Apply basic transformations
- Use homogeneous coordinates and matrices
- Build composite transformations
PTU syllabus topics
- Window-to-viewport transformation
- scaling
- translation
- rotation
- reflection
- shear
- homogeneous coordinates
- composite transformations
Translation
[1 0 tx; 0 1 ty; 0 0 1]
Scaling
[sx 0 0; 0 sy 0; 0 0 1]
Rotation
[cosθ −sinθ 0; sinθ cosθ 0; 0 0 1]
Composite
Multiply matrices right to left in order of application
Topic 1
Window-to-viewport 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)
Example
Window (0, 0)–(100, 100) mapped to viewport (200, 100)–(400, 300): sx = sy = 2. Point (30, 50) → (200 + 30 × 2, 100 + 50 × 2) = (260, 200).
Topic 2
Scaling, translation 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 shear
- 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
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 5
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.
Example
Reflect a point about the line y = x + 2: translate by (0, −2), reflect about y = x, translate by (0, 2). Point (1, 1) → (1, −1) → (−1, 1) → (−1, 3).
Key terms
- Window
- Region of the world chosen for display
- Viewport
- Screen region where the window appears
- Homogeneous coordinates
- (x, y, 1) form enabling matrix translation
- Shear
- Transformation slanting a shape
- Composite transformation
- Product of several transformation matrices
Quick revision
- xv = xvmin + (xw − xwmin) × sx; same for y.
- Translation, scaling, rotation equations and matrices.
- Reflections about axes, origin and y = x; x- and y-shear.
- 3 × 3 matrices; order of multiplication matters.
- Fixed-point scaling and rotation; reflection about an arbitrary line.
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.Distinguish a window and a viewport.
- Q2.Write the scaling matrix in homogeneous form.
- Q3.Rotate (2, 0) by 90° about the origin.
- Q4.What is an x-shear?
- Q5.Why are homogeneous coordinates used?
- Q6.Is matrix multiplication of transformations commutative?
Long-answer questions
- Q1.Explain the window-to-viewport transformation with an example.
- Q2.Explain the basic 2D transformations with matrices.
- Q3.Derive the matrix for rotation about an arbitrary point.
- Q4.Explain reflection about an arbitrary line using composite transformations.
Stuck on this unit?
Message SBS on WhatsApp for help with Computer Graphics, or to ask about studying M.Sc IT at Synetic.
