Stage 01 · Lesson 09/12

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

  1. Pick θ

    Positive CCW from +x toward +y.

  2. Build R

    Fill cos/sin as in the formula (radians in code).

  3. Multiply

    v′ = R v. Check |v′| equals |v|.

  4. 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

rotation_2d.py · Python
"""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
SymptomLikely causeFix
Point rotates clockwise instead of anticlockwiseUsed [[c, s], [−s, c]] (that is R(−θ))R(θ) = [[c, −s], [s, c]]
Length changes after rotatingTypo in a sign or degrees in cos/sinCheck det(R) = 1 and use radians
R(90°)·(3,4) gives (4, −3)Clockwise convention by mistakeCorrect anticlockwise answer: (−4, 3)
Adding Euler angles gives wrong pose3D rotations don't add like vectorsMultiply rotation matrices instead
NoteChange one thing at a time. Most Stage 1 bugs are units (degrees vs radians, mm vs m), order of multiplication, or a frame that was never named.

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

  1. Pick any vector in the code lab; rotate by 0°, 30°, 90°, 180°.
  2. Confirm |Rv| matches |v| each time.
  3. 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

Loading 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

  1. Build R(θ) for θ = 30°, 90° and 180° by hand.
  2. Rotate (3, 4) by each and check |v| = 5 every time.
  3. Run rotation_2d.py and compare.
  4. Make the pocket card: formula, three properties (det = 1, Rᵀ = R⁻¹, keeps length) and the (3, 4) example.

Stuck? Hints, one at a time

NoteTry the task first. Read one hint, try again, and only then read the next one.
  1. Hint 1: cos30° ≈ 0.866, sin30° = 0.5.
  2. Hint 2: R(30°)·(3, 4) = (0.866·3 − 0.5·4, 0.5·3 + 0.866·4) ≈ (0.598, 4.964).
  3. 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

0-day streak
Daily goal:lessons, quizzes or assignments a day

Mark this lesson complete when you have worked the experiment, knowledge check, and assignment (even roughly).

Watch on Quark Lab · GATE RA + PH

EP01: Rotation Matrices & Coordinate Frames

How does a robot know which way it is pointing? Frames and orientation, the derivation of the 2D rotation matrix (columns = new axes), its properties (RᵀR = I, R⁻¹ = Rᵀ, det R = +1; reflections have det −1), 3D Rx/Ry/Rz, why rotation order matters (fixed vs current axes), a solved GATE-style NAT problem and the common traps.

All Quark Lab episodes →

Stuck somewhere?

Ask a doubt about this lesson

Saved with this lesson's id and your email so we can reply. Privacy · or email contact@aihubstation.in