determin.ant
02-transformations / 2.3

Module 2: Transformations

Composition

Where you'll see this: a 3D game applies a chain of transformations to every object each frame — scale it, rotate it, translate it into world space, then into camera space. All of those are multiplied into one matrix so the GPU only does one operation per vertex. Composition is how that chain is built.

You can apply one transformation after another. First rotate the grid, then stretch it. The combined effect is itself a linear transformation — and it has its own matrix.

Matrix multiplication = applying two transformations

If AA is the first transformation and BB is the second, the composition is written BABAB after A. The order matters: rotate-then-scale is not the same as scale-then-rotate.

(BA)v=B(Av)(B \circ A)\,\mathbf{v} = B(A\mathbf{v})

Read right-to-left: apply AA to the vector first, then applyBB to the result. The combined matrix BABA stores that whole process in one object.

Why order matters

Consider rotating 90° then scaling x by 2, versus scaling x by 2 then rotating 90°. Try swapping A and B in the interactive — you'll get a different grid each time. In matrix terms: BAABBA \neq AB in general.

Matrix multiplication is not commutative. This surprises people who are used to regular numbers where 3×5=5×33 \times 5 = 5 \times 3. With matrices, the order you multiply them in is the order the transformations happen.

Determinants multiply

There's a clean rule for area scaling: the determinant of a product equals the product of the determinants.

det(BA)=det(B)det(A)\det(BA) = \det(B) \cdot \det(A)

If A doubles area and B triples it, BA scales area by 6. Watch the determinant readout below the matrices as you change presets.

In code

import numpy as np

A = np.array([[0, -1], [1,  0]])  # rotate 90°
B = np.array([[2,  0], [0,  1]])  # scale x by 2

# Apply A first, then B
BA = B @ A
v = np.array([1, 0])
print(BA @ v)   # same as B @ (A @ v)

In NumPy, B @ A computes the composed matrix. Note that A @ B gives a different result.

Matrices as TransformationsThe Transformation Zoo
A is applied first, then B — result is B·A
îĵ
A (first)
[
]
î → [0.7071067811865476, 0.7071067811865475]ĵ → [-0.7071067811865475, 0.7071067811865476]
B (second)
[
]
î → [2, 0]ĵ → [0, 1]
B · A = [1.41, -1.41; 0.71, 0.71]
det(B·A) = 2 = det(A) × det(B) = 1 × 2