Geometric Interpretation of Linear Transformations
A 2×2 matrix is easiest to understand by watching what it does to a shape: the unit square becomes a parallelogram spanned by the two columns, and every other figure is carried along. This lesson draws the basic transformations (rotation, scaling, reflection, shear, projection) in 2D and 3D, the same matrices that move every object in a game.
Watch the unit square
The unit square has corners , , and . A linear map with matrix sends them to , , and : the square becomes the parallelogram spanned by the columns of . Straight lines stay straight, parallel lines stay parallel, the origin stays fixed, and equally spaced points stay equally spaced. Those four properties characterise linear maps geometrically.
The basic 2D transformations
| Type | Matrix | What it does |
|---|---|---|
| Rotation by | turns about , keeps lengths and angles | |
| Uniform scale by | grows () or shrinks () | |
| Non-uniform scale | stretches by and by | |
| Reflection across a line through at angle | mirror image | |
| Horizontal shear | slides each point sideways by | |
| Projection onto the -axis | flattens to a line (not invertible) |
Here they are applied to a small "house" shape:
import numpy as np
import matplotlib.pyplot as plt
house = np.array([[0, 0], [2, 0], [2, 1.5], [1, 2.5], [0, 1.5], [0, 0]]).T # 2 x 6, columns = points
t = np.radians(40)
maps = {
"rotate 40°": np.array([[np.cos(t), -np.sin(t)], [np.sin(t), np.cos(t)]]),
"scale (1.5, 0.5)": np.array([[1.5, 0], [0, 0.5]]),
"reflect in y-axis": np.array([[-1, 0], [0, 1]]),
"shear k = 0.8": np.array([[1, 0.8], [0, 1]]),
}
fig, axes = plt.subplots(1, 4, figsize=(12, 3.2))
for ax, (name, A) in zip(axes, maps.items()):
img = A @ house # transform all points at once
ax.plot(*house, color="lightgray", lw=2)
ax.plot(*img, color="tab:blue", lw=2)
ax.set_title(name); ax.set_aspect("equal"); ax.set_xlim(-3, 4); ax.set_ylim(-1, 4)
ax.axhline(0, lw=0.5, color="k"); ax.axvline(0, lw=0.5, color="k")
for name, A in maps.items():
print(f"{name:18s} columns: {np.round(A[:, 0], 3).tolist()} {np.round(A[:, 1], 3).tolist()}")rotate 40° columns: [0.766, 0.643] [-0.643, 0.766]
scale (1.5, 0.5) columns: [1.5, 0.0] [0.0, 0.5]
reflect in y-axis columns: [-1, 0] [0, 1]
shear k = 0.8 columns: [1.0, 0.0] [0.8, 1.0]
The grey outline is the original, blue the image. Note that the whole shape is transformed with one matrix product, A @ house, applied to all points stored as columns.
Rotations in 3D
In a rotation turns about an axis through . The rotations about the coordinate axes keep one coordinate fixed and act as a 2D rotation on the other two:
( has its signs "swapped" so that every rotation is counter-clockwise when you look down its axis towards the origin in a right-handed system.) Any 3D rotation is a product of these, but the order matters: rotations about different axes do not commute.
import numpy as np
def Rx(deg):
t = np.radians(deg); c, s = np.cos(t), np.sin(t)
return np.array([[1, 0, 0], [0, c, -s], [0, s, c]])
def Rz(deg):
t = np.radians(deg); c, s = np.cos(t), np.sin(t)
return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
v = np.array([1.0, 0.0, 0.0])
print("Rx(90) Rz(90) v:", np.round(Rx(90) @ Rz(90) @ v, 6).tolist())
print("Rz(90) Rx(90) v:", np.round(Rz(90) @ Rx(90) @ v, 6).tolist())
R = Rx(30) @ Rz(70)
print("R^T R == I:", np.allclose(R.T @ R, np.eye(3)), " det R:", round(float(np.linalg.det(R)), 6))Rx(90) Rz(90) v: [0.0, 0.0, 1.0]
Rz(90) Rx(90) v: [0.0, 1.0, 0.0]
R^T R == I: True det R: 1.0
Rotation matrices are orthogonal (, so , which is cheap) and have determinant . Reflections are orthogonal with determinant (Orthogonal Functions and Orthogonal Matrices).
Reading a matrix geometrically
| Clue | Meaning |
|---|---|
| columns orthonormal, | rotation |
| columns orthonormal, | reflection (possibly combined with a rotation) |
| diagonal | scaling along the axes |
| squashes the plane onto a line or point (projection-like) | |
| area scale factor (determinants) | |
| projection |
In software: rotate, scale and shear in games
- 2D games rotate sprites and velocity vectors with the 2×2 rotation matrix (Rotation in 2D); a non-uniform scale squashes a character when it lands; a shear gives italic text or a cheap "wind" sway on grass.
- 3D engines build each object's transform from scale, rotation and translation, in that order ( applied to column vectors), with translation added through homogeneous coordinates (Translate, Rotate, Scale).
- Euler angles describe a rotation as three axis rotations; because the order matters and two axes can line up, they suffer from gimbal lock (Euler Angles and Gimbal Lock). Engines therefore store rotations as quaternions or axis-angle and convert to a matrix only for rendering (Rotations: Matrices vs Quaternions).
- Drift: multiplying many rotation matrices in floating point slowly breaks orthogonality (the object starts to skew); engines re-orthonormalise periodically.
Exercises
Exercise 1: Identify the transformation
Describe geometrically the maps with matrices (a) , (b) , (c) , (d) .
Answer
(a) rotation by 90°, (b) rotation by 180° (point reflection through ), (c) uniform scaling by 2, (d) vertical shear by 0.5.
Solution
(a) , : the rotation matrix with . (b) Every vector is negated: . (c) Both columns are doubled. (d) , fixed: each point moves up by .
Exercise 2: Where does the square go?
Under , find the images of the corners of the unit square. What is the area of the resulting parallelogram?
Answer
Corners , , , ; area 5.
Solution
The corners go to , column 1 , column 2 , and their sum . The area of the parallelogram spanned by and is , the absolute value of .
Exercise 3: Reflection across via the formula
Use the reflection formula with and confirm you get .
Answer
, , giving .
Solution
This swaps and , the mirror in the line .
Exercise 4: Rotate about a vertical axis
In a -up game world, a turret at the origin points along . Using , where does it point after turning by ? Write in NumPy and check.
Answer
It points along : .
Solution
has , , so it maps to .
import numpy as np
def Ry(deg):
t = np.radians(deg); c, s = np.cos(t), np.sin(t)
return np.array([[c, 0, s], [0, 1, 0], [-s, 0, c]])
print(np.round(Ry(90) @ [0, 0, 1], 6).tolist())[1.0, 0.0, 0.0]
Test yourself
What does the matrix do to the plane?
- Rotates it
- A horizontal shear: each point moves sideways by
- Scales by 3
- Reflects it
For a 3D rotation matrix , what is ?
- itself
- It has no inverse
Do rotations about the -axis and the -axis commute?
- Yes, always
- Only in left-handed systems
- Only for angles under 90°
- No, the order changes the result