Skip to content
Unit 2 Syllabus Note· Computer Graphics and Animation

Computer Graphics and Animation

Comprehensive exam revision notes for BCA-305N Unit 2 (2D Transformations, Window-to-Viewport Mapping & 3D Projections). Includes Section A (2M), Section B (5M), and Section C (15M) questions, answers, and diagrams.

Computer Graphics and Animation

2D Transformations, Window-to-Viewport Mapping & 3D Projections

Core Definitions & Key Concepts

What is a 2D Transformation and why are Homogeneous Coordinates necessary

A transformation alters an object's position, size, or orientation. In Cartesian coordinates, translation is additive (x' = x + t_x), while rotation and scaling are multiplicative, preventing matrix composition. Homogeneous Coordinates represent a 2D point as [x, y, 1]^T, converting all affine transformations into unified 3 × 3 matrix multiplications.

State the 3 × 3 matrix for 2D Translation by (t_x, t_y)

$T(t_x, t_y) = \begin{bmatrix} 1 & 0 & t_x \\ 0 & 1 & t_y \\ 0 & 0 & 1 \end{bmatrix}$

State the 3 × 3 matrix for 2D Rotation about the origin by angle \theta

$R(\theta) = \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix}$

State the 3 × 3 matrix for 2D Scaling by (s_x, s_y)

$S(s_x, s_y) = \begin{bmatrix} s_x & 0 & 0 \\ 0 & s_y & 0 \\ 0 & 0 & 1 \end{bmatrix}$

What is the difference between Window and Viewport

  • Window: A world-coordinate area selected for viewing (what is to be viewed in world space).
  • Viewport: The display device area where the contents of the window are mapped and displayed (where it is to be viewed on screen).

What is Clipping in Computer Graphics

Clipping is the process of identifying and removing parts of geometric primitives that lie outside a designated clipping window/boundary so that only visible elements are rendered.

The 4-bit region code (TBRL) in the Cohen-Sutherland line clipping algorithm

Every endpoint is assigned a 4-bit Outcode [Top, Bottom, Right, Left]:

  • Bit 1 (Top): Set if y > y_{\max}
  • Bit 2 (Bottom): Set if y < y_{\min}
  • Bit 3 (Right): Set if x > x_{\max}
  • Bit 4 (Left): Set if x < x_{\min}

If outcode is 0000, the point lies inside the clip window.

What are the two trivial acceptance/rejection tests in Cohen-Sutherland clipping

  • Trivial Accept: If Code(P_1) = 0000 AND Code(P_2) = 0000 (both endpoints completely inside).
  • Trivial Reject: If Code(P_1) \ BITWISE-AND \ Code(P_2) \neq 0000 (both endpoints lie entirely on the same external side).

Parallel Projection and Perspective Projection

  • Parallel Projection: Projection lines are parallel; preserves relative proportions and dimensions; objects do not appear smaller with distance; used in engineering blueprints (orthographic).
  • Perspective Projection: Projection lines converge at a Center of Projection (cop); objects farther away appear smaller (foreshortening); models human vision.

What is Vanishing Point in Perspective Projection

The point in a perspective projection where a set of parallel lines that are not parallel to the projection plane appear to converge.

Conceptual & Architectural Analysis

Derive the Composite Transformation Matrix for 2D Rotation about an Arbitrary Point (x_r, y_r)

3-Step Rotation about an Arbitrary Pivot (x_r, y_r):

  1. Translate pivot point to origin: T(-x_r, -y_r)
  2. Rotate by angle \theta about origin: R(\theta)
  3. Translate origin back to pivot point: T(x_r, y_r)

$M = T(x_r, y_r) \cdot R(\theta) \cdot T(-x_r, -y_r)$

$\begin{bmatrix} x' \\ y' \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & 0 & x_r \\ 0 & 1 & y_r \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} \cos\theta & -\sin\theta & 0 \\ \sin\theta & \cos\theta & 0 \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & -x_r \\ 0 & 1 & -y_r \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$

$\mathbf{x' = x_r + (x - x_r)\cos\theta - (y - y_r)\sin\theta} \mathbf{y' = y_r + (x - x_r)\sin\theta + (y - y_r)\cos\theta}$

Derive the Window-to-Viewport Transformation Equations

System Architecture / Concept DiagramHorizontal Scroll Enabled
[ WORLD COORDINATE WINDOW ]                     [ DEVICE VIEWPORT ]
(xw_max, yw_max)                                (xv_max, yv_max)
       +-------------+                                 +-------------+
       |   (xw, yw)  |                                 |   (xv, yv)  |
       |      *      |       ==============>           |      *      |
       +-------------+                                 +-------------+
(xw_min, yw_min)                                (xv_min, yv_min)

To maintain identical relative positioning: $\frac{xv - xv_{\min}}{xv_{\max} - xv_{\min}} = \frac{xw - xw_{\min}}{xw_{\max} - xw_{\min}} \implies xv = xv_{\min} + (xw - xw_{\min}) \cdot S_x \frac{yv - yv_{\min}}{yv_{\max} - yv_{\min}} = \frac{yw - yw_{\min}}{yw_{\max} - yw_{\min}} \implies yv = yv_{\min} + (yw - yw_{\min}) \cdot S_y Where scaling factors are: S_x = \frac{xv_{\max} - xv_{\min}}{xw_{\max} - xw_{\min}} \quad and \quad S_y = \frac{yv_{\max} - yv_{\min}}{yw_{\max} - yw_{\min}}$

The Sutherland-Hodgman Polygon Clipping Algorithm

The algorithm clips an entire polygon against each of the four clipping boundaries sequentially (Left, Right, Bottom, Top):

  • For each edge from vertex v_1 to v_2, evaluate transition:
  1. In to In: Output v_2.
  2. In to Out: Output intersection point I.
  3. Out to Out: Output nothing.
  4. Out to In: Output intersection point I and vertex v_2.

2D Reflection and Shearing Matrices

  • Reflection about X-axis: x' = x, y' = -y \implies \begin{bmatrix} 1 & 0 & 0 \\ 0 & -1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
  • Reflection about Y-axis: x' = -x, y' = y \implies \begin{bmatrix} -1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}
  • X-direction Shear: x' = x + sh_x \cdot y, y' = y \implies \begin{bmatrix} 1 & sh_x & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{bmatrix}

Parallel Projections: Orthographic vs Oblique (Cavalier vs Cabinet)

In Parallel Projections:

  • Orthographic: Projection rays are perpendicular to the projection plane (90^\circ). Includes Isometric, Dimetric, Trimetric.
  • Oblique: Projection rays intersect projection plane at an oblique angle \alpha:
  • Cavalier Projection: Angle is 45^\circ; line segments perpendicular to viewing plane are projected with full length (1:1).
  • Cabinet Projection: Angle is ≈ 63.4^\circ; lines perpendicular to view plane are drawn at half scale (1:2), providing more natural visual depth.

In-Depth Analysis & Implementation

Demonstrate the Complete Cohen-Sutherland Line Clipping Algorithm with Mathematical Intersection Derivations and Worked Numerical Example

Comprehensive Cohen-Sutherland Algorithm Study

System Architecture / Concept DiagramHorizontal Scroll Enabled
                       Top Boundary (ymax)
          1001   |          1000          |   1010
        ---------+------------------------+---------
          0001   |       CLIP WINDOW      |   0010
                 |          0000          |  (xmax)
        ---------+------------------------+---------
          0101   |          0100          |   0110
        (xmin)   | Bottom Boundary (ymin) |

1. Outcode Bit Allocation (4 bits):

  • Bit 1 (Sign of y - y_{\max}): 1 if y > y_{\max}
  • Bit 2 (Sign of y_{\min} - y): 1 if y < y_{\min}
  • Bit 3 (Sign of x - x_{\max}): 1 if x > x_{\max}
  • Bit 4 (Sign of x_{\min} - x): 1 if x < x_{\min}

2. Intersection Calculation with Window Boundary:

For line between (x_1, y_1) and (x_2, y_2) with slope m = \frac{y_2 - y_1}{x_2 - x_1}:

  • If clipping against Vertical Edge (x = x_{\min} or x = x_{\max}):

$x = x_{edge}, \quad y = y_1 + m(x_{edge} - x_1)$

  • If clipping against Horizontal Edge (y = y_{\min} or y = y_{\max}):

$y = y_{edge}, \quad x = x_1 + \frac{y_{edge} - y_1}{m}$

3. Worked Numerical Problem:

  • Clip Window: [x_{\min} = 10, y_{\min} = 10, x_{\max} = 100, y_{\max} = 100]
  • Line Segment: P_1(5, 40) to P_2(120, 80)
  • Step 1: Compute Outcodes:
  • P_1(5, 40): x < 10 \implies Left bit set \implies Code(P_1) = \mathbf{0001}
  • P_2(120, 80): x > 100 \implies Right bit set \implies Code(P_2) = \mathbf{0010}
  • Step 2: Acceptance/Rejection Tests:
  • Both codes are not zero \implies not trivially accepted.
  • Code(P_1) \ \& \ Code(P_2) = 0001 \ \& \ 0010 = 0000 \implies not trivially rejected. Line must be clipped!
  • Step 3: Clip $P_1$ against Left Edge ($x = 10$):
  • Slope m = \frac{80 - 40}{120 - 5} = \frac{40}{115} ≈ 0.3478
  • x' = 10
  • y' = 40 + 0.3478(10 - 5) = 40 + 1.74 = 41.74
  • New P_1'(10, 41.74) has code \mathbf{0000}!
  • Step 4: Clip $P_2$ against Right Edge ($x = 100$):
  • x'' = 100
  • y'' = 80 + 0.3478(100 - 120) = 80 - 6.96 = 73.04
  • New P_2'(100, 73.04) has code \mathbf{0000}!
  • Conclusion: Clipped visible line segment connects $(10, 41.74)$ to $(100, 73.04)$.

Derive the Complete Mathematical Formulation of Perspective Projection onto the z = 0 View Plane with Center of Projection at (0, 0, -d)

Mathematical Derivation of Perspective Transformation

System Architecture / Concept DiagramHorizontal Scroll Enabled
          Y-axis
            ^
            |         P(x, y, z) [3D Object Point]
            |        *
            |       /|
            |  P'  / |
            |  *  /  |
            | /| /   |
  ----------+--|-+---+---------> Z-axis
          C |  | |
  (0,0,-d)  |  | |
            |  View Plane (z = 0)

1. Geometric Triangles Similarity:

By similar triangles formed by line connecting COP (0, 0, -d) to point P(x, y, z) intersecting view plane at P'(x', y', 0): $\frac{x'}{d} = \frac{x}{z + d} \implies x' = \frac{x}{\frac{z}{d} + 1} \frac{y'}{d} = \frac{y}{z + d} \implies y' = \frac{y}{\frac{z}{d} + 1}$

2. Homogeneous Matrix Formulation:

In 4D projective space [x_h, y_h, z_h, w_h]^T: $M_{persp} = \begin{bmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 0 \\ 0 & 0 & \frac{1}{d} & 1 \end{bmatrix} Multiplying with P = [x, y, z, 1]^T: P_h' = M_{persp} \cdot P = \begin{bmatrix} x \\ y \\ 0 \\ \frac{z}{d} + 1 \end{bmatrix} Dividing by the homogeneous coordinate wh = \frac{z}{d} + 1$ (Perspective Division): $$x' = \frac{x}{\frac{z}{d} + 1}, \quad y' = \frac{y}{\frac{z}{d} + 1}, \quad z' = 0$$ As distance $z \to \infty$, $wh increases, causing x' and y'$ to shrink towards 0, perfectly producing the visual phenomenon of perspective foreshortening.

Implement a Python 2D Transformation Pipeline for Scaling, Rotation about Arbitrary Pivot, and Translation

Python
1import numpy as np
2
3def get_translation_matrix(tx, ty):
4 return np.array([
5 [1, 0, tx],
6 [0, 1, ty],
7 [0, 0, 1]
8 ])
9
10def get_rotation_matrix(angle_deg):
11 theta = np.radians(angle_deg)
12 return np.array([
13 [np.cos(theta), -np.sin(theta), 0],
14 [np.sin(theta), np.cos(theta), 0],
15 [0, 0, 1]
16 ])
17
18def get_scaling_matrix(sx, sy):
19 return np.array([
20 [sx, 0, 0],
21 [0, sy, 0],
22 [0, 0, 1]
23 ])
24
25def rotate_around_pivot(points, angle_deg, px, py):
26 # 1. Translate to origin
27 T1 = get_translation_matrix(-px, -py)
28 # 2. Rotate
29 R = get_rotation_matrix(angle_deg)
30 # 3. Translate back
31 T2 = get_translation_matrix(px, py)
32
33 # Composite Matrix M = T2 * R * T1
34 M = T2 @ R @ T1
35
36 # Points format: 3 x N homogeneous matrix
37 homog_points = np.vstack([points.T, np.ones(points.shape[0])])
38 transformed = M @ homog_points
39 return transformed[:2].T
40
41# Triangle vertices
42triangle = np.array([
43 [10.0, 10.0],
44 [30.0, 10.0],
45 [20.0, 40.0]
46])
47
48# Rotate 45 degrees around pivot (20, 20)
49transformed_triangle = rotate_around_pivot(triangle, 45, 20, 20)
50print("Original Triangle:\n", triangle)
51print("\nTransformed Triangle:\n", np.round(transformed_triangle, 2))

Important Exam Points & Quick Revision

Examiners frequently ask: Cohen-Sutherland Line Clipping (with numerical problem), 2D composite rotation about arbitrary pivot derivation, and Perspective vs Parallel projection differences.

Your reading progress
0%

100% left on this page — finishing it closes the gap for 2D Transformations, Window-to-Viewport Mapping & 3D Projections.

Weak topic hint

2D Transformations, Window-to-Viewport Mapping & 3D Projections still counts as a weak topic until you finish this note and answer its questions.

Practise this unit
What Should You Do Next?

Test Your Understanding

Now that you've read through these notes, practice unit MCQs to identify weak points and solidify your learning before exams.