Math for Robotics · Lesson 09
Rotation
Est. 30–40 min
Why
Why rotation is special among matrices
Concept
The big idea: length-preserving orientation change
- Planar rotation by θ: R = [[cosθ, −sinθ], [sinθ, cosθ]] (CCW).
- Properties: Rᵀ R = I, det(R) = 1, |R v| = |v|.
- Columns of R are where the unit +x and +y axes go.
- 3D rotations are 3×3 with the same orthogonality idea — but need more care (Euler angles vs matrices vs quaternions later).
R(θ) = [[ cosθ, −sinθ ], [ sinθ, cosθ ]]
How it works
How it actually works, step by step
Pick θ
Positive CCW from +x toward +y.
Build R
Fill cos/sin as in the formula (radians in code).
Multiply
v′ = R v. Check |v′| equals |v|.
Read columns
First column = image of (1,0); second = image of (0,1).
Visual
Visualise it: 2D rotation matrix in action
Change θ. Basis vectors rotate; lengths stay 1. That is the rotation matrix living on screen.
Interactive · 2D rotation visualizer
R(θ) =
[ 0.819 , -0.574 ]
[ 0.574 , 0.819 ]
R·v = (62.3, 68.0)
Length is preserved under pure rotation (|v| ≈ |R·v|). This 2×2 matrix is the planar cousin of SO(3) rotations used on 6DOF wrists.
Worked example
Worked example: rotate (3,4) by 90°
Code lab
Code lab: prove length preservation
"""Stage 1 L09 — 2D rotation matrix preserves length."""
import math
def R(theta_deg):
th = math.radians(theta_deg)
c, s = math.cos(th), math.sin(th)
return ((c, -s), (s, c))
def apply(M, v):
return (M[0][0]*v[0] + M[0][1]*v[1], M[1][0]*v[0] + M[1][1]*v[1])
v = (3.0, 4.0)
print(f"|v| before = {math.hypot(*v):.3f}")
for deg in [0, 30, 90, 180]:
rv = apply(R(deg), v)
print(f"R({deg:>3}°)·v = ({rv[0]:7.3f}, {rv[1]:7.3f}) |Rv|={math.hypot(*rv):.3f}")Expected output
|v| before = 5.000 R( 0°)·v = ( 3.000, 4.000) |Rv|=5.000 R( 30°)·v = ( 0.598, 4.964) |Rv|=5.000 R( 90°)·v = ( -4.000, 3.000) |Rv|=5.000 R(180°)·v = ( -3.000, -4.000) |Rv|=5.000
Real world
Joint rotations and turntables
- Every revolute joint applies a rotation about its axis
- Turntables and rotary stages in inspection cells
- Yaw of a mobile base in the plane
Mistakes
Common mistakes and confusions
Hardware & safety
Hardware lab and safety notes
A lazy Susan / rotating stool or a phone compass app shows rotation in real life: everything on the turntable keeps its distance from the centre — exactly what R(θ) promises.
- Place a coin 5 cm from the centre of a turntable (or a plate on a marble). Measure (x, y), turn 90°, measure again.
- Check |p| stays 5 cm — rotation preserves length.
- On a servo, the horn tip moves on a circle of fixed radius for the same reason.
Debugging
Debugging: when it doesn’t work
| Symptom | Likely cause | Fix |
|---|---|---|
| Point rotates clockwise instead of anticlockwise | Used [[c, s], [−s, c]] (that is R(−θ)) | R(θ) = [[c, −s], [s, c]] |
| Length changes after rotating | Typo in a sign or degrees in cos/sin | Check det(R) = 1 and use radians |
| R(90°)·(3,4) gives (4, −3) | Clockwise convention by mistake | Correct anticlockwise answer: (−4, 3) |
| Adding Euler angles gives wrong pose | 3D rotations don't add like vectors | Multiply rotation matrices instead |
Think
Think about it
Think
Why is det(R) = +1 for a proper rotation, not −1?
Experiment
Try it in the lab: preserve length
Experiment
Preserve length
You will need
- rotation-2d interactive
- Python lab
Steps
- Pick any vector in the code lab; rotate by 0°, 30°, 90°, 180°.
- Confirm |Rv| matches |v| each time.
- In the interactive, watch unit axes stay length 1.
Interactive · 2D rotation visualizer
R(θ) =
[ 0.819 , -0.574 ]
[ 0.574 , 0.819 ]
R·v = (62.3, 68.0)
Length is preserved under pure rotation (|v| ≈ |R·v|). This 2×2 matrix is the planar cousin of SO(3) rotations used on 6DOF wrists.
All printed |Rv| values should equal the original magnitude.
Knowledge check
Check your understanding
Knowledge check
1. R(θ) for planar CCW uses…
2. Rotation preserves…
3. Rᵀ R equals…
4. R(90°)·(1,0) for CCW equals…
Practice quiz
Mini assignment
Hands-on assignment
Mini assignment
Rotation card
Make a pocket card: R(θ) formula, three properties, and one numerical example with (3,4).
Deliverables
- Card photo or text
Do this, step by step
- Build R(θ) for θ = 30°, 90° and 180° by hand.
- Rotate (3, 4) by each and check |v| = 5 every time.
- Run
rotation_2d.pyand compare. - Make the pocket card: formula, three properties (det = 1, Rᵀ = R⁻¹, keeps length) and the (3, 4) example.
Stuck? Hints, one at a time
- Hint 1: cos30° ≈ 0.866, sin30° = 0.5.
- Hint 2: R(30°)·(3, 4) = (0.866·3 − 0.5·4, 0.5·3 + 0.866·4) ≈ (0.598, 4.964).
- Hint 3: √(0.598² + 4.964²) ≈ 5.000 — length kept.
Challenges (pick by level)
- 🟢 Easy: What is R(360°)? Why?
- 🟡 Medium: Show R(30°)·R(60°) = R(90°) numerically.
- 🟠 Hard: Rotate a square of 4 points by 45° and plot before/after with matplotlib.
Next step
Next, Lesson 10: Homogeneous Transformation packs R and t into one matrix. Related: 3D rotations and joints in Stage 8 — Kinematics & IK.
Sources
Self-attested for now — keep artifacts in your lab notebook.
Complete
Today's goal
0 of 1 done today
Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).