The idea: doing A and then B is one matrix, B·A
Every 2×2 matrix moves the plane: it sends each point v to A·v. If you move the plane with A and then move the result with B, every point ends at B(A·v). That two-step move is again a linear map, so it has a matrix of its own, and that matrix is the product B·A. This is called the composition of the two maps.
Watch the order of the letters. The transform that acts first is written on the right, because it is the one next to v: in B·A·v, the vector meets A first. Read a product from right to left. On the canvas, pick "first A" and "then B": the grid moves by A, then by B, and the product panel works out B·A.
Row times column
Each entry of B·A is a row of B times a column of A: multiply entry by entry and add. With A = rotate 90° = [0 −1; 1 0] and B = shear = [1 1; 0 1]:
The columns of the answer are where î and ĵ end up after both moves: î goes to (0, 1) under the rotation, and the shear moves (0, 1) to (1, 1). That is column 1 of B·A. Column j of B·A is B times column j of A. The full rule for bigger matrices is on Matrix Multiplication.
Order matters, AB ≠ BA
Swap the two and you get a different matrix: rotate 90° after the shear gives R·H = [0 −1; 1 1], not [1 −1; 1 0]. The two end pictures differ. The Swap order button keeps the first end picture in grey and runs the other order from the start, so you can see the blue F land somewhere else (Demo: rotate then shear vs shear then rotate).
Some pairs do commute (AB = BA):
| Pair | Commutes? | Why |
|---|---|---|
| two rotations about 0 | ✓ yes | the angles add: 45° + 90° = 90° + 45° = 135° |
| two scalings along the axes | ✓ yes | diagonal matrices: [a 0; 0 b][c 0; 0 d] = [ac 0; 0 bd] |
| any map and itself, any map and I | ✓ yes | A·A = A·A, A·I = I·A = A |
| rotation and shear | ✗ no | H·R ≠ R·H above |
| two different reflections | ✗ no | one order turns +2α, the other −2α |
| scale x and rotate 90° | ✗ no | the stretch lands on x or on y |
Two rotations about the origin always commute (Demo: two rotations: order doesn't matter): after Swap order the blue grid lands exactly on the grey one. See Rotation Matrix and Scaling Matrix.
Two reflections make a rotation
A reflection flips the plane over a mirror line. Flip twice and the two flips cancel: the result keeps orientation, so it is a rotation. Its angle is twice the angle between the mirrors, turning from the first mirror toward the second. Reflect in the x-axis (0°) and then in the line y = x (45°): the result is the rotation by 2·45° = 90° (Demo: two reflections make a rotation):
In the other order (first y = x, then the x-axis) the turn goes the other way, −90°. A reflection followed by a rotation, or the other way round, is again a reflection.
Determinants multiply
The determinant is the factor by which a map changes areas, with a minus sign when it flips orientation. Two maps in a row multiply the area factors, so det(BA) = det B · det A (Demo: det multiplies).
| first A | then B | det A | det B | det(BA) | what happens to area |
|---|---|---|---|---|---|
| scale x by 2 | reflect in x-axis | 2 | −1 | −2 | doubled and flipped |
| reflect in x-axis | reflect in y = x | −1 | −1 | 1 | two flips cancel: a rotation |
| rotate 90° | shear k = 1 | 1 | 1 | 1 | area kept |
| project onto x-axis | rotate 90° | 0 | 1 | 0 | flat: area 0, for good |
Because det B · det A = det A · det B, the two orders always have the same determinant even when AB ≠ BA: same area factor, different map.
Undo in reverse order: socks and shoes
You put on socks, then shoes. To undo that you take off the shoes first, then the socks. Matrices work the same way: the inverse of B·A is
B went on last, so B⁻¹ acts first; A⁻¹ acts last and is written on the left. The Undo (reverse order) button does exactly that: the grid moves by B⁻¹ back to A's picture, then by A⁻¹ back to the plain grid (Demo: undo in reverse order (socks and shoes)). The wrong order, B⁻¹A⁻¹, does not get back unless A and B commute.
If either map has det 0, the product has det 0 too and nothing can undo it. A projection sends a whole line of points to one point, and no matrix can tell them apart again (Demo: a projection can't be undone).
See also the overview Linear Transformations, the single transforms Rotation Matrix, Reflection Matrix, Scaling Matrix, Shear Matrix and Projection Matrix, Inverse Matrix, Affine Transforms (composing moves that include a translation), Rotate and Translate in 2D, Diagonalization (A = PDP⁻¹, a composition of three maps) and SVD and PCA (every matrix is rotate, stretch, rotate).
What the page leaves out
Only seven fixed 2×2 maps and pairs of them are drawn. Chains of three or more (the product is associative: (CB)A = C(BA), so the brackets never matter, only the order), composing with translations (they need 3×3 homogeneous matrices, see Affine Transforms), 3D compositions such as yaw-pitch-roll rotations, rotations about different centers, and the group structure (rotations form a group that commutes in 2D but not in 3D) are not shown.