Lite / Intelligent Robotic Systems / Week 13
The rotation matrix, built from scratch
Every robot, game engine and spacecraft turns things with the same four entries: cos, −sin, sin, cos. Where does that minus sign come from?
Why should I care?
Rotations are the most important matrices in robotics. Every joint, every turn of a vehicle and every camera orientation is a rotation. Deriving R(θ) yourself, once, means you'll never have to memorise where the minus sign goes: you can rebuild it in ten seconds from a sketch.
- Derive the 2D rotation matrix from where it sends (1, 0) and (0, 1).
- Rotate a point by a given angle about the origin.
- Show that a rotation keeps lengths and has determinant 1.
Predict
Rotate (1, 0) by 90° anticlockwise. Where does it go?
- (0, 1)
- (0, −1)
- (−1, 0)
- (1, 1)
Guess first, then reveal
(0, 1): a quarter turn anticlockwise takes 'east' to 'north'. And (0, 1) goes to (−1, 0). Those two answers are the columns of R(90°) = [0 −1; 1 0].
Discover
Choose Rotate. Set θ = 90°, then 30°, then −45°. Each time, read where the orange (1, 0) arrow lands and check it is (cos θ, sin θ). Where does the green (0, 1) arrow land? Check |P| = |P′| and det = 1 every time.
What the interactive shows (text version)
With the Rotate preset the grid turns rigidly by θ. At 90° the orange arrow (image of (1, 0)) points straight up to (0, 1) and the green arrow (image of (0, 1)) points left to (−1, 0). The readout shows |P| equal to |P′| and determinant 1 for every angle.
Watch (optional)
Watch for: Watch for the trick: follow just the two basis arrows, then read off the matrix. Pause when the rotation example appears and predict its entries.
Shows a matrix as a description of where the basis vectors land, so you can read a transformation straight off its columns.
“Linear transformations and matrices | Chapter 3, Essence of linear algebra” by 3Blue1Brown (opens YouTube; streaming video uses a lot of data)
The video is optional. Everything you need is in this lesson's text.
Understand
Using R(θ)
To rotate a point about the origin by θ (anticlockwise positive): x′ = x cos θ − y sin θ, y′ = x sin θ + y cos θ. For a clockwise rotation, use a negative θ: cos stays the same, sin changes sign. To rotate about some other pivot, shift the pivot to the origin, rotate, then shift back.
What makes it a rotation
Its columns are unit length and perpendicular to each other, so lengths and angles are kept (it is 'orthogonal'), and det = 1, so it doesn't mirror. A matrix with orthonormal columns but det = −1 is a reflection, not a rotation.
Same matrix, two stories
R(θ)·p can mean 'turn the point p by θ' or 'p is given in a frame turned by θ; here it is in the outer frame'. Both are the same calculation. Robotics uses the second story constantly: a link frame rotated by θ1 turns the link's own coordinates into the base frame's.
Explain it another way
Intuitive
Stick a drawing pin through the origin of a sheet of tracing paper and turn the sheet. Everything moves together, nothing stretches. The rotation matrix is the recipe for where each mark ends up.
Technical
R(θ) ∈ SO(2), the group of 2×2 orthogonal matrices with determinant 1. Rᵀ = R⁻¹ = R(−θ), and R(α)R(β) = R(α + β): planar rotations commute.
Mathematical
Rotate (2, −5) by 135°: cos = −0.7071, sin = 0.7071. x′ = 2(−0.7071) − (−5)(0.7071) = −1.414 + 3.536 = 2.121. y′ = 2(0.7071) + (−5)(−0.7071) = 1.414 + 3.536 = 4.950.
Applied
A camera on a robot's wrist sees a part at (0.1, 0) m in its own frame. With the wrist turned 30°, the part is at R(30°)·(0.1, 0) = (0.0866, 0.05) m relative to the wrist in the arm's frame.
Derivation: Deriving R(θ)
A matrix is fixed by where it sends (1, 0) and (0, 1): those images are its columns.
Rotating (1, 0) by θ lands on the unit circle at angle θ: (cos θ, sin θ). That's column 1.
(0, 1) starts at 90°, so after rotating it is at θ + 90°: (cos(θ + 90°), sin(θ + 90°)) = (−sin θ, cos θ). That's column 2, and the source of the minus sign.
So R(θ) = [cos θ −sin θ; sin θ cos θ], and R(θ)·(x, y) = (x cos θ − y sin θ, x sin θ + y cos θ).
Check lengths: (x cos θ − y sin θ)² + (x sin θ + y cos θ)² = x²(cos² + sin²) + y²(sin² + cos²) + (cross terms that cancel) = x² + y². Lengths are kept.
Check area: det R = cos θ · cos θ − (−sin θ) · sin θ = cos²θ + sin²θ = 1. No stretching, no flipping.
Worked example 1
Rotate (3, 4) by 90° clockwise.
θ = −90°: cos = 0, sin = −1. x′ = 3×0 − 4×(−1) = 4, y′ = 3×(−1) + 4×0 = −3. (4, −3): length still 5.
Common mix-ups
The minus sign in R(θ) goes on the bottom-left entry.
✓ It goes top-right: column 2 is where (0, 1) lands, (−sin θ, cos θ). Rebuild it from a sketch if unsure.A rotation matrix rotates about any point you like.
✓ It rotates about the origin. For another pivot, translate, rotate, translate back (or use a homogeneous transform).
Practice
Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.
Apply it
Write a Python function rotate(x, y, deg) using the formula. Test that rotating by 30° twelve times returns (very nearly) the starting point, and explain the tiny difference you see.
Reflect
You derived the matrix from two arrows. What would you need to know to derive a 3D rotation the same way?
Write your answer on paper or in your own notes. Lite never stores what you write.
Go further
- Rotation matrix (Wikipedia)
2D and 3D rotation matrices and their properties.