Textbooks/Robotics From First Principles/Chapter 4Lite (plain text) version
4Rotations and transforms
Version 1 · Technically checked (automated checks only) · 4 source lessons · 7 practice items
Introduction
A matrix is a machine that moves vectors. The rotation matrix turns any arrow by an angle without stretching it, and a homogeneous transform packs a rotation and a shift into one matrix so that chains of frames become chains of multiplications. Order matters: rotate then shift is not shift then rotate. With transforms you can walk from the world to a gripper and back again.
Explanation
This chapter is built from 4 School lessons. Each part below is the lesson's own explanation; open the lesson for its predict-and-discover activities.
4.1 A matrix is a machine that moves vectors
Four numbers in a box can rotate, stretch, shear or flip an entire plane at once. How do they know where everything goes?
The recipe
For M = [a b; c d] and v = (x, y): M·v = (a·x + b·y, c·x + d·y). Each output component is one row of M dotted with v. A 2×2 matrix takes a 2D vector to another 2D vector.
Columns are where the axes land
M·(1, 0) = (a, c), the first column. M·(0, 1) = (b, d), the second column. Any vector (x, y) = x·(1, 0) + y·(0, 1), so M·v = x·(column 1) + y·(column 2). To design a matrix, decide where (1, 0) and (0, 1) should go and write those as columns. Grid lines stay straight, parallel and evenly spaced: that's what 'linear' means.
The determinant
det M = ad − bc is the factor by which areas change. det = 1: areas kept (rotations). det = 2: doubled. Negative: the plane is flipped over (a mirror image). det = 0: the plane is squashed onto a line or a point, information is lost, and the matrix cannot be undone.
Common mix-ups
- The rows of a matrix tell you where the axes go.
✓ The columns do: column 1 is where (1, 0) lands, column 2 where (0, 1) lands. - A negative determinant means the matrix shrinks things.
✓ The size of det is the area factor; the minus sign means a flip (mirror image).
Open the full lesson: A matrix is a machine that moves vectors →
4.2 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?
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.
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.
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).
Open the full lesson: The rotation matrix, built from scratch →
4.3 Homogeneous transforms: rotate and shift in one matrix
A 2×2 matrix can't move the origin. Add a row of 0, 0, 1 and suddenly it can. What is that extra 1 doing?
The 3×3 transform
T = [cos θ −sin θ tx; sin θ cos θ ty; 0 0 1] describes a frame turned by θ with its origin at (tx, ty) in its parent. Top-left 2×2: the rotation. Right column: where the frame's origin is. Bottom row: always 0, 0, 1. Points go in as (x, y, 1).
Reading T_parent←child
We label transforms by what they convert: T_WA turns coordinates in frame A into coordinates in the world W. So p_W = T_WA · p_A. Its columns even tell a story: column 1 is A's x axis seen in W, column 2 is A's y axis, column 3 is A's origin in W.
Points and directions
Points (positions) carry a 1: they get rotated and shifted. Directions (velocities, forces, axes) carry a 0: they get rotated only, because moving a frame doesn't change which way an arrow points. Keeping that last coordinate right is a common source of bugs in robot code.
Derivation: Why the extra row of 0, 0, 1 works
A rigid move is p′ = R·p + t: rotate, then add a translation. The '+ t' is not a matrix multiplication, so a 2×2 matrix can't do it.
Trick: write points with an extra coordinate fixed at 1: p = (x, y, 1).
Build T = [R t; 0 0 1] = [cos θ −sin θ tx; sin θ cos θ ty; 0 0 1].
Multiply: row 1 gives x cos θ − y sin θ + tx·1, row 2 gives x sin θ + y cos θ + ty·1, row 3 gives 0 + 0 + 1 = 1. That is exactly R·p + t, with the 1 still in place.
The 1 picks up the translation column. (A direction vector, which shouldn't be shifted, is written with a 0 instead, and correctly ignores t.)
Common mix-ups
- You can translate first and rotate after, it makes no difference.
✓ T = [R t] means rotate the local point, then add t. Shifting first would rotate the shift too. - The bottom row 0 0 1 is decoration.
✓ It keeps the final 1 in place so that transforms can be multiplied together and chained.
Open the full lesson: Homogeneous transforms: rotate and shift in one matrix →
4.4 Chains of frames, and the way back
A camera on a wrist on an elbow on a shoulder sees a bolt. To grab it, the robot must know where the bolt is in the room. How many matrices is that?
Chaining: labels like dominoes
T_WB = T_WA · T_AB: the A's in the middle 'cancel'. For a longer chain, T_W←tool = T_W←base · T_base←1 · T_1←2 · T_2←tool. Multiply left to right in the order of the chain; the point goes in on the right. In 2D, the angles of a chain simply add, and the translations combine through the rotations.
Inverting a rigid transform
To go the other way (W → A), use T_AW = T_WA⁻¹. For a rigid transform no general inverse is needed: T⁻¹ = [Rᵀ −Rᵀt; 0 0 1]. Rotate back by −θ, and the new translation is the old one, rotated back and negated. Check: T⁻¹·T = I.
Up and down the tree
To get a camera's measurement into the gripper frame you might go up from camera to world and back down to gripper: T_gripper←camera = T_W←gripper⁻¹ · T_W←camera. Every arrow you traverse backwards needs an inverse. Writing the subscripts carefully is the whole skill.
Common mix-ups
- The inverse of a transform just negates the angle and the translation.
✓ The angle negates, but the new translation is −Rᵀt: the old shift, rotated back, then negated. - Transforms can be multiplied in any order as long as all of them are included.
✓ Only the order that chains the frame labels gives the right answer.
Worked examples
A matrix is a machine that moves vectors: example 1
Find [2 −1; 1 3]·(4, −2).
Solution
Row 1: 2×4 + (−1)×(−2) = 8 + 2 = 10. Row 2: 1×4 + 3×(−2) = 4 − 6 = −2. Answer (10, −2).
The rotation matrix, built from scratch: example 1
Rotate (3, 4) by 90° clockwise.
Solution
θ = −90°: cos = 0, sin = −1. x′ = 3×0 − 4×(−1) = 4, y′ = 3×(−1) + 4×0 = −3. (4, −3): length still 5.
Homogeneous transforms: rotate and shift in one matrix: example 1
Write T for a frame rotated 30° with origin (1, 2), and find the point (2, 0) in the parent.
Solution
T = [0.866 −0.5 1; 0.5 0.866 2; 0 0 1]. T·(2, 0, 1) = (1.732 + 1, 1 + 2, 1) = (2.732, 3).
Chains of frames, and the way back: example 1
T_WA has θ = 90°, t = (2, 1). Find T_AW and use it to express the world point (2, 3) in A.
Solution
Rᵀ = R(−90°). −Rᵀt: Rᵀ(2, 1) = (1, −2), negated (−1, 2). So T_AW = (−90°, (−1, 2)). Point: R(−90°)(2, 3) + (−1, 2) = (3, −2) + (−1, 2) = (2, 0). Check: T_WA·(2, 0) = (0, 2) + (2, 1) = (2, 3). ✓
Interactive figures
Interactive figure (online). Description: The matrix grid shows the plane before (fine grid) and after (blue grid) applying the matrix. An orange arrow shows where (1, 0) lands, a green arrow where (0, 1) lands, and a purple patch shows the transformed unit square. A test point (1.5, 1) and its image P′ are joined by a dashed arrow. The readout lists the matrix, both columns, P′ and the determinant.
Interactive figure (online). Description: The frame-chain viewer draws the world axes in black, frame A in blue and frame B in orange (solid arrow for x, dashed for y), with point p as a lime dot. The readout shows p in B, in A and in the world, and prints the 3×3 matrices T_WA, T_AB and their product T_WB.
Laboratory
Everything runs in your browser. No kit, nothing mains-powered. Simulations are simplified educational models.
Equation Lab exploration
Equation Lab: Matrices
Apply a 30° rotation matrix to the unit square and confirm that every side keeps its length.
Open Equation Lab: Matrices →Playground lab
Playground: Robotic kinematics
Chain two frames and predict where a point ends up before checking it.
Open Playground: Robotic kinematics →
Guided practice
Answers are checked on the server; wrong answers get a hint and another try. Signed in, solved items also count towards the source lesson.
- [3 1; 0 2]·(2, 5): what is the first component?
- Which matrix sends (1, 0) to (0, 2) and (0, 1) to (−1, 0)?
- [0 −1; 2 0]
- [0 2; −1 0]
- [0 −1; 0 2]
- [2 0; 0 −1]
- Which matrix is R(90°)?
- [0 1; −1 0]
- [0 −1; 1 0]
- [1 0; 0 1]
- [−1 0; 0 −1]
- The point (5, 12) is rotated by 73°. What is its distance from the origin afterwards?
- Frame rotated 0° with origin (4, −1). Point (2, 3) in that frame. What is its parent x coordinate?
- Which is T_W←tool for the chain world → base → link → tool?
- T_W←base · T_base←link · T_link←tool
- T_link←tool · T_base←link · T_W←base
- T_W←base + T_base←link + T_link←tool
- T_W←base⁻¹ · T_link←tool
- T has θ = 0° and t = (3, −2). What is the x translation of T⁻¹?
Engineering applications
Robot software frameworks
Robot software keeps a tree of frames, map to robot to arm to camera to gripper, each joined by a transform. Asking where the camera sees a cup in map coordinates is a walk along that tree, multiplying transforms.
Games and graphics
Every object in a video game is drawn by multiplying its points by a chain of transforms: model to world, world to camera, camera to screen. The same mathematics places a robot hand.
Watch
Optional verified videos. Nothing loads from YouTube until you press play.
- Modern Robotics, Chapter 3.2.1: Rotation Matrices (Part 1 of 2) (Northwestern Robotics)
- Modern Robotics, Chapter 3: Introduction to Rigid-Body Motions (Northwestern Robotics)
- Linear transformations and matrices | Chapter 3, Essence of linear algebra (3Blue1Brown)
Chapter summary
- Multiplying a matrix by a vector moves the vector; the columns show where the axes go.
- A rotation matrix turns vectors by an angle and keeps their lengths.
- A homogeneous transform combines a rotation and a translation in one 3 × 3 matrix.
- Chains of transforms multiply in order; the inverse walks the chain backwards.
Glossary
- 2D rotation matrix
- A 2D rotation by angle θ anticlockwise maps (x, y) to (x cos θ − y sin θ, x sin θ + y cos θ), written as a 2×2 matrix.
- Matrix multiplication
- Multiplying matrices combines rows of the first with columns of the second: each entry of the result is a dot product of a row and a column.
- Coordinate frame
- A coordinate frame is an origin plus a set of axes used to describe positions and directions. Robots use several: world, base, each joint, sensors and the tool.
Definitions from the Field Guide.
Project: A frame tree
Model a desk lamp with a base, two arms and a head as a chain of four frames. Choose angles and lengths, write each homogeneous transform, multiply them to find where the bulb is, and invert the chain to express a point on the desk in the bulb's frame.
Deliverables
- A labelled sketch of the four frames
- Each transform written out
- The bulb position and the inverted point, checked in code
Keep your work in your Engineering Journal; it stays private unless you choose to share it.
References
- Kevin M. Lynch and Frank C. Park (2017). Modern Robotics: Mechanics, Planning, and Control. Cambridge University Press.
- John J. Craig (2005). Introduction to Robotics: Mechanics and Control, 3rd edition. Pearson Prentice Hall.
- Mark W. Spong et al. (2006). Robot Modeling and Control. Wiley.
Further reading from the source lessons
- Linear map (Wikipedia) ↗The general idea behind matrices as transformations.
- Rotation matrix (Wikipedia) ↗2D and 3D rotation matrices and their properties.
- Homogeneous coordinates (Wikipedia) ↗Where the idea comes from (projective geometry) and why graphics uses it.
- Rigid transformation (Wikipedia) ↗Properties of transformations that keep distances.
Publication record
- Version
- 1
- Status
- Technically checked (automated checks only)
- Technical review
- Automated checks only, last run 2026-11-29. No human, educator or mentor review is claimed.src/content/textbooks/textbooks.test.ts: schema, every lesson, diagram, practice item, video, Field Guide entry, lab and reference resolves; figure numbers recomputed; no practice answers in client payloads.
- Written by
- Compiled and written by the Tactiverge team with AI assistance, from Tactiverge School lessons that were themselves written with AI assistance.
- Licence
- All rights reserved by the founders unless a licence is approved.
- Corrections
- None recorded yet.Spotted a mistake? Use “Report a problem” on any chapter, or see the corrections page.