TactivergeLite

Lite / Textbooks / Robotics From First Principles / Chapter 4

4. Rotations and transforms

Version 1 · Technically checked (automated checks only) · 4 source lessons · Full interactive version

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

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(θ)
  1. A matrix is fixed by where it sends (1, 0) and (0, 1): those images are its columns.

  2. Rotating (1, 0) by θ lands on the unit circle at angle θ: (cos θ, sin θ). That's column 1.

  3. (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.

  4. So R(θ) = [cos θ −sin θ; sin θ cos θ], and R(θ)·(x, y) = (x cos θ − y sin θ, x sin θ + y cos θ).

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

  6. Check area: det R = cos θ · cos θ − (−sin θ) · sin θ = cos²θ + sin²θ = 1. No stretching, no flipping.

Common mix-ups

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

  2. Trick: write points with an extra coordinate fixed at 1: p = (x, y, 1).

  3. Build T = [R t; 0 0 1] = [cos θ −sin θ tx; sin θ cos θ ty; 0 0 1].

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

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

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

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.

The interactive versions are in the full chapter.

Laboratory

These run in a browser on the full site (they need a faster connection). Simulations are simplified educational models.

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.

  1. [3 1; 0 2]·(2, 5): what is the first component?
    Answer it in “A matrix is a machine that moves vectors”
  2. 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”
  3. Which matrix is R(90°)?
    Answer it in “The rotation matrix, built from scratch”
  4. 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”
  5. 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”
  6. Which is T_W←tool for the chain world → base → link → tool?
    Answer it in “Chains of frames, and the way back”
  7. 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.

Summary

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

Write it up on paper or in your own notes. Lite never stores what you write.

References

Further reading from the lessons

← 3. Vectors and frames5. Forward kinematics →