Unit 3 of 4 · B.Sc IT Sem 6

Unit 3: 2D transformations and clipping

Computer Graphics notes · PTU syllabus (BSIT603/BSBC602)

3 min read9 topics10 exam questions
On this page
  1. Unit summary
  2. Cartesian and homogeneous coordinates
  3. Translation, scaling and rotation
  4. Reflection and shearing
  5. Composite transformations
  6. 2D viewing transformation
  7. Line clipping: Cohen–Sutherland
  8. Line clipping: Liang–Barsky
  9. Polygon clipping: Sutherland–Hodgman
  10. Text clipping
  11. Key terms
  12. Quick revision
  13. 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
Key formulas2D transformations (homogeneous)
  • 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

1

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.
2

Topic 2

Translation, scaling and rotation

Key formulasBasic 2D transformations
  • 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 θ

TransformationRow 1Row 2Row 3
Translation T1 0 tx0 1 ty0 0 1
Scaling Ssx 0 00 sy 00 0 1
Rotation Rcos θ −sin θ 0sin θ cos θ 00 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).

3

Topic 3

Reflection and shearing

Key termsReflection 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
4

Topic 4

Composite transformations

ProcessRotation about a fixed point (xr, yr)
  1. 1Translate the point to the origin: T(−xr, −yr)
  2. 2Rotate by θ: R(θ)
  3. 3Translate back: T(xr, yr)
  4. 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.
5

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.
Key formulasWindow-to-viewport mapping
  • 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

Process2D viewing pipeline
  1. 1Model coordinates
  2. 2World coordinates
  3. 3Clip to the window
  4. 4Normalised device coordinates
  5. 5Map to the viewport (device coordinates)
6

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.
ProcessCohen–Sutherland algorithm
  1. 1Assign region codes to both endpoints
  2. 2Both codes 0000

    Line fully inside — accept

  3. 3Logical AND of codes non-zero

    Fully outside — reject

  4. 4Otherwise

    Find the intersection with a window edge for an outside endpoint

  5. 5Replace that endpoint and repeat
Key formulasIntersection points
  • 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).

7

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.
Key formulasLiang–Barsky
  • 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

8

Topic 8

Polygon clipping: Sutherland–Hodgman

ProcessSutherland–Hodgman algorithm
  1. 1Clip the polygon against one window edge at a time — left, right, bottom, top
  2. 2For each edge from vertex S to vertex P apply four cases
  3. 3Output of one stage is input to the next
Key termsFour cases for an edge S → P
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.
9

Topic 9

Text clipping

ComparisonText clipping strategies
Rule
Accuracy

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

  1. Q1.Why are homogeneous coordinates used?
  2. Q2.Write the rotation matrix for angle θ.
  3. Q3.Reflect (3, 5) about the line y = x.
  4. Q4.Distinguish a window and a viewport.
  5. Q5.What do region codes 0000 for both endpoints indicate?
  6. Q6.Name the four cases in Sutherland–Hodgman clipping.

Long-answer questions

  1. Q1.Explain 2D transformations with matrices.
  2. Q2.Derive the composite matrix for rotation about a fixed point.
  3. Q3.Explain the Cohen–Sutherland and Liang–Barsky line clipping algorithms.
  4. 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.

WhatsApp us