Geometric Transformations
A geometric
transformation in computer graphics is a change in the position, size,
shape, or orientation of an object or image. Common examples include moving
(translation), turning (rotation), resizing (scaling), and flipping
(reflection). These transformations are done using mathematical formulas and matrices
to change the coordinates of an object in 2D or 3D space. The result can be
seen on a computer screen.
2D Transformations
2D transformations are
applied to objects or images in a flat (2D) plane, like a piece of paper or a
computer screen.
[IMAGE IDEA: 2D Plane
with X and Y axes]
text
Copy
Download
Y-axis (vertical)
↑
│
│
│
│
│
←──────────────┼──────────────→ X-axis (horizontal)
│
│
│
│
↓
Types of 2D Transformations
1. Translation
(Moving)
Translation moves an
object from one position to another without changing its shape, size, or
orientation. It just changes the location.
[IMAGE IDEA:
Translation - Object moving from one point to another]
text
Copy
Download
BEFORE TRANSLATION AFTER TRANSLATION
Y Y
↑ ↑
│ ┌───┐ │ ┌───┐
│ │ │ │ │ │
│ │ │ │ │ │
│ └───┘ │ └───┘
│ ↑ │ ↑
│ at (2,3) │ at (6,5)
│
│
└──────→ X └──────→ X
Translation by (dx=4, dy=2)
2. Rotation (Turning)
Rotation changes the
orientation of an object around a fixed point (called the origin or pivot
point).
[IMAGE IDEA: Rotation
- Object turning around a point]
text
Copy
Download
BEFORE ROTATION AFTER ROTATION (45°)
Y
Y
↑ ↑
│ ┌───┐ │ /───\
│ │ │ │ │ │
│ │ │ │ │ │
│ └───┘ │ \───/
│ ↑ │ ↑
│ at origin │ rotated
│
│
└──────→ X └──────→ X
Rotation angle = θ (theta)
3. Scaling (Resizing)
Scaling changes the
size of an object. It can be:
·
Uniform
(Isotropic) Scaling – Same scaling
in all directions (makes object bigger or smaller but same shape)
·
Non-Uniform
(Anisotropic) Scaling – Different
scaling in X and Y directions (stretches or squashes)
[IMAGE IDEA: Scaling -
Object getting bigger]
text
Copy
Download
BEFORE SCALING AFTER SCALING (2x)
Y Y
↑ ↑
│ ┌───┐ │ ┌───────┐
│ │ │ │ │ │
│ │ │ │ │ │
│ └───┘ │ └───────┘
│ ↑ │ ↑
│ normal size │
larger size
│
│
└──────→ X └──────→ X
Scale factor = 2 in both X and Y
4. Shear (Slanting)
Shear transformation
changes the shape of an object by moving its sides. It creates a slanted or
skewed effect.
[IMAGE IDEA: Shear -
Square becoming parallelogram]
text
Copy
Download
BEFORE SHEAR AFTER SHEAR
Y Y
↑ ↑
│ ┌───┐ │ ┌────┐
│ │ │ │ /
/
│ │ │ │ / /
│ └───┘ │ └────┘
│ ↑ │ ↑
│ square │ parallelogram
│ │
└──────→ X └──────→ X
(Top moves right, bottom moves left)
5. Reflection
(Flipping)
Reflection creates a
mirror image of an object across an axis (X-axis, Y-axis, or a line).
[IMAGE IDEA: Reflection
- Flipping across axes]
text
Copy
Download
REFLECTION ACROSS Y-AXIS
BEFORE AFTER
Y Y
↑ ↑
│ ┌───┐ │ ┌───┐
│ │ │ │ │ │
│ │ │ │ │ │
│ └───┘ │ └───┘
│ ↑ │ ↑
│ (2,3) │ (-2,3)
│ │
└──────→ X └──────→ X
│
│
│ (flipped across
Y-axis) │
│ x becomes -x │
Homogeneous Coordinates and Matrix Representation of 2D
Transformations
What are Homogeneous Coordinates?
Homogeneous
coordinates are a way to
represent 2D points and vectors in 3D space.
·
A normal 2D point is
written as (x, y)
·
In homogeneous
coordinates, it is written as (x, y, w) where w ≠ 0
·
Usually we use w
= 1 for simplicity
[IMAGE IDEA:
Homogeneous Coordinates Concept]
text
Copy
Download
2D Space Homogeneous Space (3D)
Y Z
↑ ↑
│ ● (x,y) │
│
│
│
│ ● (x,y,w)
│
│
└──────→ X └──────→ X
│
↓ Y
Why Use Homogeneous Coordinates?
1. Translations can be done using matrix
multiplication (not addition)
2. Multiple transformations can be combined into a single matrix
3. More efficient for complex operations
Matrix Representation (3×3 Matrices)
All 2D transformation
matrices in homogeneous coordinates are 3×3 matrices, with the last
row always [0, 0, 1].
2D Translation Matrix
[IMAGE IDEA:
Translation Matrix Visualization]
text
Copy
Download
Translation by (dx, dy)
┌─────────┐
│ 1 0 dx │
│ 0 1 dy │
│ 0 0 1 │
└─────────┘
Visual representation:
Y
↑
│ ● (x,y)
│ \
│ \ (dx, dy)
│ \
│ ● (x',y')
│
└──────→ X
Formula:
text
Copy
Download
[ x' ] [ 1
0 dx ] [ x ]
[ y' ] = [ 0 1 dy ]
[ y ]
[ 1 ] [
0 0
1 ] [ 1 ]
Result: x' = x + dx, y' = y + dy
2D Rotation Matrix
[IMAGE IDEA: Rotation
Matrix Visualization]
text
Copy
Download
Rotation by angle θ (theta)
┌─────────────────┐
│ cosθ -sinθ 0 │
│ sinθ cosθ 0 │
│ 0 0 1 │
└─────────────────┘
Visual representation:
Y
↑
│ ● (x',y')
│ /|
│ / | θ = angle
│ / |
│ ●───┼──→ X
│ (x,y)
│
└──────────────────────→
Formula:
text
Copy
Download
[ x' ] [ cosθ
-sinθ 0 ] [ x ]
[ y' ] = [ sinθ cosθ 0
] [ y ]
[ 1 ] [
0 0 1 ] [ 1 ]
Meaning: The object rotates by angle θ (theta)
around the origin.
2D Scaling Matrix
[IMAGE IDEA: Scaling
Matrix Visualization]
text
Copy
Download
Scaling by (sx, sy)
┌─────────┐
│ sx 0 0 │
│ 0 sy 0 │
│ 0 0 1 │
└─────────┘
Visual representation:
Y
↑
│ ● (x',y')
│ │
│ │ sy
│ │
│ ●───→ X
│ (x,y) sx
│
└──────────────────────→
Formula:
text
Copy
Download
[ x' ] [ sx
0 0 ] [ x ]
[ y' ] = [ 0 sy 0
] [ y ]
[ 1 ] [
0 0
1 ] [ 1 ]
Result: x' = x × sx, y' = y × sy
Note: If sx = sy, it's uniform scaling. If sx
≠ sy, it's non-uniform scaling.
2D Shear Matrix
[IMAGE IDEA: Shear
Matrix Visualization]
text
Copy
Download
Shear in X-direction
┌─────────┐
│ 1 shx 0 │
│ 0 1 0 │
│ 0 0 1 │
└─────────┘
Shear in Y-direction
┌─────────┐
│ 1 0 0 │
│ shy 1 0 │
│ 0 0 1 │
└─────────┘
Visual representation (X-shear):
BEFORE AFTER
┌───┐ ┌────┐
│ │ │ /
│ │ │ /
│ │ │ /
└───┘ └/
square becomes slanted parallelogram
X-Shear Formula:
text
Copy
Download
[ x' ] [ 1
shx 0 ] [ x ]
[ y' ] = [ 0 1 0
] [ y ]
[ 1 ] [
0 0
1 ] [ 1 ]
Result: x' = x + (shx × y), y' = y
Y-Shear Formula:
text
Copy
Download
[ x' ] [ 1
0 0 ] [ x ]
[ y' ] = [ shy 1 0 ]
[ y ]
[ 1 ] [
0 0
1 ] [ 1 ]
Result: x' = x, y' = y + (shy × x)
2D Reflection Matrix
[IMAGE IDEA:
Reflection Matrices]
text
Copy
Download
Reflection across X-axis:
┌─────────┐
│ 1 0 0 │
│ 0 -1 0 │
│ 0 0 1 │
└─────────┘
(y
becomes -y)
Reflection across Y-axis:
┌─────────┐
│ -1 0 0 │
│ 0 1 0 │
│ 0 0 1 │
└─────────┘
(x becomes -x)
Visual:
Original
X-axis Y-axis
reflection reflection
┌───┐ ┌───┐ ┌───┐
│ │ │ │ │ │
│ │ │ │ │ │
└───┘ └───┘ └───┘
↑ ↑ ↑
normal
flipped flipped
upside down left-right
Composition of 2D Transformations
Composition means applying multiple transformations
one after another. The order matters!
[IMAGE IDEA:
Composition Order Example]
text
Copy
Download
Example: Rotate first, then translate
Different orders give different results!
ORDER 1: TRANSLATE THEN ROTATE ORDER 2: ROTATE THEN TRANSLATE
Step 1: Translate Step 1: Rotate
┌───┐
→ ┌───┐ ┌───┐ ↻ ◇
│ │ │ │ │ │ (rotated)
└───┘
└───┘ └───┘
at (0,0) at (2,0) at (0,0)
Step 2: Rotate Step 2: Translate
┌───┐
┌───┐ ◇ → ◇
│ │ ↻ │ │ (rotated) at (2,0)
└───┘
└───┘
RESULT: Shape moved then rotated RESULT: Shape rotated then moved
(different final position!) (different final position!)
Matrix Formula for Composition
If we have:
·
T = Translation matrix
·
R = Rotation matrix
·
S = Scaling matrix
Then the combined
transformation matrix is:
A = S × R × T
Important: The matrix on the right is applied
FIRST!
text
Copy
Download
A = S × R × T
Step 1: Apply T (translation)
Step 2: Apply R (rotation)
Step 3: Apply S (scaling)
[IMAGE IDEA:
Composition as Matrix Multiplication]
text
Copy
Download
Combined Matrix M = S × R × T
[a b c]
[sx 0 0] [cosθ -sinθ 0] [1 0 dx]
[d e f] = [0 sy 0] × [sinθ cosθ 0] × [0 1 dy]
[0 0 1]
[0 0 1] [0 0
1] [0 0 1]
To apply to a point P:
P' = M × P
Window-to-Viewport Transformations
Window-to-Viewport
transformation maps a 2D
world-coordinate system (the "window") to a 2D screen-coordinate
system (the "viewport").
[IMAGE IDEA: Window to
Viewport Mapping]
text
Copy
Download
WORLD COORDINATES (Window) SCREEN COORDINATES (Viewport)
Y Y'
↑ ↑
│ ┌─────────────────┐ │ ┌─────────────┐
│ │ │ │ │ │
│ │ ┌───────┐ │ │ │ ┌───────┐ │
│ │ │ Object│ │ ======> │ │ │ Object│ │
│ │ └───────┘ │ │ │ └───────┘ │
│ │ │ │ │ │
│ └─────────────────┘ │ └─────────────┘
│ │
└──────────────→ X └──────────→
X'
(xmin, ymin) to (xmax, ymax) (xmin', ymin') to (xmax', ymax')
Matrix Representation
text
Copy
Download
[ x' ] [ sx
0 tx ] [ x ]
[ y' ] = [ 0 sy
ty ] [ y ]
[ 1 ] [
0 0
1 ] [ 1 ]
Where:
·
(x,
y) = original
window coordinates
·
(x',
y') = transformed
viewport coordinates
·
(sx,
sy) = scaling
factors
·
(tx,
ty) = translation
factors
Scaling and Translation Formulas
text
Copy
Download
sx = (xmax' - xmin') /
(xmax - xmin)
sy = (ymax' - ymin') /
(ymax - ymin)
tx = xmin' - (sx ×
xmin)
ty = ymin' - (sy ×
ymin)
[IMAGE IDEA: Aspect
Ratio Preservation]
text
Copy
Download
Window (square) Viewport (rectangle)
┌─────┐ ┌───────┐
│ │ │ │
│ □ │ ======> │ □ │
│ │ │ │
└─────┘ └───────┘
Square stays square Square stays square
(aspect ratio preserved) (no distortion)
Important: This transformation preserves the aspect
ratio (relative proportions) of objects so they don't look distorted.
Introduction to 3D Transformations Matrix
3D transformations are
used to manipulate objects in a three-dimensional space (X, Y,
and Z axes).
[IMAGE IDEA: 3D
Coordinate System]
text
Copy
Download
Z (depth)
↑
│
│
│
│
X (width) ←─────┼─────→ Y (height)
/
/
/
↓
(origin)
3D Translation Matrix (4×4)
[IMAGE IDEA: 3D
Translation]
text
Copy
Download
Translation by (tx, ty, tz)
┌─────────────────┐
│ 1 0 0 tx
│
│ 0 1 0 ty
│
│ 0 0 1 tz
│
│ 0 0 0
1 │
└─────────────────┘
Formula:
[ x' ]
[ 1 0 0 tx ]
[ x ]
[ y' ]
[ 0 1 0 ty ]
[ y ]
[ z' ] = [ 0 0
1 tz ] [ z ]
[ 1
] [ 0 0
0 1 ] [ 1 ]
3D Rotation Matrix (4×4)
[IMAGE IDEA: 3D
Rotation around Z-axis]
text
Copy
Download
Rotation around Z-axis by angle θ
┌─────────────────┐
│ cosθ -sinθ 0 0 │
│ sinθ cosθ 0 0 │
│ 0 0 1 0 │
│ 0 0 0 1
│
└─────────────────┘
[IMAGE IDEA: 3D
Rotation around X-axis]
text
Copy
Download
Rotation around X-axis by angle θ
┌─────────────────┐
│ 1
0 0 0 │
│ 0 cosθ
-sinθ 0 │
│ 0
sinθ cosθ 0 │
│ 0
0 0 1 │
└─────────────────┘
[IMAGE IDEA: 3D
Rotation around Y-axis]
text
Copy
Download
Rotation around Y-axis by angle θ
┌─────────────────┐
│ cosθ
0 sinθ 0 │
│ 0
1 0 0 │
│ -sinθ
0 cosθ 0 │
│ 0
0 0 1 │
└─────────────────┘
3D Scaling Matrix (4×4)
[IMAGE IDEA: 3D
Scaling]
text
Copy
Download
Scaling by (sx, sy, sz)
┌─────────────┐
│ sx
0 0 0 │
│ 0
sy 0 0 │
│ 0
0 sz 0 │
│ 0
0 0 1 │
└─────────────┘
Formula:
[ x' ]
[ sx 0 0 0
] [ x ]
[ y' ]
[ 0 sy 0 0 ]
[ y ]
[ z' ] = [ 0 0
sz 0 ] [ z ]
[ 1
] [ 0 0
0 1 ] [ 1 ]
Composition of 3D Transformations
Just like 2D, 3D
transformations can be combined by multiplying matrices in order.
Combined Matrix = S ×
R × T
Where T = Translation,
R = Rotation, S = Scaling
[IMAGE IDEA: 3D Object
Transformation]
text
Copy
Download
Original
After Translation After
Rotation After Scaling
Cube (moved) (turned) (resized)
□ □ ◇ █
/
\ / \ / \
/ \
□
□ → □
□ → ◇ ◇ →
█ █
\
/ \ / \ /
\ /
□ □ ◇ █
Summary Table of 2D Transformation Matrices (3×3)
|
Transformation |
Matrix |
Effect |
|
Translation |
[1 0 dx; 0 1 dy; 0 0 1] |
Move object |
|
Rotation |
[cosθ -sinθ 0; sinθ cosθ 0; 0 0 1] |
Turn object |
|
Scaling |
[sx 0 0; 0 sy 0; 0 0 1] |
Resize object |
|
X-Shear |
[1 shx 0; 0 1 0; 0 0 1] |
Slant horizontally |
|
Y-Shear |
[1 0 0; shy 1 0; 0 0 1] |
Slant vertically |
|
X-Reflection |
[1 0 0; 0 -1 0; 0 0 1] |
Flip vertically |
|
Y-Reflection |
[-1 0 0; 0 1 0; 0 0 1] |
Flip horizontally |
Summary Table of 3D Transformation Matrices (4×4)
|
Transformation |
Matrix |
Effect |
|
Translation |
[1 0 0 tx; 0 1 0 ty; 0 0 1 tz; 0 0
0 1] |
Move in 3D |
|
Rotation (Z) |
[cosθ -sinθ 0 0; sinθ cosθ 0 0; 0
0 1 0; 0 0 0 1] |
Turn around Z |
|
Rotation (X) |
[1 0 0 0; 0 cosθ -sinθ 0; 0 sinθ
cosθ 0; 0 0 0 1] |
Turn around X |
|
Rotation (Y) |
[cosθ 0 sinθ 0; 0 1 0 0; -sinθ 0
cosθ 0; 0 0 0 1] |
Turn around Y |
|
Scaling |
[sx 0 0 0; 0 sy 0 0; 0 0 sz 0; 0 0
0 1] |
Resize in 3D |