Chapter 6
More on Matrices
Man's mind stretched to a new idea
never goes back to its original dimensions.
— Oliver Wendell Holmes Jr. (1841–1935)
Chapter 4 presented a few of the most of the important properties and operations of
matrices and discussed how matrices can be used to express geometric transformations in general.
Chapter 5 considered matrices and geometric transforms in detail. This chapter
completes our coverage of matrices by discussing a few more interesting and useful matrixoperations.

Section 6.1 covers the determinant of a matrix.

Section 6.2 covers the inverse of a matrix.

Section 6.3 discusses orthogonal matrices.

Section 6.4 introduces
homogeneous vectors and
$4\times 4$
matrices, and
shows how they can be used to perform affine transformations
in3D.

Section 6.5 discusses
perspective projection and shows how to do it
with a
$4\times 4$
matrix.
6.1Determinant of a Matrix
For square matrices, there is a special scalar called the
determinant of the matrix. The determinant has many useful properties in linear algebra,
and it also has interesting geometric interpretations.
As is our custom, we first discuss some math, and then make some geometric interpretations.
Section 6.1.1 introduces the notation for determinants and gives the linear
algebra rules for computing the determinant of a
$2\times 2$
or
$3\times 3$
matrix.
Section 6.1.2 discusses minors and cofactors. Then,
Section 6.1.3 shows how to compute the determinant of an arbitrary
$n\times n$
matrix, by using minors and cofactors. Finally, Section 6.1.4
interprets the determinant from a geometric perspective.
6.1.1
Determinants of
$\mathbf{2}\mathbf{\times}\mathbf{2}$
and
$\mathbf{3}\mathbf{\times}\mathbf{3}$
matrices
The determinant of a square matrix
$\mathbf{M}$
is denoted
$\left\mathbf{M}\right$
or, in some
other books, as “
$\mathrm{d}\mathrm{e}\mathrm{t}\text{}\mathbf{M}$
.” The determinant of a nonsquare matrix is
undefined. This section shows how to compute determinants of
$2\times 2$
and
$3\times 3$
matrices. The determinant of a general
$n\times n$
matrix, which is fairly complicated, is
discussed in Section 6.1.3
The determinant of a
$\mathbf{2}\mathbf{\times}\mathbf{2}$
matrix is given by
Determinant of a
$\mathbf{2}\mathbf{\times}\mathbf{2}$
matrix
$$\begin{array}{}\text{(6.1)}& \left\mathbf{M}\right=\left\begin{array}{cc}{m}_{11}& {m}_{12}\\ {m}_{21}& {m}_{22}\end{array}\right={m}_{11}{m}_{22}{m}_{12}{m}_{21}.\end{array}$$
Notice that when we write the determinant of a matrix, we replace the brackets with vertical
lines.
Equation (6.1) can be remembered easier with the following diagram. Simply multiply
entries along the diagonal and backdiagonal, then subtract the backdiagonal term from the
diagonal term.
Some examples help to clarify the simple calculation:
$$\begin{array}{rl}\left\begin{array}{cc}2& 1\\ 1& 2\end{array}\right& =(2)(2)(1)(1)=4+1=5;\\ \left\begin{array}{cc}3& 4\\ 2& 5\end{array}\right& =(3)(5)(4)(2)=158=23;\\ \left\begin{array}{cc}a& b\\ c& d\end{array}\right& =adbc.\end{array}$$
The determinant of a
$3\times 3$
matrix is given by
Determinant of a
$\mathbf{3}\mathbf{\times}\mathbf{3}$
matrix
$$\begin{array}{rl}{\displaystyle \left\begin{array}{ccc}{m}_{11}& {m}_{12}& {m}_{13}\\ {m}_{21}& {m}_{22}& {m}_{23}\\ {m}_{31}& {m}_{32}& {m}_{33}\end{array}\right}{\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle \phantom{\rule{1em}{0ex}}}& \\ \text{(6.2)}& =& \begin{array}{c}{m}_{11}{m}_{22}{m}_{33}+{m}_{12}{m}_{23}{m}_{31}+{m}_{13}{m}_{21}{m}_{32}\\ {\textstyle}{m}_{13}{m}_{22}{m}_{31}{m}_{12}{m}_{21}{m}_{33}{m}_{11}{m}_{23}{m}_{32}\end{array}=& \text{}\text{}{m}_{11}({m}_{22}{m}_{33}{m}_{23}{m}_{32})\\ & {\textstyle}+{m}_{12}({m}_{23}{m}_{31}{m}_{21}{m}_{33})\\ & {\textstyle}+{m}_{13}({m}_{21}{m}_{32}{m}_{22}{m}_{31}).\end{array}$$
A similar diagram can be used to memorize Equation (6.2). We
write two copies of the matrix
$\mathbf{M}$
side by side and multiply entries along the diagonals
and backdiagonals, adding the diagonal terms and subtracting the backdiagonal terms.
For example,
$$\begin{array}{rl}\left\begin{array}{ccc}4& 3& 3\\ 0& 2& 2\\ 1& 4& 1\end{array}\right& =\begin{array}{rrlrrr}& 4& 2& 1& 2& 4\\ +& 3& 2& 1& 0& 1\\ +& 3& 0& 4& 2& 1\end{array}\\ & =\begin{array}{rrlr}& 4& 2& 8\\ +& 3& 2& 0\\ +& 3& 0& 2\end{array}=\begin{array}{rrr}& 4& 6\\ +& 3& 2\\ +& 3& 2\end{array}=\begin{array}{rr}& 24\\ +& 6\\ +& 6\end{array}\\ \text{(6.3)}& & =24.\end{array}$$
If we interpret the rows of a
$3\times 3$
matrix as three vectors, then the determinant of the
matrix is equivalent to the socalled
“triple product” of the three vectors:
$\mathbf{3}\mathbf{\times}\mathbf{3}$
determinant vs. 3D vector triple product
$$\left\begin{array}{ccc}{a}_{x}& {a}_{y}& {a}_{z}\\ {b}_{x}& {b}_{y}& {b}_{z}\\ {c}_{x}& {c}_{y}& {c}_{z}\end{array}\right=\begin{array}{l}({a}_{y}{b}_{z}{a}_{z}{b}_{y}){c}_{x}\\ {\textstyle}+({a}_{z}{b}_{x}{a}_{x}{b}_{z}){c}_{y}\\ {\textstyle}+({a}_{x}{b}_{y}{a}_{y}{b}_{x}){c}_{z}\end{array}=(\mathbf{a}\times \mathbf{b})\cdot \mathbf{c}.$$
6.1.2Minors and Cofactors
Before we can look at determinants in the general case, we need to introduce some other
constructs: minors and cofactors.
Assume
$\mathbf{M}$
is a matrix with
$r$
rows and
$c$
columns. Consider the matrix obtained by
deleting row
$i$
and column
$j$
from
$\mathbf{M}$
. This matrix will obviously have
$r1$
rows and
$c1$
columns. The determinant of this submatrix, denoted
${M}^{\{ij\}}$
is known as a minor
of
$\mathbf{M}$
. For example, the minor
${M}^{\{12\}}$
is the determinant of the
$2\times 2$
matrix that is the result of deleting row 1 and column 2 from the
$3\times 3$
matrix
$\mathbf{M}$
:
A minor of a
$\mathbf{3}\mathbf{\times}\mathbf{3}$
matrix
$$\mathbf{M}=\left[\begin{array}{ccc}{4}& {3}& {3}\\ 0& {2}& 2\\ 1& {4}& 1\end{array}\right]\text{}\text{}\text{}\text{}\u27f9\text{}\text{}\text{}\text{}{M}^{\{12\}}=\left\begin{array}{cc}0& 2\\ 1& 1\end{array}\right=2.$$
The cofactor of a square matrix
$\mathbf{M}$
at a given row and column is the same as the
corresponding minor, but with alternating minors negated:
Matrix cofactor
$$\begin{array}{}\text{(6.4)}& {C}^{\{ij\}}=(1{)}^{i+j}{M}^{\{ij\}}.\end{array}$$
As shown in Equation (6.4), we use the notation
${C}^{\{ij\}}$
to denote the
cofactor of
$\mathbf{M}$
in row
$i$
, column
$j$
. The
$(1{)}^{(i+j)}$
term has the effect of
negating every other cofactor in a checkerboard pattern:
$$\left[\begin{array}{ccccc}+& & +& & \cdots \\ & +& & +& \cdots \\ +& & +& & \cdots \\ & +& & +& \cdots \\ \vdots & \vdots & \vdots & \vdots & \ddots \end{array}\right].$$
In the next section, we use minors and cofactors to compute determinants of an arbitrary
dimension
$n\times n$
, and again in Section 6.2 to compute the inverse of a matrix.
6.1.3Determinants of Arbitrary
$\mathit{n}\mathbf{\times}\mathit{n}$
Matrices
Several equivalent definitions exist for the determinant of a matrix of arbitrary dimension
$n\times n$
. The definition we consider here expresses a determinant in terms of its cofactors.
This definition is recursive, since cofactors are themselves signed determinants. First, we
arbitrarily select a row or column from the matrix. Now, for each element in the row or column,
we multiply this element by the corresponding cofactor. Summing these products yields the
determinant of the matrix. For example, arbitrarily selecting row
$i$
, the determinant can be
computed by
$$\begin{array}{}\text{(6.5)}& \left\mathbf{M}\right=\sum _{j=1}^{n}{m}_{ij}{C}^{\{ij\}}=\sum _{j=1}^{n}{m}_{ij}(1{)}^{i+j}{M}^{\{ij\}}.\end{array}$$
Computing an
$\mathit{n}\mathbf{\times}\mathit{n}$
determinant by using cofactors of row
$\mathit{i}$
As it turns out, it doesn't matter which row or column we choose; they all will produce the same
result.
Let's look at an example. We'll rewrite the equation for
$3\times 3$
determinant using
Equation (6.5):
Recursive definition of determinant applied to
$\mathbf{3}\mathbf{\times}\mathbf{3}$
case
$$\begin{array}{r}\begin{array}{rl}\left\begin{array}{ccc}{m}_{11}& {m}_{12}& {m}_{13}\\ {m}_{21}& {m}_{22}& {m}_{23}\\ {m}_{31}& {m}_{32}& {m}_{33}\end{array}\right& ={m}_{11}\left\begin{array}{cc}{m}_{22}& {m}_{23}\\ {m}_{32}& {m}_{33}\end{array}\right{m}_{12}\left\begin{array}{cc}{m}_{21}& {m}_{23}\\ {m}_{31}& {m}_{33}\end{array}\right\\ & {\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle}+{m}_{13}\left\begin{array}{cc}{m}_{21}& {m}_{22}\\ {m}_{31}& {m}_{32}\end{array}\right.\end{array}\end{array}$$
Now, let's derive the
$4\times 4$
matrix determinant:
Recursive definition of determinant applied to
$\mathbf{4}\mathbf{\times}\mathbf{4}$
case
$$\begin{array}{rl}{\displaystyle \left\begin{array}{cccc}{m}_{11}& {m}_{12}& {m}_{13}& {m}_{14}\\ {m}_{21}& {m}_{22}& {m}_{23}& {m}_{24}\\ {m}_{31}& {m}_{32}& {m}_{33}& {m}_{34}\\ {m}_{41}& {m}_{42}& {m}_{43}& {m}_{44}\end{array}\right={m}_{11}\left\begin{array}{ccc}{m}_{22}& {m}_{23}& {m}_{24}\\ {m}_{32}& {m}_{33}& {m}_{34}\\ {m}_{42}& {m}_{43}& {m}_{44}\end{array}\right}{\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle \phantom{\rule{1em}{0ex}}}{\textstyle \phantom{\rule{1em}{0ex}}}& \\ & {\textstyle}{m}_{12}\left\begin{array}{ccc}{m}_{21}& {m}_{23}& {m}_{24}\\ {m}_{31}& {m}_{33}& {m}_{34}\\ {m}_{41}& {m}_{43}& {m}_{44}\end{array}\right+{m}_{13}\left\begin{array}{ccc}{m}_{21}& {m}_{22}& {m}_{24}\\ {m}_{31}& {m}_{32}& {m}_{34}\\ {m}_{41}& {m}_{42}& {m}_{44}\end{array}\right\\ & {\textstyle}{m}_{14}\left\begin{array}{ccc}{m}_{21}& {m}_{22}& {m}_{23}\\ {m}_{31}& {m}_{32}& {m}_{33}\\ {m}_{41}& {m}_{42}& {m}_{43}\end{array}\right.\end{array}$$
Expanding the cofactors, we have
Determinant of a
$4\times 4$
matrix in expanded form
$$\begin{array}{r}{\textstyle \phantom{\rule{1em}{0ex}}}\text{}{m}_{11}[{m}_{22}({m}_{33}{m}_{44}{m}_{34}{m}_{43})+{m}_{23}({m}_{34}{m}_{42}{m}_{32}{m}_{44})+{m}_{24}({m}_{32}{m}_{43}{m}_{33}{m}_{42})]\\ {\textstyle}{m}_{12}[{m}_{21}({m}_{33}{m}_{44}{m}_{34}{m}_{43})+{m}_{23}({m}_{34}{m}_{41}{m}_{31}{m}_{44})+{m}_{24}({m}_{31}{m}_{43}{m}_{33}{m}_{41})]\\ {\textstyle}+{m}_{13}[{m}_{21}({m}_{32}{m}_{44}{m}_{34}{m}_{42})+{m}_{22}({m}_{34}{m}_{41}{m}_{31}{m}_{44})+{m}_{24}({m}_{31}{m}_{42}{m}_{32}{m}_{41})]\\ {\textstyle}{m}_{14}[{m}_{21}({m}_{32}{m}_{43}{m}_{33}{m}_{42})+{m}_{22}({m}_{33}{m}_{41}{m}_{31}{m}_{43})+{m}_{23}({m}_{31}{m}_{42}{m}_{32}{m}_{41})]{\displaystyle .}\end{array}$$
As you can imagine, the complexity of explicit formulas for determinants of higher degree grows
rapidly. Luckily, we can perform an operation known as
“pivoting,” which doesn't affect the value
of the determinant, but causes a particular row or column to be filled with zeroes except for a
single element (the “pivot” element). Then only one cofactor has to be evaluated. Since we
won't need determinants of matrices higher than the
$4\times 4$
case, anyway, a complete
discussion of pivoting is outside the scope of this book.
Let's briefly state some important characteristics concerning determinants.

The determinant of an identity matrix of any dimension is 1:
Determinant of identity matrix
$$\left\mathbf{I}\right=1.$$

The determinant of a matrix product is equal to the
product of the determinants:
Determinant of matrix product
$$\left\mathbf{A}\mathbf{B}\right=\left\mathbf{A}\right\left\mathbf{B}\right.$$
This extends to more than two matrices:
$$\left{\mathbf{M}}_{1}{\mathbf{M}}_{2}\cdots {\mathbf{M}}_{n1}{\mathbf{M}}_{n}\right=\left{\mathbf{M}}_{1}\right\left{\mathbf{M}}_{2}\right\cdots \left{\mathbf{M}}_{n1}\right\left{\mathbf{M}}_{n}\right.$$

The determinant of the transpose of a matrix is equal to the original
determinant:
Determinant of matrix transpose
$$\left{\mathbf{M}}^{\mathrm{T}}\right=\left\mathbf{M}\right.$$

If any row or column in a matrix contains all 0s, then the determinant
of that matrix is 0:
Determinant of matrix with a row/column full of 0s
$$\left\begin{array}{cccc}?& ?& \cdots & ?\\ ?& ?& \cdots & ?\\ \vdots & \vdots & & \vdots \\ 0& 0& \cdots & 0\\ \vdots & \vdots & & \vdots \\ ?& ?& \cdots & ?\end{array}\right=\left\begin{array}{cccccc}?& ?& \cdots & 0& \cdots & ?\\ ?& ?& \cdots & 0& \cdots & ?\\ \vdots & \vdots & & \vdots & & \vdots \\ ?& ?& \cdots & 0& \cdots & ?\end{array}\right=0.$$

Exchanging any pair of rows negates the determinant:
Swapping rows negates the determinant
$$\left\begin{array}{cccc}{m}_{11}& {m}_{12}& \cdots & {m}_{1n}\\ {m}_{21}& {m}_{22}& \cdots & {m}_{2n}\\ \vdots & \vdots & & \vdots \\ {m}_{i1}& {m}_{i2}& \cdots & {m}_{in}\\ \vdots & \vdots & & \vdots \\ {m}_{j1}& {m}_{j2}& \cdots & {m}_{jn}\\ \vdots & \vdots & & \vdots \\ {m}_{n1}& {m}_{n2}& \cdots & {m}_{nn}\end{array}\right=\left\begin{array}{cccc}{m}_{11}& {m}_{12}& \cdots & {m}_{1n}\\ {m}_{21}& {m}_{22}& \cdots & {m}_{2n}\\ \vdots & \vdots & & \vdots \\ {m}_{j1}& {m}_{j2}& \cdots & {m}_{jn}\\ \vdots & \vdots & & \vdots \\ {m}_{i1}& {m}_{i2}& \cdots & {m}_{in}\\ \vdots & \vdots & & \vdots \\ {m}_{n1}& {m}_{n2}& \cdots & {m}_{nn}\end{array}\right.$$
This same rule applies for exchanging a pair of columns.

Adding any multiple of a row (column) to another row (column) does not change the
value of the determinant!
Adding one row to
another doesn't
change the
determinant
$$\left\begin{array}{cccc}{m}_{11}& {m}_{12}& \cdots & {m}_{1n}\\ {m}_{21}& {m}_{22}& \cdots & {m}_{2n}\\ \vdots & \vdots & & \vdots \\ {m}_{i1}& {m}_{i2}& \cdots & {m}_{in}\\ \vdots & \vdots & & \vdots \\ {m}_{j1}& {m}_{j2}& \cdots & {m}_{jn}\\ \vdots & \vdots & & \vdots \\ {m}_{n1}& {m}_{n2}& \cdots & {m}_{nn}\end{array}\right=\left\begin{array}{cccc}{m}_{11}& {m}_{12}& \cdots & {m}_{1n}\\ {m}_{21}& {m}_{22}& \cdots & {m}_{2n}\\ \vdots & \vdots & & \vdots \\ {m}_{i1}+k{m}_{j1}& {m}_{i2}+k{m}_{j2}& \cdots & {m}_{in}+k{m}_{jn}\\ \vdots & \vdots & & \vdots \\ {m}_{j1}& {m}_{j2}& \cdots & {m}_{jn}\\ \vdots & \vdots & & \vdots \\ {m}_{n1}& {m}_{n2}& \cdots & {m}_{nn}\end{array}\right$$
This explains why our shear matrices from
Section 5.5 have a determinant
of 1.
6.1.4Geometric Interpretation of Determinant
The determinant of a matrix has an interesting geometric interpretation. In 2D, the determinant
is equal to the signed area of the parallelogram or
skew box that has the basis vectors as two sides (see Figure 6.1). (We
discussed how we can use skew boxes to visualize coordinate space transformations in
Section 4.2.) By signed area, we mean that the area is
negative if the skew box is “flipped” relative to its original orientation.
In 3D, the determinant is the volume of the
parallelepiped that has the transformed basis vectors as three edges. It will be negative
if the object is reflected (“turned inside out”) as a result of the transformation.
The determinant is related to the change in size that results from
transforming by the matrix. The absolute value of the determinant
is related to the change in area (in 2D) or volume (in 3D) that
will occur as a result of transforming an object by the matrix,
and the sign of the determinant indicates whether any reflection
or projection is contained in the matrix.
The determinant of the matrix can also be used to help classify the
type of transformation represented by a matrix. If the determinant
of a matrix is zero, then the matrix contains a projection. If the
determinant of a matrix is negative, then reflection is contained in
the matrix. See
Section 5.7 for more
about different classes of transformations.
6.2Inverse of a Matrix
Another important operation that applies only to square matrices is the
inverse of a matrix. This section discusses the matrix inverse from a mathematical and
geometric perspective.
The inverse of a square matrix
$\mathbf{M}$
, denoted
${\mathbf{M}}^{1}$
is the matrix such that
when we multiply
$\mathbf{M}$
by
${\mathbf{M}}^{1}$
on either side, the result is the identity
matrix. In other words,
Matrix inverse
$$\mathbf{M}({\mathbf{M}}^{1})={\mathbf{M}}^{1}\mathbf{M}=\mathbf{I}.$$
Not all matrices have an inverse. An obvious example is a matrix with a row or column filled
with 0s—no matter what you multiply this matrix by, the corresponding row or column in the result will also be full of 0s.
If a matrix has an inverse, it is said to be invertible or nonsingular. A matrix
that does not have an inverse is said to be noninvertible or singular. For any
invertible matrix
$\mathbf{M}$
, the vector equality
$\mathbf{v}\mathbf{M}=\mathbf{0}$
is true
only when
$\mathbf{v}=\mathbf{0}$
. Furthermore, the rows of an invertible matrix are linearly
independent, as are the columns. The rows (and columns) of a singular matrix are linearly
dependent.
The determinant of a singular matrix is zero and the determinant of a nonsingular matrix is
nonzero. Checking the magnitude of the determinant is the most commonly used test for
invertibility because it's the easiest and quickest. In ordinary circumstances, this is OK, but
please note that the method can break down. An example is an extreme shear matrix with basis
vectors that form a very long, thin parallelepiped with unit volume. This
ill conditioned
matrix is nearly singular, even though its determinant is 1. The condition number is the
proper tool for detecting such cases, but this is an advanced topic slightly beyond the scope of
this book.
There are several ways to compute the inverse of a matrix. The one we use is based on the
classical adjoint, which is the subject of the next section.
6.2.1The Classical Adjoint
Our method for computing the inverse of a matrix is based on the classical adjoint. The
classical adjoint of a matrix
$\mathbf{M}$
, denoted “
$\mathrm{a}\mathrm{d}\mathrm{j}\text{}\mathbf{M}$
,” is defined as the
transpose of the matrix of cofactors of
$\mathbf{M}$
.
Let's look at an example. Take the
$3\times 3$
matrix
$\mathbf{M}$
given earlier:
$$\mathbf{M}=\left[\begin{array}{ccc}4& 3& 3\\ 0& 2& 2\\ 1& 4& 1\end{array}\right].$$
First, we compute the cofactors of
$\mathbf{M}$
, as discussed in Section 6.1.2:
$$\begin{array}{rcclrcclrccl}{C}^{\{11\}}=+& \begin{array}{c}2\\ 4\end{array}& \begin{array}{c}2\\ 1\end{array}& \text{}=6,& {C}^{\{12\}}=& \begin{array}{c}0\\ 1\end{array}& \begin{array}{c}2\\ 1\end{array}& \text{}=2,& {C}^{\{13\}}=+& \begin{array}{c}0\\ 1\end{array}& \begin{array}{c}2\\ 4\end{array}& \text{}=2,\\ \\ {C}^{\{21\}}=& \begin{array}{c}3\\ 4\end{array}& \begin{array}{c}3\\ 1\end{array}& \text{}=9,& {C}^{\{22\}}=+& \begin{array}{c}4\\ 1\end{array}& \begin{array}{c}3\\ 1\end{array}& \text{}=1,& {C}^{\{23\}}=& \begin{array}{c}4\\ 1\end{array}& \begin{array}{c}3\\ 4\end{array}& \text{}=13,\\ \\ {C}^{\{31\}}=+& \begin{array}{c}3\\ 2\end{array}& \begin{array}{c}3\\ 2\end{array}& \text{}=0,& {C}^{\{32\}}=& \begin{array}{c}4\\ 0\end{array}& \begin{array}{c}3\\ 2\end{array}& \text{}=8,& {C}^{\{33\}}=+& \begin{array}{c}4\\ 0\end{array}& \begin{array}{c}3\\ 2\end{array}& \text{}=8.\end{array}$$
The classical adjoint of
$\mathbf{M}$
is the transpose of the matrix of cofactors:
The classical adjoint
$$\begin{array}{rl}\text{(6.6)}& \mathrm{a}\mathrm{d}\mathrm{j}\text{}\mathbf{M}& ={\left[\begin{array}{ccc}{C}^{\{11\}}& {C}^{\{12\}}& {C}^{\{13\}}\\ {C}^{\{21\}}& {C}^{\{22\}}& {C}^{\{23\}}\\ {C}^{\{31\}}& {C}^{\{32\}}& {C}^{\{33\}}\end{array}\right]}^{\mathrm{T}}& ={\left[\begin{array}{ccc}6& 2& 2\\ 9& 1& 13\\ 0& 8& 8\end{array}\right]}^{\mathrm{T}}=\left[\begin{array}{ccc}6& 9& 0\\ 2& 1& 8\\ 2& 13& 8\end{array}\right].\end{array}$$
6.2.2Matrix Inverse—Official Linear Algebra Rules
To compute the inverse of a matrix, we divide the classical adjoint by the determinant:
Computing matrix inverse from classical adjoint and determinant
$$\begin{array}{}\text{(6.2.2)}& {\mathbf{M}}^{1}=\frac{\mathrm{a}\mathrm{d}\mathrm{j}\text{}\mathbf{M}}{\left\mathbf{M}\right}.\end{array}$$
If the determinant is zero, the division is undefined, which jives with our earlier statement
that matrices with a zero determinant are noninvertible.
Let's look at an example. In the previous section we calculated the classical adjoint of a
matrix
$\mathbf{M}$
; now let's calculate its inverse:
$$\begin{array}{rl}\mathbf{M}& =\left[\begin{array}{ccc}4& 3& 3\\ 0& 2& 2\\ 1& 4& 1\end{array}\right];\\ {\mathbf{M}}^{1}& =\frac{\mathrm{a}\mathrm{d}\mathrm{j}\text{}\mathbf{M}}{\left\mathbf{M}\right}=\frac{1}{24}\left[\begin{array}{ccc}6& 9& 0\\ 2& 1& 8\\ 2& 13& 8\end{array}\right]=\left[\begin{array}{ccc}1/4& 3/8& 0\\ 1/12& 1/24& 1/3\\ 1/12& 13/24& 1/3\end{array}\right].\end{array}$$
Here the value of
$\mathrm{a}\mathrm{d}\mathrm{j}\text{}\mathbf{M}$
comes from Equation (6.6), and
$\left\mathbf{M}\right$
is from Equation (6.3).
There are other techniques that can be used to compute the inverse of a matrix, such as
Gaussian elimination. Many linear algebra textbooks assert that such techniques are better
suited for implementation on a computer because they require fewer arithmetic operations, and
this assertion is true for larger matrices and matrices with a structure that may be exploited.
However, for arbitrary matrices of smaller order, such as the
$2\times 2$
,
$3\times 3$
, and
$4\times 4$
matrices encountered most often in geometric applications, the classical adjoint
method is generally the method of choice. The reason is that the classical adjoint method
provides for a branchless implementation, meaning there are no if statements, or
loops that cannot be unrolled statically. On today's superscalar architectures and dedicated
vector processors, this is a big win.
We close this section with a quick list of several important properties concerning matrix
inverses.

The inverse of the inverse of a matrix is the original matrix:
$$({\mathbf{M}}^{1}{)}^{1}=\mathbf{M}.$$
(Of course, this assumes that
$\mathbf{M}$
is nonsingular.)

The identity matrix is its own inverse:
$${\mathbf{I}}^{1}=\mathbf{I}.$$
Note that there are other matrices that are their own inverse. For example, consider any
reflection matrix, or a matrix that rotates
$180{}^{\mathrm{o}}$
about any axis.

The inverse of the transpose of a matrix is the transpose of
the inverse of the matrix:
$$({\mathbf{M}}^{\mathrm{T}}{)}^{1}=({\mathbf{M}}^{1}{)}^{\mathrm{T}}$$

The inverse of a matrix product is equal to the product of the inverses of the matrices,
taken in reverse order:
$$(\mathbf{A}\mathbf{B}{)}^{1}={\mathbf{B}}^{1}{\mathbf{A}}^{1}.$$
This extends to more than two matrices:
$${({\mathbf{M}}_{1}{\mathbf{M}}_{2}\cdots {\mathbf{M}}_{n1}{\mathbf{M}}_{n})}^{1}={{\mathbf{M}}_{n}}^{1}{{\mathbf{M}}_{n1}}^{1}\cdots {{\mathbf{M}}_{2}}^{1}{{\mathbf{M}}_{1}}^{1}.$$

The determinant of the inverse is the reciprocal of the determinant of the original matrix:
$$\left{\mathbf{M}}^{1}\right=1/\left\mathbf{M}\right.$$
6.2.3Matrix Inverse—Geometric Interpretation
The inverse of a matrix is useful geometrically because it allows us to compute the “reverse”
or “opposite” of a transformation—a transformation that “undoes” another transformation if
they are performed in sequence. So, if we take a vector, transform it by a matrix
$\mathbf{M}$
,
and then transform it by the inverse
${\mathbf{M}}^{1}$
, then we will get the original vector
back. We can easily verify this algebraically:
$$(\mathbf{v}\mathbf{M}){\mathbf{M}}^{1}=\mathbf{v}(\mathbf{M}{\mathbf{M}}^{1})=\mathbf{v}\mathbf{I}=\mathbf{v}.$$
6.3Orthogonal Matrices
Previously we made reference to a special class of square matrices known as orthogonal
matrices. This section investigates orthogonal matrices a bit more closely. As usual, we first
introduce some pure math (Section 6.3.1), and then give some geometric
interpretations (Section 6.3.2). Finally, we discuss how to adjust
an arbitrary matrix to make it orthogonal (Section 6.3.3).
6.3.1Orthogonal Matrices—Official Linear Algebra Rules
A square matrix
$\mathbf{M}$
is orthogonal if and only if the product of the matrix and its transpose is the identity
matrix:
Definition of orthogonal matrix
$$\begin{array}{}\text{(6.7)}& \mathbf{M}\text{}\mathrm{i}\mathrm{s}\text{}\mathrm{o}\mathrm{r}\mathrm{t}\mathrm{h}\mathrm{o}\mathrm{g}\mathrm{o}\mathrm{n}\mathrm{a}\mathrm{l}\phantom{\rule{.2in}{0ex}}\u27fa\phantom{\rule{.2in}{0ex}}\mathbf{M}{\mathbf{M}}^{\mathrm{T}}=\mathbf{I}.\end{array}$$
Recall from Section 6.2.2 that, by definition, a matrix times its inverse is the
identity matrix (
$\mathbf{M}{\mathbf{M}}^{1}=\mathbf{I}$
). Thus, if a matrix is orthogonal, its
transpose and inverse are equal:
Equivalent definition of orthogonal matrix
$$\begin{array}{}\text{(6.3.1)}& \mathbf{M}\text{}\mathrm{i}\mathrm{s}\text{}\mathrm{o}\mathrm{r}\mathrm{t}\mathrm{h}\mathrm{o}\mathrm{g}\mathrm{o}\mathrm{n}\mathrm{a}\mathrm{l}\phantom{\rule{.2in}{0ex}}\u27fa\phantom{\rule{.2in}{0ex}}{\mathbf{M}}^{\mathrm{T}}={\mathbf{M}}^{1}.\end{array}$$
This is extremely powerful information, because the inverse of a matrix is often needed, and
orthogonal matrices arise frequently in practice in 3D graphics. For example, as mentioned
in Section 5.7.5, rotation and reflection matrices
are orthogonal. If we know that our matrix is orthogonal, we can essentially avoid computing the
inverse, which is a relatively costly computation.
6.3.2Orthogonal Matrices—Geometric Interpretation
Orthogonal matrices are interesting to us primarily because their inverse is trivial to compute.
But how do we know if a matrix is orthogonal in order to exploit its structure?
In many cases, we may have information about the way the matrix was constructed and therefore
know a priori that the matrix contains only rotation and/or reflection. This is a very
common situation, and it's very important to take advantage of this when using matrices to
describe rotation. We return to this topic in Section 8.2.1.
But what if we don't know anything in advance about the matrix? In other words, how can we tell
if an arbitrary matrix
$\mathbf{M}$
is orthogonal? Let's look at the
$3\times 3$
case, which is
the most interesting one for our purposes. The conclusions we draw in this section can be
extended to matrices of any dimension.
Let
$\mathbf{M}$
be an orthogonal
$3\times 3$
matrix. Expanding the definition of orthogonality
given by Equation (6.7), we have
$$\begin{array}{rl}\phantom{\rule{9pc}{0ex}}\mathbf{M}\phantom{XXXXXXXXX}{\mathbf{M}}^{\mathrm{T}}\phantom{XXXX}& =\phantom{\rule{2pc}{0ex}}\mathbf{I},\phantom{xxxxxxxxxxxxxxxxxxxxx}\\ \left[\begin{array}{ccc}{m}_{11}& {m}_{12}& {m}_{13}\\ {m}_{21}& {m}_{22}& {m}_{23}\\ {m}_{31}& {m}_{32}& {m}_{33}\end{array}\right]\left[\begin{array}{ccc}{m}_{11}& {m}_{21}& {m}_{31}\\ {m}_{12}& {m}_{22}& {m}_{32}\\ {m}_{13}& {m}_{23}& {m}_{33}\end{array}\right]& =\left[\begin{array}{ccc}1& 0& 0\\ 0& 1& 0\\ 0& 0& 1\end{array}\right].\end{array}$$
This gives us nine equations, all of which must be true for
$\mathbf{M}$
to be orthogonal:
Conditions satisfied by an orthogonal matrix
$$\begin{array}{rl}\text{(6.8)}& {m}_{11}{m}_{11}+{m}_{12}{m}_{12}+{m}_{13}{m}_{13}& =1,{m}_{11}{m}_{21}+{m}_{12}{m}_{22}+{m}_{13}{m}_{23}& =0,\\ {m}_{11}{m}_{31}+{m}_{12}{m}_{32}+{m}_{13}{m}_{33}& =0,\\ {m}_{21}{m}_{11}+{m}_{22}{m}_{12}+{m}_{23}{m}_{13}& =0,\\ \text{(6.9)}& {m}_{21}{m}_{21}+{m}_{22}{m}_{22}+{m}_{23}{m}_{23}& =1,{m}_{21}{m}_{31}+{m}_{22}{m}_{32}+{m}_{23}{m}_{33}& =0,\\ {m}_{31}{m}_{11}+{m}_{32}{m}_{12}+{m}_{33}{m}_{13}& =0,\\ {m}_{31}{m}_{21}+{m}_{32}{m}_{22}+{m}_{33}{m}_{23}& =0,\\ \text{(6.10)}& {m}_{31}{m}_{31}+{m}_{32}{m}_{32}+{m}_{33}{m}_{33}& =1.\end{array}$$
Let the vectors
${\mathbf{r}}_{1}$
,
${\mathbf{r}}_{2}$
, and
${\mathbf{r}}_{3}$
stand for the rows of
$\mathbf{M}$
:
$$\begin{array}{rl}{\mathbf{r}}_{1}& =\left[\begin{array}{ccc}{m}_{11}& {m}_{12}& {m}_{13}\end{array}\right],\\ {\mathbf{r}}_{2}& =\left[\begin{array}{ccc}{m}_{21}& {m}_{22}& {m}_{23}\end{array}\right],\\ {\mathbf{r}}_{3}& =\left[\begin{array}{ccc}{m}_{31}& {m}_{32}& {m}_{33}\end{array}\right],\\ \mathbf{M}& =\left[\begin{array}{c}{\mathbf{r}}_{1}\\ {\mathbf{r}}_{2}\\ {\mathbf{r}}_{3}\end{array}\right].\end{array}$$
Now we can rewrite the nine equations more compactly:
Conditions satisfied by an orthogonal matrix
$$\begin{array}{rlrlrl}{\mathbf{r}}_{1}\cdot {\mathbf{r}}_{1}& =1,& {\mathbf{r}}_{1}\cdot {\mathbf{r}}_{2}& =0,& {\mathbf{r}}_{1}\cdot {\mathbf{r}}_{3}& =0,\\ {\mathbf{r}}_{2}\cdot {\mathbf{r}}_{1}& =0,& {\mathbf{r}}_{2}\cdot {\mathbf{r}}_{2}& =1,& {\mathbf{r}}_{2}\cdot {\mathbf{r}}_{3}& =0,\\ {\mathbf{r}}_{3}\cdot {\mathbf{r}}_{1}& =0,& {\mathbf{r}}_{3}\cdot {\mathbf{r}}_{2}& =0,& {\mathbf{r}}_{3}\cdot {\mathbf{r}}_{3}& =1.\end{array}$$
This notational changes makes it easier for us to make some interpretations.

First, the dot product of a vector with itself is 1 if
and only if the vector is a unit vector. Therefore, the equations
with a 1 on the righthand side of the equals sign
(Equations (6.8),
(6.9),
and (6.10))
will be true only when
${\mathbf{r}}_{1}$
,
${\mathbf{r}}_{2}$
,
and
${\mathbf{r}}_{3}$
are unit vectors.

Second, recall from Section 2.11.2
that the dot product of two vectors is 0 if and only if they are
perpendicular. Therefore, the other six equations (with 0 on the
righthand side of the equals sign) are true when
${\mathbf{r}}_{1}$
,
${\mathbf{r}}_{2}$
, and
${\mathbf{r}}_{3}$
are mutually perpendicular.
So, for a matrix to be orthogonal, the following must be true:

Each row of the matrix must be a unit vector.

The rows of the matrix must be mutually perpendicular.
Similar statements can be made regarding the columns of the matrix, since if
$\mathbf{M}$
is orthogonal, then
${\mathbf{M}}^{\mathrm{T}}$
must be orthogonal as well.
Notice that these criteria are precisely those that we said in
Section 3.3.3 were satisfied by an orthonormal set of basis
vectors. In that section, we also noted that an orthonormal basis was particularly useful
because we could perform, by using the dot product, the “opposite” coordinate transform from
the one that is always available. When we say that the transpose of an orthogonal matrix is
equal to its inverse, we are just restating this fact in the formal language of linear algebra.
Also notice that three of the orthogonality equations are duplicates, because the dot product is
commutative. Thus, these nine equations actually express only six constraints. In an arbitrary
$3\times 3$
matrix there are nine elements and thus nine degrees of freedom, but in an
orthogonal matrix, six degrees of freedom are removed by the constraints, leaving three degrees
of freedom. It is significant that three is also the number of degrees of freedom inherent in 3D
rotation. (However, rotation matrices cannot contain a reflection, so there is “slightly more
freedom” in the set of orthogonal matrices than in the set of orientations in 3D.)
When computing a matrix inverse, we will usually only take advantage of orthogonality if we know
a priori that a matrix is orthogonal. If we don't know in advance, it's probably a waste
of time to check. In the best case, we check for orthogonality and find that the matrix is
indeed orthogonal, and then we transpose the matrix. But this may take almost as much time as
doing the inversion. In the worst case, the matrix is not orthogonal, and any time we spent
checking was definitely wasted. Finally, even matrices that are orthogonal in the abstract may
not be exactly orthogonal when represented in floating point, and so we must use tolerances,
which have to be tuned.
One important note is needed here on terminology that can be slightly confusing. In linear algebra, we
describe a set of basis vectors as orthogonal if they are mutually perpendicular. It is
not required that they have unit length. If they do have unit length, they are an
orthonormal basis. Thus the rows and columns of an orthogonal matrix are
orthonormal basis vectors. However, constructing a matrix from a set of orthogonal basis
vectors does not necessarily result in an orthogonal matrix (unless the basis vectors are also
orthonormal).
6.3.3Orthogonalizing a Matrix
It is sometimes the case that we encounter a matrix that is slightly out of orthogonality. We
may have acquired bad data from an external source, or we may have accumulated floating point
error (which is called matrix creep). For basis vectors used for bump mapping (see
Section 10.9), we will often adjust the basis to be orthogonal, even if
the texture mapping gradients aren't quite perpendicular. In these situations, we would like to
orthogonalize the matrix, resulting in a matrix that has mutually perpendicular unit
vector axes and is (hopefully) as close to the original matrix as possible.
The standard algorithm for constructing a set of orthogonal basis vectors (which is what the rows
of an orthogonal matrix are) is GramSchmidt orthogonalization. The basic idea is to go
through the basis vectors in order. For each basis vector, we subtract off the portion of that
vector that is parallel to the proceeding basis vectors, which must result in a perpendicular
vector.
Let's look at the
$3\times 3$
case as an example. As before, let
${\mathbf{r}}_{1}$
,
${\mathbf{r}}_{2}$
, and
${\mathbf{r}}_{3}$
stand for the
rows of a
$3\times 3$
matrix
$\mathbf{M}$
. (Remember, you can
also think of these as the
$x$
,
$y$
, and
$z$
axes of a coordinate
space.) Then an orthogonal set of row vectors,
${\mathbf{r}}_{1}^{\prime}$
,
${\mathbf{r}}_{2}^{\prime}$
, and
${\mathbf{r}}_{3}^{\prime}$
, can be computed according to
the following algorithm:
GramSchmidt orthogonalization of 3D basis vectors
$$\begin{array}{rl}{\mathbf{r}}_{1}^{\prime}& \Leftarrow {\mathbf{r}}_{1},\\ {\mathbf{r}}_{2}^{\prime}& \Leftarrow {\mathbf{r}}_{2}\frac{{\mathbf{r}}_{2}\cdot {\mathbf{r}}_{1}^{\prime}}{{\mathbf{r}}_{1}^{\prime}\cdot {\mathbf{r}}_{1}^{\prime}}{\mathbf{r}}_{1}^{\prime},\\ {\mathbf{r}}_{3}^{\prime}& \Leftarrow {\mathbf{r}}_{3}\frac{{\mathbf{r}}_{3}\cdot {\mathbf{r}}_{1}^{\prime}}{{\mathbf{r}}_{1}^{\prime}\cdot {\mathbf{r}}_{1}^{\prime}}{\mathbf{r}}_{1}^{\prime}\frac{{\mathbf{r}}_{3}\cdot {\mathbf{r}}_{2}^{\prime}}{{\mathbf{r}}_{2}^{\prime}\cdot {\mathbf{r}}_{2}^{\prime}}{\mathbf{r}}_{2}^{\prime}.\end{array}$$
After applying these steps, the vectors
${\mathbf{r}}_{1}$
,
${\mathbf{r}}_{2}$
, and
${\mathbf{r}}_{3}$
are
guaranteed to be mutually perpendicular, and thus will form an orthogonal basis. However, they
may not necessarily be unit vectors. We need an orthonormal basis to form an orthogonal matrix,
and so we must normalize the vectors. (Again, the terminology can be confusing, see the note at
the end of the previous section.) Notice that if we normalize the vectors as we go, rather than
in a second pass, then we can avoid all of the divisions. Also, a trick that works in 3D (but
not in higher dimensions) is to compute the third basis vector using the cross product:
$${\mathbf{r}}_{3}^{\prime}\Leftarrow {\mathbf{r}}_{1}^{\prime}\times {\mathbf{r}}_{2}^{\prime}.$$
The GramSchmidt algorithm is biased, depending on the order in which the basis vectors are
listed. For instance,
${\mathbf{r}}_{1}$
never changes, and
${\mathbf{r}}_{3}$
is likely to change the
most. A variation on the algorithm that is not biased towards any particular axis is to abandon
the attempt to completely orthogonalize the entire matrix in one pass. We select some fraction
$k$
, and instead of subtracting off all of the projection, we subtract off only
$k$
of it. We
also subtract the projection onto the original axis, not the adjusted one. In this way, the
order in which we perform the operations does not matter and we have no dimensional bias. This
algorithm is summarized by
Nonbiased incremental orthogonalization algorithm
$$\begin{array}{rl}{\mathbf{r}}_{1}^{\prime}& \Leftarrow {\mathbf{r}}_{1}k\frac{{\mathbf{r}}_{1}\cdot {\mathbf{r}}_{2}}{{\mathbf{r}}_{2}\cdot {\mathbf{r}}_{2}}{\mathbf{r}}_{2}k\frac{{\mathbf{r}}_{1}\cdot {\mathbf{r}}_{3}}{{\mathbf{r}}_{3}\cdot {\mathbf{r}}_{3}}{\mathbf{r}}_{3},\\ {\mathbf{r}}_{2}^{\prime}& \Leftarrow {\mathbf{r}}_{2}k\frac{{\mathbf{r}}_{2}\cdot {\mathbf{r}}_{1}}{{\mathbf{r}}_{1}\cdot {\mathbf{r}}_{1}}{\mathbf{r}}_{1}k\frac{{\mathbf{r}}_{2}\cdot {\mathbf{r}}_{3}}{{\mathbf{r}}_{3}\cdot {\mathbf{r}}_{3}}{\mathbf{r}}_{3},\\ {\mathbf{r}}_{3}^{\prime}& \Leftarrow {\mathbf{r}}_{3}k\frac{{\mathbf{r}}_{3}\cdot {\mathbf{r}}_{1}}{{\mathbf{r}}_{1}\cdot {\mathbf{r}}_{1}}{\mathbf{r}}_{1}k\frac{{\mathbf{r}}_{3}\cdot {\mathbf{r}}_{2}}{{\mathbf{r}}_{2}\cdot {\mathbf{r}}_{2}}{\mathbf{r}}_{2}.\end{array}$$
One iteration of this algorithm results in a set of basis vectors
that are slightly “more orthogonal” than the original vectors, but
possibly not completely orthogonal. By repeating this procedure
multiple times, we can eventually converge on an orthogonal basis.
Selecting an appropriately small value for
$k$
(say,
$1/4$
) and
iterating a sufficient number of times (say, ten) gets us fairly
close. Then, we can use the standard GramSchmidt algorithm to
guarantee a perfectly orthogonal basis.
6.4
$\mathbf{4}\mathbf{\times}\mathbf{4}$
Homogeneous Matrices
Up until now, we have used only 2D and 3D vectors. In this
section, we introduce 4D vectors and the socalled “homogeneous” coordinate. There is nothing
magical about 4D vectors and matrices (and no, the fourth coordinate in this case isn't
“time”). As we will see, 4D vectors and
$4\times 4$
matrices are nothing more than a
notational convenience for what are simple 3D operations.
This section introduces 4D homogeneous space and
$4\times 4$
transformation matrices and their
application to affine 3D geometry. Section 6.4.1 discusses the nature of 4D
homogeneous space and how it is related to physical 3D space.
Section 6.4.2 explains how
$4\times 4$
transformation matrices can be
used to express translations. Section 6.4.3 explains how
$4\times 4$
transformation matrices can be used to express affine transformations.
6.4.14D Homogeneous Space
As was mentioned in Section 2.1, 4D vectors have four components, with
the first three components being the standard
$x$
,
$y$
, and
$z$
components. The fourth component
in a 4D vector is
$w$
, sometimes referred to as the homogeneous coordinate.
To understand how the standard physical 3D space is extended into 4D, let's first examine
homogeneous coordinates in 2D, which are of the form
$(x,y,w)$
. Imagine the standard 2D plane
as existing in 3D at the plane
$w=1$
, such that physical 2D point
$(x,y)$
is represented in
homogeneous space
$(x,y,1)$
. For all points that are not in the plane
$w=1$
, we can compute
the corresponding 2D point by projecting the point onto the plane
$w=1$
, by dividing by
$w$
. So
the homogeneous coordinate
$(x,y,w)$
is mapped to the physical 2D point
$(x/w,y/w)$
. This is
shown inFigure 6.2.
For any given physical 2D point
$(x,y)$
there are an infinite number of corresponding points in
homogeneous space, all of the form
$(kx,ky,k)$
, provided that
$k\ne 0$
. These points form a
line through the (homogeneous) origin.
When
$w=0$
, the division is undefined and there is no corresponding physical point in 2D space.
However, we can interpret a 2D homogeneous point of the form
$(x,y,0)$
as a “point at
infinity,” which defines a direction rather than a location. When we make the
conceptual distinction between “points” and “vectors” (see
Section 2.4), then the “locations” where
$w\ne 0$
are “points“
and the “directions” with
$w=0$
are are “vectors.” There is more on this in the next section.
The same basic idea applies when extending physical 3D space to 4D homogeneous space (although
it's a lot harder to visualize). The physical 3D points can be thought of as living in the
hyperplane in 4D at
$w=1$
. A 4D point is of the form
$(x,y,z,w)$
, and we project a 4D point
onto this hyperplane to yield the corresponding physical 3D point
$(x/w,y/w,z/w)$
. When
$w=0$
, the 4D point represents a “point at infinity,” which defines a direction rather than a
location.
Homogeneous coordinates and projection by division by
$w$
are interesting, but why on earth would
we want to use 4D space? There are two primary reasons for using 4D vectors and
$4\times 4$
matrices. The first reason, which we discuss in the next section, is actually nothing more than
a notational convenience. The second reason is that if we put the proper value into
$w$
, the
homogenous division will result in a perspective projection, as we discuss in
Section 6.5.
6.4.2
$\mathbf{4}\mathbf{\times}\mathbf{4}$
Translation Matrices
Recall from Section 4.2 that a
$3\times 3$
transformation
matrix represents a linear transformation, which does not contain translation. Due to the
nature of matrix multiplication, the zero vector is always transformed into the zero vector, and
therefore any transformation that can be represented by a matrix multiplication cannot contain
translation. This is unfortunate, because matrix multiplication and inversion are very
convenient tools for composing complicated transformations out of simple ones and manipulating
nested coordinate space relationships. It would be nice if we could find a way to somehow extend
the standard
$3\times 3$
transformation matrix to be able to handle transformations with
translation;
$4\times 4$
matrices provide a mathematical “kludge” that allows us to do this.
Assume for the moment that
$w$
is always 1. Thus, the standard 3D vector
$[x,y,z]$
will always
be represented in 4D as
$[x,y,z,1]$
. Any
$3\times 3$
transformation matrix can by represented
in 4D by using the conversion
Extending a
$\mathbf{3}\mathbf{\times}\mathbf{3}$
transform matrix into 4D
$$\left[\begin{array}{ccc}{m}_{11}& {m}_{12}& {m}_{13}\\ {m}_{21}& {m}_{22}& {m}_{23}\\ {m}_{31}& {m}_{32}& {m}_{33}\end{array}\right]\u27f9\left[\begin{array}{cccc}{m}_{11}& {m}_{12}& {m}_{13}& 0\\ {m}_{21}& {m}_{22}& {m}_{23}& 0\\ {m}_{31}& {m}_{32}& {m}_{33}& 0\\ 0& 0& 0& 1\end{array}\right].$$
When we multiply a 4D vector of the form
$[x,y,z,1]$
by a
$4\times 4$
matrix of this form, we
get the same result as the standard
$3\times 3$
case, the only difference being the additional
coordinate
$w=1$
:
$$\begin{array}{r}{\displaystyle \left[\begin{array}{ccc}x& y& z\end{array}\right]\left[\begin{array}{ccc}{m}_{11}& {m}_{12}& {m}_{13}\\ {m}_{21}& {m}_{22}& {m}_{23}\\ {m}_{31}& {m}_{32}& {m}_{33}\end{array}\right]}\\ & =\left[\begin{array}{ccc}x{m}_{11}+y{m}_{21}+z{m}_{31}& x{m}_{12}+y{m}_{22}+z{m}_{32}& x{m}_{13}+y{m}_{23}+z{m}_{33}\end{array}\right];\\ {\displaystyle \left[\begin{array}{cccc}x& y& z& 1\end{array}\right]\left[\begin{array}{cccc}{m}_{11}& {m}_{12}& {m}_{13}& 0\\ {m}_{21}& {m}_{22}& {m}_{23}& 0\\ {m}_{31}& {m}_{32}& {m}_{33}& 0\\ 0& 0& 0& 1\end{array}\right]}\\ & =\left[\begin{array}{cccc}x{m}_{11}+y{m}_{21}+z{m}_{31}& x{m}_{12}+y{m}_{22}+z{m}_{32}& x{m}_{13}+y{m}_{23}+z{m}_{33}& 1\end{array}\right].\end{array}$$
Now for the interesting part. In 4D, we can also express translation as a matrix multiplication,
something we were not able to do in 3D:
Using a
$\mathbf{4}\mathbf{\times}\mathbf{4}$
matrix to perform translation in 3D
$$\begin{array}{}\text{(6.11)}& \left[\begin{array}{cccc}x& y& z& 1\end{array}\right]\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ \mathrm{\Delta}x& \mathrm{\Delta}y& \mathrm{\Delta}z& 1\end{array}\right]=\left[\begin{array}{cccc}x+\mathrm{\Delta}x& y+\mathrm{\Delta}y& z+\mathrm{\Delta}z& 1\end{array}\right].\end{array}$$
It is important to understand that this matrix multiplication is still a linear
transformation. Matrix multiplication cannot represent “translation” in 4D, and the 4D zero
vector will always be transformed back into the 4D zero vector. The reason this trick works to
transform points in 3D is that we are actually shearing 4D space. (Compare
Equation (6.11) with the shear matrices from
Section 5.5.) The 4D hyperplane that corresponds to physical 3D
space does not pass through the origin in 4D. Thus, when we shear 4D space, we are able to
translate in 3D.
Let's examine what happens when we perform a transformation without translation followed by a
transformation with only translation. Let
$\mathbf{R}$
be a rotation matrix. (In fact,
$\mathbf{R}$
could possibly contain other 3D linear transformations, but for now, let's assume
$\mathbf{R}$
only contains rotation.) Let
$\mathbf{T}$
be a translation matrix of the form in
Equation (6.11):
$$\begin{array}{rlrl}\mathbf{R}& =\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& 0\\ {r}_{21}& {r}_{22}& {r}_{23}& 0\\ {r}_{31}& {r}_{32}& {r}_{33}& 0\\ 0& 0& 0& 1\end{array}\right],& \mathbf{T}& =\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ \mathrm{\Delta}x& \mathrm{\Delta}y& \mathrm{\Delta}z& 1\end{array}\right].\end{array}$$
Then we could rotate and then translate a point
$\mathbf{v}$
to compute a new point
${\mathbf{v}}^{\prime}$
by
$${\mathbf{v}}^{\prime}=\mathbf{v}\mathbf{R}\mathbf{T}.$$
Remember that the order of transformations is important, and since
we have chosen to use row vectors, the order of transformations
coincides with the order that the matrices are multiplied, from left
to right. We are rotating first and then translating.
Just as with
$3\times 3$
matrices, we can concatenate the two matrices into a single
transformation matrix, which we assign to the matrix
$\mathbf{M}$
:
$$\begin{array}{rl}\mathbf{M}& =\mathbf{R}\mathbf{T},\\ {\mathbf{v}}^{\prime}& =\mathbf{v}\mathbf{R}\mathbf{T}=\mathbf{v}(\mathbf{R}\mathbf{T})=\mathbf{v}\mathbf{M}.\end{array}$$
Let's now examine the contents of
$\mathbf{M}$
:
$$\begin{array}{rl}\mathbf{M}=\mathbf{R}\mathbf{T}& =\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& 0\\ {r}_{21}& {r}_{22}& {r}_{23}& 0\\ {r}_{31}& {r}_{32}& {r}_{33}& 0\\ 0& 0& 0& 1\end{array}\right]\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ \mathrm{\Delta}x& \mathrm{\Delta}y& \mathrm{\Delta}z& 1\end{array}\right]\\ & =\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& 0\\ {r}_{21}& {r}_{22}& {r}_{23}& 0\\ {r}_{31}& {r}_{32}& {r}_{33}& 0\\ \mathrm{\Delta}x& \mathrm{\Delta}y& \mathrm{\Delta}z& 1\end{array}\right].\end{array}$$
Notice that the upper
$3\times 3$
portion of
$\mathbf{M}$
contains the rotation portion, and the bottom row contains the
translation portion. The rightmost column (for now) will be
$[0,0,0,1{]}^{\mathrm{T}}$
.
Applying this information in reverse, we can take any
$4\times 4$
matrix and separate it into
a linear transformation portion, and a translation portion. We can express this succinctly with
block matrix notation, by assigning the translation vector
$[\mathrm{\Delta}x,\mathrm{\Delta}y,\mathrm{\Delta}z]$
to
the vector
$\mathbf{t}$
:
$$\mathbf{M}=\left[\begin{array}{cc}\mathbf{R}& \mathbf{0}\\ \mathbf{t}& 1\end{array}\right].$$
For the moment, we are assuming that the rightmost column of
a
$4\times 4$
transformation matrix is always
$[0,0,0,1{]}^{\mathrm{T}}$
. We will begin to encounter situations
where this is not be the case in
Section 6.5.
Let's see what happens with the socalled “points at infinity” (those vectors with
$w=0$
).
Multiplying by a “standard”
$3\times 3$
linear transformation matrix extended into 4D (a
transformation that does not contain translation), we get
Multiplying a “point at infinity” by a
$\mathbf{4}\mathbf{\times}\mathbf{4}$
matrix without
translation
$$\begin{array}{c}{\displaystyle \left[\begin{array}{cccc}x& y& z& 0\end{array}\right]\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& 0\\ {r}_{21}& {r}_{22}& {r}_{23}& 0\\ {r}_{31}& {r}_{32}& {r}_{33}& 0\\ 0& 0& 0& 1\end{array}\right]}\hfill \\ \hfill =\left[\begin{array}{cccc}x{r}_{11}+y{r}_{21}+z{r}_{31}& x{r}_{12}+y{r}_{22}+z{r}_{32}& x{r}_{13}+y{r}_{23}+z{r}_{33}& 0\end{array}\right].\end{array}$$
In other words, when we transform a pointatinfinity vector of the form
$[x,y,z,0]$
by a
transformation matrix containing rotation, scale, etc., the expected transformation occurs, and
the result is another pointatinfinity vector of the form
$[{x}^{\prime},{y}^{\prime},{z}^{\prime},0]$
.
When we transform a pointatinfinity vector by a transformation that does contain
translation, we get the following result:
Multiplying a “point at infinity” by a
$\mathbf{4}\mathbf{\times}\mathbf{4}$
matrix with translation
$$\begin{array}{c}{\displaystyle \left[\begin{array}{cccc}x& y& z& 0\end{array}\right]\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& 0\\ {r}_{21}& {r}_{22}& {r}_{23}& 0\\ {r}_{31}& {r}_{32}& {r}_{33}& 0\\ \mathrm{\Delta}x& \mathrm{\Delta}y& \mathrm{\Delta}z& 1\end{array}\right]}\hfill \\ \hfill =\left[\begin{array}{cccc}x{r}_{11}+y{r}_{21}+z{r}_{31}& x{r}_{12}+y{r}_{22}+z{r}_{32}& x{r}_{13}+y{r}_{23}+z{r}_{33}& 0\end{array}\right].\end{array}$$
Notice that the result is the same—that is, no translation occurs.
In other words, the
$w$
component of a 4D vector can be used to selectively “switch off” the
translation portion of a
$4\times 4$
matrix. This is useful because some vectors represent
“locations” and should be translated, and other vectors represent “directions,” such as
surface normals, and should not be translated. In a geometric sense, we can think of the first
type of data, with
$w=1$
, as “points,” and the second type of data, the “points at infinity”
with
$w=0$
, as “vectors.”
So, one reason why
$4\times 4$
matrices are useful is that a
$4\times 4$
transformation matrix
can contain translation. When we use
$4\times 4$
matrices solely for this purpose, the
rightmost column of the matrix will always be
$[0,0,0,1{]}^{\mathrm{T}}$
. Since this is the case, why
don't we just drop the column and use a
$4\times 3$
matrix? According to linear algebra rules,
$4\times 3$
matrices are undesirable for several reasons:

We cannot multiply a
$4\times 3$
matrix by another
$4\times 3$
matrix.

We cannot invert a
$4\times 3$
matrix, since the matrix
is not square.

When we multiply a 4D vector by a
$4\times 3$
matrix, the
result is a 3D vector.
Strict adherence to linear algebra rules forces us to add the fourth column. Of course, in our
code, we are not bound by linear algebra rules. It is a common technique to write a
$4\times 3$
matrix class that is useful for representing transformations that contain translation. Basically,
such a matrix is a
$4\times 4$
matrix, where the rightmost column is assumed to be
$[0,0,0,1{]}^{\mathrm{T}}$
and therefore isn't explicitly stored.
Chapter 5 presented
$3\times 3$
matrices for
many primitive transformations. Because a
$3\times 3$
matrix can represent only linear
transformations in 3D, translation was not considered. Armed with
$4\times 4$
transform
matrices, though, we can now create more general affine transformations that contain
translation, such as:

rotation about an axis that does not pass through the origin,

scale about a plane that does not pass through the origin,

reflection about a plane that does not pass through the origin, and

orthographic projection onto a plane that does not pass through
the origin.
The basic idea is to translate the “center” of the transformation to the origin, perform the
linear transformation by using the techniques developed in Chapter 5, and
then transform the center back to its original location. We start with a translation matrix
$\mathbf{T}$
that translates the point
$\mathbf{p}$
to the origin, and a linear transform matrix
$\mathbf{R}$
from Chapter 5 that performs the linear transformation. The
final affine transformation matrix
$\mathbf{A}$
will be equal to the matrix product
$\mathbf{T}\mathbf{R}({\mathbf{T}}^{1})$
, where
${\mathbf{T}}^{1}$
is the translation matrix with
the opposite translation amount as
$\mathbf{T}$
.
It is interesting to observe the general form of such a matrix. Let's first write
$\mathbf{T}$
,
$\mathbf{R}$
, and
${\mathbf{T}}^{1}$
in the partitioned form we used earlier:
$$\begin{array}{rl}\mathbf{T}& =\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ {p}_{x}& {p}_{y}& {p}_{z}& 1\end{array}\right]=\left[\begin{array}{cc}\mathbf{I}& \mathbf{0}\\ \mathbf{}\mathbf{p}& 1\end{array}\right];\\ {\mathbf{R}}_{4\times 4}& =\left[\begin{array}{cccc}{r}_{11}& {r}_{12}& {r}_{13}& 0\\ {r}_{21}& {r}_{22}& {r}_{23}& 0\\ {r}_{31}& {r}_{32}& {r}_{33}& 0\\ 0& 0& 0& 1\end{array}\right]=\left[\begin{array}{cc}{\mathbf{R}}_{3\times 3}& \mathbf{0}\\ \mathbf{0}& 1\end{array}\right];\\ {\mathbf{T}}^{1}& =\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 0\\ {p}_{x}& {p}_{y}& {p}_{z}& 1\end{array}\right]=\left[\begin{array}{cc}\mathbf{I}& 0\\ \mathbf{p}& 1\end{array}\right].\end{array}$$
Evaluating the matrix multiplication, we get
$$\mathbf{T}{\mathbf{R}}_{4\times 4}{\mathbf{T}}^{1}=\left[\begin{array}{cc}\mathbf{I}& \mathbf{0}\\ \mathbf{p}& 1\end{array}\right]\left[\begin{array}{cc}{\mathbf{R}}_{3\times 3}& \mathbf{0}\\ \mathbf{0}& 1\end{array}\right]\left[\begin{array}{cc}\mathbf{I}& \mathbf{0}\\ \mathbf{p}& 1\end{array}\right]=\left[\begin{array}{cc}{\mathbf{R}}_{3\times 3}& \mathbf{0}\\ \mathbf{p}\left({\mathbf{R}}_{3\times 3}\right)+\mathbf{p}& 1\end{array}\right].$$
Thus, the extra translation in an affine transformation changes only the last row of the
$4\times 4$
matrix. The upper
$3\times 3$
portion, which contains the linear transformation, is
not affected.
Our use of “homogeneous” coordinates so far has really been nothing more than a mathematical
kludge to allow us to include translation in our transformations. We use quotations around
“homogeneous” because the
$w$
value was always 1 (or 0, in the case of points at infinity). In
the next section, we will remove the quotations, and discuss meaningful ways to use 4D
coordinates with other
$w$
values.
6.5
$\mathbf{4}\mathbf{\times}\mathbf{4}$
Matrices and Perspective Projection
Section 6.4.1 showed that when we interpret
a 4D homogeneous vector in 3D, we divide by
$w$
. This division is a mathematical tool that we
did not really take advantage of in the previous section, since
$w$
was always 1 or 0. However,
if we play our cards right, we can use the division by
$w$
to encapsulate very succinctly the
important geometric operation of perspective projection.
We can learn a lot about perspective projection by comparing it to another type of projection we
have already discussed, orthographic projection.
Section 5.3 showed how to project 3D space onto a 2D
plane, known as the projection plane, by using orthographic projection. Orthographic
projection is also known as parallel projection, because the projectors are parallel. (A
projector is a line from the original point to the resulting projected point on the
plane). The parallel projectors used in orthographic projection are shown in
Figure 6.3.
Perspective projection in 3D also projects onto a 2D plane. However, the projectors are not
parallel. In fact, they intersect at a point, known as the center of projection. This is
shown in Figure 6.4.
Because the center of projection is in front of the projection plane, the projectors cross before
striking the plane, and thus the image is inverted. As we move an object farther away from the
center of projection, its orthographic projection remains constant, but the perspective
projection gets smaller, as illustrated in Figure 6.5. The teapot on
the right is further from the projection plane, and the projection is (slightly) smaller than the
closer teapot. This is a very important visual cue known as perspective foreshortening.
6.5.1A Pinhole Camera
Perspective projection is important in graphics because it models the way the human visual system
works. Actually, the human visual system is more complicated because we have two eyes, and for
each eye, the projection surface (our retina) is not flat; so let's look at the simpler example
of a pinhole camera. A pinhole camera is a box with a tiny hole on one end. Rays of light enter the pinhole (thus
converging at a point), and then strike the opposite end of the box, which is the projection
plane. This is shown in Figure 6.6.
In this view, the left and back sides of the box have been removed so you can see the inside.
Notice that the image projected onto the back of the box is inverted. This is because the rays
of light (the projectors) cross as they meet at the pinhole (the center of projection).
Let's examine the geometry behind the perspective projection of a pinhole camera. Consider a 3D
coordinate space with the origin at the pinhole, the
$z$
axis perpendicular to the projection
plane, and the
$x$
 and
$y$
axes parallel to the plane of projection, as shown in
Figure 6.7.
Let's see if we can't compute, for an arbitrary point
$\mathbf{p}$
, the 3D coordinates of
${\mathbf{p}}^{\prime}$
, which is
$\mathbf{p}$
projected through the pinhole onto the projection plane.
First, we need to know the distance from the pinhole to the projection plane. We assign this
distance to the variable
$d$
. Thus, the plane is defined by the equation
$z=d$
. Now let's
view things from the side and solve for
$y$
(see Figure 6.8).
By similar triangles, we can see that
$$\frac{{p}_{y}^{\prime}}{d}}={\displaystyle \frac{{p}_{y}}{z}}\text{}\text{}\text{}\u27f9\text{}\text{}\text{}{p}_{y}^{\prime}={\displaystyle \frac{d{p}_{y}}{z}}.$$
Notice that since a pinhole camera flips the image upside down, the signs of
${p}_{y}$
and
${p}_{y}^{\prime}$
are opposite. The value of
${p}_{x}^{\prime}$
is computed in a similar manner:
$${p}_{x}^{\prime}={\displaystyle \frac{d{p}_{x}}{z}}.$$
The
$z$
values of all the projected points are the same:
$d$
. Thus, the result of projecting a
point
$\mathbf{p}$
through the origin onto a plane at
$z=d$
is
Projecting onto the plane
$\mathit{z}\mathbf{=}\mathbf{}\mathit{d}$
$$\mathbf{p}=\left[\begin{array}{ccc}x& y& z\end{array}\right]\text{}\text{}\text{}\u27f9\text{}\text{}\text{}{\mathbf{p}}^{\prime}=\left[\begin{array}{ccc}{x}^{\prime}& {y}^{\prime}& {z}^{\prime}\end{array}\right]=\left[\begin{array}{ccc}dx/z& dy/z& d\end{array}\right].$$
In practice, the extra minus signs create unnecessary complexities, and so we move the plane of
projection to
$z=d$
, which is in front of the center of projection, as shown in
Figure 6.9. Of course, this would never work
for a real pinhole camera, since the purpose of the pinhole in the first place is to allow in
only light that passes through a single point. However, in the mathematical universe inside a
computer, it works just fine.
As expected, moving the plane of projection in front of the center of projection removes the
annoying minus signs:
Projecting a point onto the plane
$\mathit{z}\mathbf{=}\mathit{d}$
$$\begin{array}{}\text{(6.12)}& {\mathbf{p}}^{\prime}=\left[\begin{array}{ccc}{x}^{\prime}& {y}^{\prime}& {z}^{\prime}\end{array}\right]=\left[\begin{array}{ccc}dx/z& dy/z& d\end{array}\right].\end{array}$$
6.5.2Perspective Projection Matrices
Because the conversion from 4D to 3D space implies a division, we can encode a perspective
projection in a
$4\times 4$
matrix. The basic idea is to come up with an equation for
${\mathbf{p}}^{\prime}$
with a common denominator for
$x$
,
$y$
, and
$z$
, and then set up a
$4\times 4$
matrix that will set
$w$
equal to this denominator. We assume that the original points have
$w=1$
.
First, we manipulate Equation (6.12) to have a common denominator:
$${\mathbf{p}}^{\prime}=\left[\begin{array}{ccc}dx/z& dy/z& d\end{array}\right]=\left[\begin{array}{ccc}dx/z& dy/z& dz/z\end{array}\right]={\displaystyle \frac{\left[\begin{array}{ccc}x& y& z\end{array}\right]}{z/d}}.$$
To divide by this denominator, we put the denominator into
$w$
, so the 4D point will be of the
form
$$\left[\begin{array}{cccc}x& y& z& z/d\end{array}\right].$$
So we need a
$4\times 4$
matrix that multiplies a homogeneous vector
$[x,y,z,1]$
to produce
$[x,y,z,z/d]$
. The matrix that does this is
Projecting onto the plane
$\mathit{z}\mathbf{=}\mathit{d}$
using a
$\mathbf{4}\mathbf{\times}\mathbf{4}$
matrix
$$\left[\begin{array}{cccc}x& y& z& 1\end{array}\right]\left[\begin{array}{cccc}1& 0& 0& 0\\ 0& 1& 0& 0\\ 0& 0& 1& 1/d\\ 0& 0& 0& 0\end{array}\right]=\left[\begin{array}{cccc}x& y& z& z/d\end{array}\right].$$
Thus, we have derived a
$4\times 4$
projection matrix.
There are several important points to be made here:

Multiplication by this matrix doesn't actually perform the perspective
transform, it just computes the proper denominator into
$w$
. Remember
that the perspective division actually occurs when we convert from 4D
to 3D by dividing by
$w$
.

There are many variations. For example, we can place the plane of
projection at
$z=0$
, and the center of projection at
$[0,0,d]$
. This
results in a slightly different equation.

This seems overly complicated. It seems like it would be simpler to
just divide by
$z$
, rather than bothering with matrices. So why is
homogeneous space interesting? First,
$4\times 4$
matrices provide a
way to express projection as a transformation that can be concatenated
with other transformations. Second, projection onto nonaxially aligned
planes is possible. Basically, we don't need homogeneous
coordinates, but
$4\times 4$
matrices provide a compact way to represent
and manipulate projection transformations.

The projection matrix in a real graphics geometry pipeline
(perhaps more accurately known as the “clip matrix”) does more than
just copy
$z$
into
$w$
. It differs from the one we derived
in two important respects:

Most graphics systems apply a normalizing scale factor
such that
$w=1$
at the far clip plane. This ensures
that the values used for depth buffering are distributed
appropriately for the scene being rendered,
to maximize precision of depth buffering.

The projection matrix in most graphics systems
also scales the
$x$
and
$y$
values according to the
field of view of the camera.
We'll get into these details in Section 10.3.2, when
we show what a projection matrix looks like in practice,
using both DirectX and OpenGL as examples.
Exercises

Compute the determinant of the following matrix:
$$\left[\begin{array}{cc}3& 2\\ 1& 4\end{array}\right]$$

Compute the determinant, adjoint, and inverse of the
following matrix:
$$\left[\begin{array}{ccc}3& 2& 0\\ 1& 4& 0\\ 0& 0& 2\end{array}\right]$$

Is the following matrix orthogonal?
$$\left[\begin{array}{ccc}0.1495& 0.1986& 0.9685\\ 0.8256& 0.5640& 0.0117\\ 0.5439& 0.8015& 0.2484\end{array}\right]$$

Invert the matrix from the previous exercise.

Invert the
$4\times 4$
matrix
$$\left[\begin{array}{cccc}0.1495& 0.1986& 0.9685& 0\\ 0.8256& 0.5640& 0.0117& 0\\ 0.5439& 0.8015& 0.2484& 0\\ 1.7928& 5.3116& 8.0151& 1\end{array}\right].$$

Construct a
$4\times 4$
matrix to translate by
$[4,2,3]$
.

Construct a
$4\times 4$
matrix to rotate 20° about the
$x$
axis
and then translate by
$[4,2,3]$
.

Construct a
$4\times 4$
matrix to translate by
$[4,2,3]$
and then
rotate 20° about the
$x$
axis.

Construct a
$4\times 4$
matrix to perform a perspective
projection onto the plane
$x=5$
. (Assume the origin is the
center of projection.)

Use the matrix from the previous exercise to compute the 3D
coordinates of the projection of the point
$(105,243,89)$
onto the plane
$x=5$
.
An attempt at visualizing the Fourth Dimension:
Take a point, stretch it into a line, curl it into a circle,
twist it into a sphere, and punch through the sphere.
— Albert Einstein (1879–1955)