Translations, Reflections and Rotations
A transformation moves every point of a figure by one rule. Translations slide, reflections flip, rotations turn, and dilations resize. These four are the moves behind every sprite, map view and 3D model you have ever seen on a screen, and in code each one is a small formula or a matrix.
Rigid motions
A transformation that keeps all distances the same is a rigid motion (an isometry). Translations, reflections and rotations are rigid, so the image of a figure is congruent to the original (Congruence and Similarity). A dilation by a factor multiplies all distances by , so it gives a similar figure instead. Reflections also reverse orientation: a shape whose corners were listed counter-clockwise comes out clockwise, like a left hand turning into a right hand in a mirror.
The coordinate rules
| Transformation | Rule |
|---|---|
| translation by | |
| reflection in the x-axis | |
| reflection in the y-axis | |
| reflection in the line | |
| reflection in the line | |
| rotation 90° counter-clockwise about the origin | |
| rotation 180° about the origin | |
| rotation 270° (or 90° clockwise) | |
| rotation by about the origin | |
| dilation by from the origin |
Positive angles turn counter-clockwise, the mathematical convention. (Screen coordinates often have y pointing down, which flips the visible direction; see Handedness.)
tri = [(1, 1), (4, 1), (1, 3)]
rules = {
"translate (2, -3)": lambda x, y: (x + 2, y - 3),
"reflect x-axis": lambda x, y: (x, -y),
"reflect y = x": lambda x, y: (y, x),
"rotate 90°": lambda x, y: (-y, x),
"rotate 180°": lambda x, y: (-x, -y),
"dilate ×2": lambda x, y: (2 * x, 2 * y),
}
def signed_area(p):
return sum(p[i][0] * p[(i + 1) % 3][1] - p[(i + 1) % 3][0] * p[i][1] for i in range(3)) / 2
print(f"{'original':18} {tri} signed area {signed_area(tri)}")
for name, f in rules.items():
img = [f(x, y) for x, y in tri]
print(f"{name:18} {img} signed area {signed_area(img)}")original [(1, 1), (4, 1), (1, 3)] signed area 3.0
translate (2, -3) [(3, -2), (6, -2), (3, 0)] signed area 3.0
reflect x-axis [(1, -1), (4, -1), (1, -3)] signed area -3.0
reflect y = x [(1, 1), (1, 4), (3, 1)] signed area -3.0
rotate 90° [(-1, 1), (-1, 4), (-3, 1)] signed area 3.0
rotate 180° [(-1, -1), (-4, -1), (-1, -3)] signed area 3.0
dilate ×2 [(2, 2), (8, 2), (2, 6)] signed area 12.0
The signed area (shoelace, from Polygons) tells the story: rigid motions keep the size 3, reflections flip the sign (orientation reversed), and the dilation by 2 multiplies the area by .
Seeing it
import matplotlib.pyplot as plt
tri = [(1, 1), (4, 1), (1, 3)]
images = {
"original": tri,
"rotate 90°": [(-y, x) for x, y in tri],
"reflect in y = x": [(y, x) for x, y in tri],
"translate (1, -5)": [(x + 1, y - 5) for x, y in tri],
}
plt.figure(figsize=(6, 5))
for name, pts in images.items():
xs, ys = zip(*pts)
plt.fill(xs, ys, alpha=0.35, label=name)
plt.plot(xs[0], ys[0], "ko", markersize=4) # mark the first corner to follow it
plt.plot([-4, 5], [-4, 5], "k--", linewidth=0.8) # the mirror line y = x
plt.axhline(0, color="gray", linewidth=0.5)
plt.axvline(0, color="gray", linewidth=0.5)
plt.axis("equal")
plt.legend(loc="lower left", fontsize=8)
print("drawn:", ", ".join(images))drawn: original, rotate 90°, reflect in y = x, translate (1, -5)
Rotation about another point, and the order of moves
To rotate about a point that is not the origin: translate to the origin, rotate, translate back. Doing several transformations in a row is composition, and its order matters.
Rotations, reflections and dilations about the origin are linear, so each is a matrix. Translations are not linear, so graphics code adds a third coordinate, writing the point as . In these homogeneous coordinates every move is a matrix and composition is matrix multiplication (the rightmost matrix acts first):
import numpy as np
def T(a, b):
return np.array([[1, 0, a], [0, 1, b], [0, 0, 1]], dtype=float)
def R(deg):
c, s = np.cos(np.radians(deg)), np.sin(np.radians(deg))
return np.array([[c, -s, 0], [s, c, 0], [0, 0, 1]])
def apply(M, x, y):
v = M @ np.array([x, y, 1.0])
return (round(float(v[0]), 6) + 0.0, round(float(v[1]), 6) + 0.0)
about_22 = T(2, 2) @ R(90) @ T(-2, -2) # rotate 90° about (2, 2)
print("rotate (4, 2) about (2, 2):", apply(about_22, 4, 2))
print("translate then rotate (1, 0):", apply(R(90) @ T(3, 0), 1, 0))
print("rotate then translate (1, 0):", apply(T(3, 0) @ R(90), 1, 0))
Fx = np.diag([1.0, -1.0, 1.0]) # reflect in the x-axis
Fd = np.array([[0.0, 1, 0], [1, 0, 0], [0, 0, 1]]) # reflect in y = x
print("two reflections = rotation 90°?", np.allclose(Fd @ Fx, R(90)))rotate (4, 2) about (2, 2): (2.0, 4.0)
translate then rotate (1, 0): (0.0, 4.0)
rotate then translate (1, 0): (3.0, 1.0)
two reflections = rotation 90°? True
The last line shows a classic fact: reflecting in two lines that meet at an angle is a rotation by about their crossing point. Here the x-axis and meet at 45°, giving 90°. The + 0.0 in apply turns a printed -0.0 into 0.0.
In software
Game engines store each object's transform as a translation, a rotation and a scale, and build its matrix as : scale first, then rotate, then move into place. Parent-child hierarchies (a wheel on a car) multiply these matrices together. Read on in Rotation in 2D, Homogeneous Coordinates, Translate, Rotate, Scale, Geometric Transformations and Graphics Transforms.
Exercises
Exercise 1: Two reflections of a point
Reflect in the y-axis, and separately in the line .
Answer
and
Solution
Exercise 2: Quarter and half turns
Rotate about the origin by 90° counter-clockwise, and by 180°.
Answer
and
Solution
Exercise 3: Rotating about a point
Rotate by 90° counter-clockwise about the point .
Answer
Solution
Exercise 4: Order matters
Start at . (a) Reflect in the x-axis, then translate by . (b) Translate by , then rotate 90° counter-clockwise about the origin. Compute both by hand and check with code.
Answer
(a) , (b)
Solution
x, y = 0, 2
a = (x, -y); a = (a[0] + 4, a[1])
b = (x + 4, y); b = (-b[1], b[0])
print(a, b)(4, -2) (-2, 4)
Exercise 5: A 30° turn
Rotate by 30° about the origin. Give the exact answer and the decimals.
Answer
Solution
import math
t = math.radians(30)
print(round(2 * math.cos(t), 3), round(2 * math.sin(t), 3))1.732 1.0
Test yourself
What is the image of after a 90° counter-clockwise rotation about the origin?
Which transformation is NOT a rigid motion?
- Reflection
- Translation
- Rotation
- Dilation by 3
Why do graphics programs use matrices with for 2D points?
- So translations can be written as matrix products too
- Because screens have three colours
- To store the z depth
- To make rotations faster