Three familiar actions
Translation is a slide: add the same offset to every point. Scaling changes size: multiply distances from a chosen center by a factor. Rotation turns points around a chosen center by an angle. If you draw a triangle on a sheet of clear plastic, you can slide, enlarge, or turn the sheet while the triangle keeps its shape. A graphics program performs matching calculations on the triangle’s coordinates.
Take a point at (2, 1). Translate it by (3, 4) and it becomes (5, 5). Scale its original coordinates by 2 about the origin and it becomes (4, 2). If you scale first and then translate, you get (7, 6); if you translate first and then scale about the origin, you get (10, 10). Order matters.
The rotation rule
Rotating a point (x, y) around the origin by an angle θ uses two numbers from trigonometry, cos θ and sin θ:
x′ = x·cos θ − y·sin θ y′ = x·sin θ + y·cos θ
That looks intimidating, so test it with an angle you can picture. For a quarter turn, θ = 90°, cos θ = 0 and sin θ = 1. The rule becomes x′ = −y and y′ = x. The point (2, 1) goes to (−1, 2). Sketch it: a quarter turn really does carry (2, 1) there. On a screen where y points down, that same rotation looks clockwise, which is why Godot’s positive 2D rotation turns things clockwise.
Turning around a point other than the origin
A door swings on its hinge, not around the corner of the screen. To rotate around a pivot point, use a three-step recipe: move the pivot to the origin, rotate, move back.
1. Subtract the pivot: (6, 4) − (4, 4) = (2, 0).
2. Rotate 90°: (2, 0) becomes (0, 2), using x′ = −y and y′ = x.
3. Add the pivot back: (0, 2) + (4, 4) = (4, 6).
The point stayed 2 units from the pivot, as a turning point should.
# Rotate point p around pivot by angle (radians).
func rotate_around(p: Vector2, pivot: Vector2, angle: float) -> Vector2:
return (p - pivot).rotated(angle) + pivot
print(rotate_around(Vector2(6, 4), Vector2(4, 4), PI / 2)) # about (4, 6)Rotate a triangle around a pivot.
Why the order matters in software
Imagine enlarging an icon and then moving it into a toolbar. If you move it first and then scale every coordinate about the screen origin, its position changes as well as its size. Game engines store each object’s translation, rotation, and scale separately and combine them in a fixed order. Objects can also be nested: a sword is attached to a hand, the hand to an arm, the arm to a character. Each one has a local transform relative to its parent. When the character turns, everything attached turns with it.
Rotating around the wrong point. If a sprite spins around its corner instead of its middle, its pivot (in Godot, its origin or offset) is in the wrong place. The math is fine; the pivot is not.
Packing it into a matrix
Programmers often store a transformation as a small grid of numbers called a matrix. The rotation rule above is exactly a 2 × 2 matrix multiplication. The benefit is that several transformations can be combined into one matrix ahead of time, so a computer can transform thousands of points with the same few multiplications. You do not need matrices to begin, but when you meet them, remember: they are slides, turns, and stretches in a compact form.
Geometry calls these moves transformations: translations, dilations, and rotations, and it asks the same question about order when it composes them. Algebra II applies similar rules to graphs: changing y = x² to y = (x − 3)² slides the parabola three units right, and y = 2x² stretches it vertically. A graphics program does the same to every point of a picture.
Where you will see it
- Animation: spinning wheels, swinging doors, orbiting moons.
- Cameras: zooming and panning are scaling and translation of the whole world.
- Interfaces: converting a mouse click from screen space into a rotated object’s local space.
Exercises
Rotate (0, 3) by 90° around the origin using x′ = −y, y′ = x.
(−3, 0).
Scale the point (5, 2) by 3 around the pivot (1, 2).
Subtract the pivot: (4, 0). Scale: (12, 0). Add back: (13, 2).
Translate by (1, 0), then rotate 90° about the origin. Where does (1, 0) end up?
Translate: (2, 0). Rotate: (0, 2). Doing it in the other order gives (1, 1).
