4.3. Matrices 151
Geometrically, L = LERP(A, B, β) is the position vector of a point that lies
β percent of the way along the line segment from point A to point B, as shown
in Figure 4.15. Mathematically, the LERP function is just a weighted average of
the two input vectors, with weights (1 – β) and β, respectively. Notice that the
weights always add to 1, which is a general requirement for any weighted
average.
4.3 Matrices
A matrix is a rectangular array of m × n scalars. Matrices are a convenient way
of representing linear transformations such as translation, rotation, and scale.
A matrix M is usually writt en as a grid of scalars Mrc enclosed in square
brackets, where the subscripts r and c represent the row and column indices
of the entry, respectively. For example, if M is a 3 × 3 matrix, it could be writ-
ten as follows:
We can think of the rows and/or columns of a 3 × 3 matrix as 3D vectors.
When all of the row and column vectors of a 3 × 3 matrix are of unit magni-
tude, we call it a special orthogonal matrix. This is also known as an isotropic
matrix, or an orthonormal matrix. Such matrices represent pure rotations.
Under certain constraints, a 4 × 4 matrix can represent arbitrary 3D trans-
formations , including translations , rotations , and changes in scale. These are
called transformation matrices , and they are the kinds of matrices that will be
most useful to us as game engineers. The transformations represented by a
matrix are applied to a point or vector via matrix multiplication. We’ll inves-
tigate how this works below.
An affi ne matrix is a 4 × 4 transformation matrix that preserves parallelism
of lines and relative distance ratios, but not necessarily absolute lengths and
angles. An affi ne matrix is any combination of the following operations: rota-
tion, translation, scale and/or shear.
4.3.1. Matrix Multiplication
The product P of two matrices A and B is writt en P = AB. If A and B are
transformation matrices, then the product P is another transformation matrix
that performs both of the original transformations. For example, if A is a scale
matrix and B is a rotation, the matrix P would both scale and rotate the points
A L= LERP(A, B, 0.4)
β = 0 B
β = 1
β = 0.4
Figure 4.15. Linear in-
terpolation (LERP) be-
tween points A and B,
with β = 0.4.
11 12 13
21 22 23
31 32 33