Lite / Textbooks / Robotics From First Principles / Chapter 4
4. Rotations and transforms
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.
Figure 4.1. Rotate, then shift (described in words)
The vector (2, 0) rotated by 30° becomes (1.732, 1); shifting that by (1, 0.5) gives (2.732, 1.5). One homogeneous transform performs both steps at once.
Explanation
Built from 4 School lessons. Each part is the lesson's own explanation.
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 Lite 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 Lite 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 Lite 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.
Open the Lite lesson: Chains of frames, and the way back
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, in words
Figure 4.2 from A matrix is a machine that moves vectors
Try each preset and describe it in words. Then choose Custom and build: (a) a matrix that triples heights only, (b) one that swaps x and y, (c) one that squashes the plane onto a line. For each, watch where the orange (1, 0) and green (0, 1) arrows land, and the determinant.
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.
Figure 4.3 from Homogeneous transforms: rotate and shift in one matrix
Set frame B's rotation and shift to 0, so only frame A matters. Put A at 90°, shift (2, 1), and p at (1, 0). Check the world position against your prediction, and read T_WA. Which entries hold the rotation? Which hold the shift?
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
These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.
- Equation Lab: Matrices (Equation Lab exploration)
Apply a 30° rotation matrix to the unit square and confirm that every side keeps its length.
Open on the full site - Playground: Robotic kinematics (Playground lab)
Chain two frames and predict where a point ends up before checking it.
Open on the full site
Practice
Each question links to its Lite lesson, where your answer is checked on our server and a wrong answer gets a hint. Answers are never sent to your device.
- [3 1; 0 2]·(2, 5): what is the first component?
Answer it in “A matrix is a machine that moves vectors” - Which matrix sends (1, 0) to (0, 2) and (0, 1) to (−1, 0)?
Answer it in “A matrix is a machine that moves vectors” - Which matrix is R(90°)?
Answer it in “The rotation matrix, built from scratch” - The point (5, 12) is rotated by 73°. What is its distance from the origin afterwards?
Answer it in “The rotation matrix, built from scratch” - Frame rotated 0° with origin (4, −1). Point (2, 3) in that frame. What is its parent x coordinate?
Answer it in “Homogeneous transforms: rotate and shift in one matrix” - Which is T_W←tool for the chain world → base → link → tool?
Answer it in “Chains of frames, and the way back” - T has θ = 0° and t = (3, −2). What is the x translation of T⁻¹?
Answer it in “Chains of frames, and the way back”
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)
Streaming video uses a lot of data. Everything you need is in the text.
- “Modern Robotics, Chapter 3.2.1: Rotation Matrices (Part 1 of 2)” by Northwestern Robotics
- “Modern Robotics, Chapter 3: Introduction to Rigid-Body Motions” by Northwestern Robotics
- “Linear transformations and matrices | Chapter 3, Essence of linear algebra” by 3Blue1Brown
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. Field Guide
- 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. Field Guide
- 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. 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
Write it up on paper or in your own notes. Lite never stores what you write.
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 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.