4. Transformations (2D & 3D)
A transformation is a controlled mathematical operation that changes an object’s position, size, orientation, or shape without changing its identity. In computer graphics, objects are stored as points (coordinates). Transformations act directly on these coordinates using matrices, ensuring precision, repeatability, and efficiency.
Does a transformation change the identity of an object?
A: No. It changes properties like position, rotation, or scale, but the object itself (topology) remains the same.
4.1 2D Transformations
In 2D graphics, each point is represented as $(x, y)$. Transformations compute new coordinates $(x', y')$ from old ones.
4.1.1 Translation (Tx, Ty – Addition)
Translation moves an object without rotating or resizing it. Every point shifts by the same amount.
Formula:
$$x' = x + T_x,\quad y' = y + T_y$$
Conceptually: “pick up the object and place it somewhere else.”
Worked Examples: Translation
Translation adds the same displacement vector $(T_x, T_y)$ to every vertex of the object. Shape, size, and orientation remain unchanged.
In translation, do the shape or orientation change?
A: No. Only the position changes.
Example 1: Translation by Vector (3, 2)
Given triangle vertices:
- $A(1, 2)$
- $B(4, 3)$
- $C(6, 1)$
Translation vector: $(T_x, T_y) = (3, 2)$
Translation formula:
$$x' = x + T_x,\quad y' = y + T_y$$
Apply translation:
- $A'(1+3,\;2+2) = (4, 4)$
- $B'(4+3,\;3+2) = (7, 5)$
- $C'(6+3,\;1+2) = (9, 3)$
New coordinates: $A'(4,4),\; B'(7,5),\; C'(9,3)$
Example 2: Translation 100 Units Right and 10 Units Up
Given triangle vertices:
- $A(20, 0)$
- $B(60, 0)$
- $C(40, 100)$
Translation parameters:
- $T_x = +100$ (right)
- $T_y = +10$ (up)
Apply translation:
- $A'(20+100,\;0+10) = (120, 10)$
- $B'(60+100,\;0+10) = (160, 10)$
- $C'(40+100,\;100+10) = (140, 110)$
New coordinates: $A'(120,10),\; B'(160,10),\; C'(140,110)$
Example 3: Translation with Negative and Positive Offsets
Given polygon vertices:
- $P_1(10, 10)$
- $P_2(15, 15)$
- $P_3(20, 10)$
Translation parameters:
- $T_x = -5$ (left)
- $T_y = +5$ (up)
Apply translation:
- $P_1'(10-5,\;10+5) = (5, 15)$
- $P_2'(15-5,\;15+5) = (10, 20)$
- $P_3'(20-5,\;10+5) = (15, 15)$
New coordinates: $P_1'(5,15),\; P_2'(10,20),\; P_3'(15,15)$
4.1.2 Scaling (Sx, Sy – Multiplication)
Scaling changes the size of an object relative to the origin.
Formula:
$$x' = x \cdot S_x,\quad y' = y \cdot S_y$$
- Uniform Scaling: $S_x = S_y$ → shape preserved
- Differential Scaling: $S_x \neq S_y$ → shape distorted
Worked Examples: Scaling
Scaling changes the size of an object by multiplying each coordinate with scaling factors. Unless stated otherwise, scaling is performed about the origin.
What usually happens if $S_x \neq S_y$?
A: The object becomes distorted (change in aspect ratio).
Example 1: Differential Scaling of a Rectangle
Given rectangle vertices:
- $P(2, 2)$
- $Q(4, 2)$
- $R(4, 5)$
- $S(2, 5)$
Scaling factors: $S_x = 2,\; S_y = 3$
Scaling formula (about origin):
$$x' = x \cdot S_x,\quad y' = y \cdot S_y$$
Apply scaling:
- $P'(2\cdot2,\;2\cdot3) = (4, 6)$
- $Q'(4\cdot2,\;2\cdot3) = (8, 6)$
- $R'(4\cdot2,\;5\cdot3) = (8, 15)$
- $S'(2\cdot2,\;5\cdot3) = (4, 15)$
New coordinates: $P'(4,6),\; Q'(8,6),\; R'(8,15),\; S'(4,15)$
Example 2: Uniform Scaling of a Triangle
Given triangle vertices:
- $A(0, 0)$
- $B(1, 1)$
- $C(5, 2)$
Uniform scaling factor: $S = 2$
Scaling formula:
$$x' = x \cdot S,\quad y' = y \cdot S$$
Apply scaling:
- $A'(0\cdot2,\;0\cdot2) = (0, 0)$
- $B'(1\cdot2,\;1\cdot2) = (2, 2)$
- $C'(5\cdot2,\;2\cdot2) = (10, 4)$
New coordinates: $A'(0,0),\; B'(2,2),\; C'(10,4)$
Example 3: Fixed Point (Composite) Scaling
Given square vertices:
- $A(0,0)$
- $B(2,0)$
- $C(2,2)$
- $D(0,2)$
Scaling factors: $S_x = 2,\; S_y = 2$
Fixed point: $(x_f, y_f) = (2, 2)$
Concept: To keep a point fixed during scaling, apply a composite transformation:
- Translate fixed point to origin
- Scale
- Translate back
Fixed-point scaling formula:
$$x' = x_f + (x - x_f)\cdot S_x$$
$$y' = y_f + (y - y_f)\cdot S_y$$
Apply scaling:
- $A'(2 + (0-2)\cdot2,\;2 + (0-2)\cdot2) = (-2, -2)$
- $B'(2 + (2-2)\cdot2,\;2 + (0-2)\cdot2) = (2, -2)$
- $C'(2 + (2-2)\cdot2,\;2 + (2-2)\cdot2) = (2, 2)$
- $D'(2 + (0-2)\cdot2,\;2 + (2-2)\cdot2) = (-2, 2)$
New coordinates: $A'(-2,-2),\; B'(2,-2),\; C'(2,2),\; D'(-2,2)$
4.1.3 Rotation (Angle θ, About Origin)
Rotation spins an object around the origin while preserving distances.
Counter-clockwise rotation:
$$ \begin{aligned} x' &= x\cos\theta - y\sin\theta \\ y' &= x\sin\theta + y\cos\theta \end{aligned} $$
- Counter-clockwise: $\theta > 0$
- Clockwise: $\theta < 0$
Worked Examples: Rotation
Rotation turns points around a reference point (usually the origin) by an angle $\theta$ without changing shape or size. Counter-clockwise rotation is taken as positive.
By convention, is a positive $\theta$ Clockwise or Counter-Clockwise?
A: Counter-Clockwise.
Example 1: $90^\circ$ Counter-Clockwise Rotation About Origin
Given point: $P(5, 2)$
Rotation angle: $\theta = 90^\circ$ (counter-clockwise)
Rotation rule for $90^\circ$ CCW:
$$ (x, y) \rightarrow (-y, x) $$
Apply rotation:
- $P'( -2,\; 5 )$
New coordinates: $( -2, 5 )$
Example 2: $45^\circ$ Rotation of a Triangle About Origin
Given triangle vertices:
- $A(1,1)$
- $B(2,3)$
- $C(3,1)$
Rotation angle: $\theta = 45^\circ$
Rotation formulas:
$$ \begin{aligned} x' &= x\cos\theta - y\sin\theta \\ y' &= x\sin\theta + y\cos\theta \end{aligned} $$
For $45^\circ$:
$$ \cos45^\circ = \sin45^\circ = \frac{\sqrt{2}}{2} $$
Apply rotation:
- $A'(1,1)$ $$ x' = \frac{\sqrt{2}}{2}(1-1)=0,\quad y' = \frac{\sqrt{2}}{2}(1+1)=\sqrt{2} $$ ⇒ $A'(0,\sqrt{2})$
- $B'(2,3)$ $$ x' = \frac{\sqrt{2}}{2}(2-3)= -\frac{\sqrt{2}}{2},\quad y' = \frac{\sqrt{2}}{2}(2+3)= \frac{5\sqrt{2}}{2} $$ ⇒ $B'(-\tfrac{\sqrt{2}}{2},\tfrac{5\sqrt{2}}{2})$
- $C'(3,1)$ $$ x' = \frac{\sqrt{2}}{2}(3-1)= \sqrt{2},\quad y' = \frac{\sqrt{2}}{2}(3+1)= 2\sqrt{2} $$ ⇒ $C'(\sqrt{2},2\sqrt{2})$
New coordinates:
$A'(0,\sqrt{2}),\; B'(-\tfrac{\sqrt{2}}{2},\tfrac{5\sqrt{2}}{2}),\; C'(\sqrt{2},2\sqrt{2})$
Example 3: Rotation About a Pivot Point
Given point: $A(0,0)$
Pivot point: $P(-1,-1)$
Rotation angle: $45^\circ$ (counter-clockwise)
Concept: Rotation about a pivot uses a composite transformation:
- Translate pivot to origin
- Rotate
- Translate back
Step 1: Translate point relative to pivot
$$ (x_t, y_t) = (0+1,\;0+1) = (1,1) $$
Step 2: Rotate by $45^\circ$
$$ x_r = \frac{\sqrt{2}}{2}(1-1)=0,\quad y_r = \frac{\sqrt{2}}{2}(1+1)=\sqrt{2} $$
Step 3: Translate back
$$ x' = 0-1 = -1,\quad y' = \sqrt{2}-1 $$
New coordinates: $(-1,\; \sqrt{2}-1)$
4.1.4 Reflection (Mirroring)
Reflection flips an object across a reference line or axis.
- About X-axis: $(x, -y)$
- About Y-axis: $(-x, y)$
- About Origin: $(-x, -y)$
- About line $y = x$: $(y, x)$
Conceptually: mirror-image inversion.
Worked Examples: Reflection
Reflection produces a mirror image of an object about a specified axis or line. Distances are preserved, but orientation is reversed.
When reflecting about the **Y-axis**, which coordinate changes sign?
A: The X-coordinate (becomes $-x$).
Example 1: Reflection About the Y-axis
Given point: $(4, 5)$
Reflection rule about Y-axis:
$$ (x, y) \rightarrow (-x, y) $$
Apply reflection:
- $(4, 5) \rightarrow (-4, 5)$
Reflected point: $(-4, 5)$
Example 2: Reflection of a Polygon About the Line $y = 2$
Given polygon vertices:
- $A(-1, 0)$
- $B(0, -2)$
- $C(1, 0)$
- $D(0, 2)$
Concept: Reflection about a horizontal line $y = c$ keeps $x$ same and mirrors $y$ as:
$$ y' = 2c - y $$
Here: $c = 2 \Rightarrow y' = 4 - y$
Apply reflection:
- $A'(-1,\;4-0) = (-1, 4)$
- $B'(0,\;4-(-2)) = (0, 6)$
- $C'(1,\;4-0) = (1, 4)$
- $D'(0,\;4-2) = (0, 2)$
Reflected polygon vertices: $A'(-1,4),\; B'(0,6),\; C'(1,4),\; D'(0,2)$
Example 3: Reflection About the Line $y = x$
Given triangle vertices:
- $A(2, 4)$
- $B(4, 6)$
- $C(2, 6)$
Reflection rule about $y = x$:
$$ (x, y) \rightarrow (y, x) $$
Apply reflection:
- $A(2,4) \rightarrow A'(4,2)$
- $B(4,6) \rightarrow B'(6,4)$
- $C(2,6) \rightarrow C'(6,2)$
Reflected triangle vertices: $A'(4,2),\; B'(6,4),\; C'(6,2)$
4.1.5 Shearing (Slanting)
Shearing shifts one coordinate proportionally to the other, creating a slant.
- X-shear: $x' = x + sh_x \cdot y$
- Y-shear: $y' = y + sh_y \cdot x$
Used to simulate perspective-like distortions in 2D.
Worked Examples: Shearing
Shearing slants an object by shifting one coordinate in proportion to the other. Shape angles change, but parallel lines remain parallel.
In an X-shear, which lines remain parallel to the X-axis?
A: Horizontal lines ($y = \text{const}$) remain horizontal; vertical lines become slanted.
Example 1: Shearing a Square with $Sh_x = 2$ and $Sh_y = 3$
Given square vertices:
- $A(0,0)$
- $B(1,0)$
- $C(1,1)$
- $D(0,1)$
Shear formulas (about origin):
$$ x' = x + Sh_x \cdot y,\quad y' = y + Sh_y \cdot x $$
Apply shearing:
- $A'(0+2\cdot0,\;0+3\cdot0) = (0,0)$
- $B'(1+2\cdot0,\;0+3\cdot1) = (1,3)$
- $C'(1+2\cdot1,\;1+3\cdot1) = (3,4)$
- $D'(0+2\cdot1,\;1+3\cdot0) = (2,1)$
New coordinates: $A'(0,0),\; B'(1,3),\; C'(3,4),\; D'(2,1)$
Example 2: Y-direction Shear About a Reference Line
Given point: $(1,3)$
Shear factor: $Sh_y = 2$
Reference line: $y_{ref} = -1$
Concept: Shearing relative to a reference line requires a composite operation:
- Translate reference line to origin
- Apply shear
- Translate back
Step 1: Translate point
$$ y_t = y - y_{ref} = 3 - (-1) = 4 $$
Step 2: Apply Y-shear
$$ y_s = y_t + Sh_y \cdot x = 4 + 2\cdot1 = 6 $$
Step 3: Translate back
$$ y' = y_s + y_{ref} = 6 - 1 = 5 $$
New coordinates: $(1,5)$
Example 3: X-direction Shear of a Triangle
Given triangle vertices:
- $A(5,5)$
- $B(10,5)$
- $C(7,10)$
Shear factor: $Sh_x = 2$
X-shear formula:
$$ x' = x + Sh_x \cdot y,\quad y' = y $$
Apply shearing:
- $A'(5+2\cdot5,\;5) = (15,5)$
- $B'(10+2\cdot5,\;5) = (20,5)$
- $C'(7+2\cdot10,\;10) = (27,10)$
New coordinates: $A'(15,5),\; B'(20,5),\; C'(27,10)$
4.2 3D Transformations
In 3D graphics, points are represented as $(x, y, z)$. Transformations extend 2D concepts into depth.
4.2.1 3D Translation
$$x' = x + T_x,\; y' = y + T_y,\; z' = z + T_z$$
4.2.2 3D Scaling
$$x' = x \cdot S_x,\; y' = y \cdot S_y,\; z' = z \cdot S_z$$
4.2.3 3D Rotation
Rotation occurs about one axis at a time.
- About X-axis: rotates in Y–Z plane
- About Y-axis: rotates in X–Z plane
- About Z-axis: rotates in X–Y plane
4.2.4 3D Reflection
- About XY-plane: $(x, y, -z)$
- About YZ-plane: $(-x, y, z)$
- About ZX-plane: $(x, -y, z)$
4.2.5 3D Shearing
Shearing in 3D skews objects along planes using proportional offsets in multiple axes.
4.3 Homogeneous Coordinates
Homogeneous coordinates add an extra dimension to unify all transformations.
2D point: $(x, y, 1)$
3D point: $(x, y, z, 1)$
This allows translation to be expressed as matrix multiplication.
Why do we use Homogeneous Coordinates (adding a 1)?
A: To treat Translation as a matrix multiplication (just like Rotation and Scaling) for uniform processing.
4.3.1 Matrix Representation
General form:
$$P' = M \cdot P$$
All transformations become matrix operations.
4.4 Composite Transformations (See Projections and Clipping later)
Multiple transformations applied in sequence form a composite transformation.
flowchart LR
Input[Original Object] --> Step1[1. Translate to Origin]
Step1 --> Step2[2. Rotate/Scale]
Step2 --> Step3[3. Translate Back]
Step3 --> Output[Transformed Object]
4.4.1 Sequence of Transformations
Example: rotate then translate is different from translate then rotate.
Is the order of transformations commutative ($AB = BA$)?
A: No. Changing the order changes the result (e.g., Rotate then Translate $\neq$ Translate then Rotate).
4.4.2 Order of Matrix Multiplication
Matrix multiplication is not commutative:
$$AB \neq BA$$
Rightmost matrix acts first.
4.5 Special Transformations
4.5.1 Rotation about a Pivot Point
Steps:
- Translate pivot to origin
- Rotate
- Translate back
4.5.2 Fixed Point Scaling
Scaling around a fixed point instead of the origin uses the same translate–scale–translate pattern.
4.6 Other Concepts
4.6.1 Affine Transformation
Affine transformations preserve straight lines and parallelism but not angles or lengths.
4.6.2 Inverse Transformation
An inverse transformation reverses the effect of a transformation.
4.6.3 Rigid Body vs. Non-Rigid Body Transformation
- Rigid: distances preserved (translation, rotation)
- Non-rigid: distances change (scaling, shearing)
Which transformations are "Rigid Body"?
A: Translation and Rotation (they preserve shape, size, and angles; only position/orientation changes).
4.6.4 Reflection about an Arbitrary Line ($y = mx + c$)
Achieved by:
- Translate line to pass through origin
- Rotate to align with X-axis
- Reflect about X-axis
- Reverse rotation
- Reverse translation
Transformation Tactics
- Translation: Shifting position by adding vectors \((T_x, T_y)\); does not affect shape/size.
- Scaling: Resizing by multiplying coordinates by \((S_x, S_y)\); if \(S_x \neq S_y\), distortion occurs (differential scaling).
- Rotation: Spinning points around origin/pivot by angle \(\theta\); uses trig functions: \(x' = x\cos\theta - y\sin\theta\).
- Homogeneous Coordinates: Representing 2D points as \((x, y, 1)\) to enable translation as matrix multiplication.
- Composite Rules: Matrix multiplication is non-commutative; apply transformations right-to-left (\(M_{\text{total}} = M_3 \cdot M_2 \cdot M_1\)).
- Reflection: Mirroring across an axis; e.g., X-axis reflection flips Y \((x, -y)\).
- Rigid Body: Preserves distance/shape (Translation, Rotation); Non-Rigid: changes shape (Scaling, Shearing).
