Chapter 5
Matrices and Linear Transformations
It's time to transform!
— Super WHY!
Chapter 4 investigated some of the basic mathematical properties of matrices. It
also developed a geometric understanding of matrices and their relationship to coordinate space
transformations in general. This chapter continues our investigation of transformations.
To be more specific, this chapter is concerned with expressing linear transformations in
3D using
$3\times 3$
matrices. We give a more formal definition of linear transformations at the
end of this chapter, but for now, recall from our informal introduction to linear transformations
in Section 4.2 that one important property of linear
transformations is that they do not contain translation.
A transformation that contains translation is known as an affine transformation. Affine
transformations in 3D cannot be implemented using
$3\times 3$
matrices.
Section 5.7.2 gives a formal definition of affine transformations, and
Section 6.4 shows how to use
$4\times 4$
matrices to
represent affine transformations.
This chapter discusses the implementation of linear transformations via matrices. It is divided
roughly into two parts. In the first part,
Sections 5.1–5.5, we take the basic tools from
previous chapters to derive matrices for primitive linear transformations of rotation, scaling,
orthographic projection, reflection, and shearing. For each transformation, examples and
equations in 2D and 3D are given. The same strategy will be used repeatedly: determine what
happens to the standard basis vectors as a result of the transformation and then put those
transformed basis vectors into the rows of our matrix.
Note that these discussions assume an active transformation: the object is transformed
while the coordinate space remains stationary. Remember from
Section 3.3.1 that we can effectively perform a passive
transformation (transform the coordinate space and keep the object still) by transforming the
object by the oppositeamount.
A lot of this chapter is filled with messy equations and details, so you might be tempted to skip
over it—but don't! There are a lot of important, easily digested principles interlaced with
the safely forgotten details. We think it's important to be able to understand how various
transform matrices can be derived, so in principle you can derive them on your own from scratch.
Commit the highlevel principles in this chapter to memory, and don't get too bogged down in the
details. This book will not selfdestruct after you read it, so keep it on hand for reference
when you need a particular equation.
The second part of this chapter returns to general principles of transformations.
Section 5.6 shows how a sequence of primitive transformations may be
combined by using matrix multiplication to form a more complicated transformation.
Section 5.7 discusses various interesting categories of
transformations, including linear, affine, invertible, anglepreserving, orthogonal, and
rigidbody transforms.
5.1Rotation
We have already seen general examples of rotation matrices. Now let's develop a more rigorous
definition. First, Section 5.1.1 examines 2D rotation.
Section 5.1.2 shows how to rotate about a cardinal axis. Finally,
Section 5.1.3 tackles the most general case of rotation about an
arbitrary axis in 3D.
5.1.1Rotation in 2D
In 2D, there's really only one type of rotation that we can do: rotation about
a point. This chapter is concerned with linear transformations, which do not contain translation,
so we restrict our discussion even further to rotation about the origin. A 2D rotation about the
origin has only one parameter, the angle
$\theta $
, which defines the amount of rotation. The
standard convention found in most math books is to consider counterclockwise rotation positive
and clockwise rotation negative. (However, different conventions are more appropriate in
different situations.) Figure 5.1 shows how the basis vectors
$\mathbf{p}$
and
$\mathbf{q}$
are rotated about the origin, resulting in the new basis vectors
${\mathbf{p}}^{\prime}$
and
${\mathbf{q}}^{\prime}$
.
Now that we know the values of the basis vectors after rotation, we can build our matrix:
2D rotation matrix
$$\begin{array}{}\text{(5.1.1)}& \mathbf{R}(\theta )=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\end{array}\right]=\left[\begin{array}{cc}\mathrm{cos}\theta & \mathrm{sin}\theta \\ \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right].\end{array}$$
5.1.23D Rotation about Cardinal Axes
In 3D, rotation occurs about an axis rather than a point, with the term axis taking
on its more commonplace meaning of a line about which something rotates. An axis of rotation
does not necessarily have to be one of the cardinal
$x$
,
$y$
, or
$z$
axes—but those special
cases are the ones we consider
in this section. Again, we are not considering translation in
this chapter, so we will limit the discussion to rotation about an axis that passes through
the
origin. In any case, we'll need to establish which direction of rotation is considered
“positive” and which is considered “negative.” We're going to obey the lefthand rule for
this. Review Section 1.3.3 if you've forgotten this rule.
Let's start with rotation about the
$x$
axis, as shown in Figure 5.2.
Constructing a matrix from the rotated basis vectors, we have
3D matrix to rotate about the
$\mathit{x}$
axis
$${\mathbf{R}}_{x}(\theta )=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\\ {\mathbf{r}}^{\prime}\end{array}\right]=\left[\begin{array}{ccc}1& 0& 0\\ 0& \mathrm{cos}\theta & \mathrm{sin}\theta \\ 0& \mathrm{sin}\theta & \mathrm{cos}\theta \end{array}\right].$$
Rotation about the
$y$
axis is similar (see Figure 5.3). The matrix to rotate
about the
$y$
axis is
3D matrix to rotate about the
$\mathit{y}$
axis
$${\mathbf{R}}_{y}(\theta )=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\\ {\mathbf{r}}^{\prime}\end{array}\right]=\left[\begin{array}{ccc}\mathrm{cos}\theta & 0& \mathrm{sin}\theta \\ 0& 1& 0\\ \mathrm{sin}\theta & 0& \mathrm{cos}\theta \end{array}\right].$$
And finally, rotation about the
$z$
axis (see Figure 5.4) is done with the
matrix
3D matrix to rotate about the
$\mathit{z}$
axis
$${\mathbf{R}}_{z}(\theta )=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\\ {\mathbf{r}}^{\prime}\end{array}\right]=\left[\begin{array}{ccc}\mathrm{cos}\theta & \mathrm{sin}\theta & 0\\ \mathrm{sin}\theta & \mathrm{cos}\theta & 0\\ 0& 0& 1\end{array}\right].$$
Please note that although the figures in this section use a lefthanded convention, the matrices
work in either left or righthanded coordinate systems, due to the conventions used to define
the direction of positive rotation. You can verify this visually by looking at the figures in a
mirror.
5.1.33D Rotation about an Arbitrary Axis
We can also rotate about an arbitrary axis in 3D, provided, of course, that the axis passes
through the origin, since we are not considering translation at the moment. This is more
complicated and less common than rotating about a cardinal axis. As before, we define
$\theta $
to be the amount of rotation about the axis. The axis will be defined by a unit vector
$\hat{\mathbf{n}}$
.
Let's derive a matrix to rotate about
$\hat{\mathbf{n}}$
by the angle
$\theta $
. In other words, we
wish to derive the matrix
$\mathbf{R}(\hat{\mathbf{n}},\theta )$
such that when we multiply a vector
$\mathbf{v}$
by
$\mathbf{R}(\hat{\mathbf{n}},\theta )$
, the resulting vector
${\mathbf{v}}^{\prime}$
is the
result of rotating
$\mathbf{v}$
about
$\hat{\mathbf{n}}$
by the angle
$\theta $
:
$${\mathbf{v}}^{\prime}=\mathbf{v}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}\mathbf{R}(\hat{\mathbf{n}},\theta ).$$
To derive the matrix
$\mathbf{R}(\hat{\mathbf{n}},\theta )$
, let's first see if we can express
${\mathbf{v}}^{\prime}$
in terms of
$\mathbf{v}$
,
$\hat{\mathbf{n}}$
, and
$\theta $
. The basic idea is to solve
the problem in the plane perpendicular to
$\hat{\mathbf{n}}$
, which is a much simpler 2D problem. To
do this, we separate
$\mathbf{v}$
into two vectors,
${\mathbf{v}}_{\parallel}$
and
${\mathbf{v}}_{\perp}$
, which are parallel
and perpendicular to
$\hat{\mathbf{n}}$
, respectively, such that
$\mathbf{v}={\mathbf{v}}_{\parallel}+{\mathbf{v}}_{\perp}$
.
(We learned how to do this with the dot product in Section 2.11.2.)
By rotating each of these components individually, we can rotate the vector as a whole. In other
words,
${\mathbf{v}}^{\prime}={\mathbf{v}}_{\parallel}^{\prime}+{\mathbf{v}}_{\perp}^{\prime}$
. Since
${\mathbf{v}}_{\parallel}$
is parallel to
$\hat{\mathbf{n}}$
, it will not be affected by the rotation about
$\hat{\mathbf{n}}$
. In other words,
${\mathbf{v}}_{\parallel}^{\prime}={\mathbf{v}}_{\parallel}$
. So all we need to do is compute
${\mathbf{v}}_{\perp}^{\prime}$
, and then we have
${\mathbf{v}}^{\prime}={\mathbf{v}}_{\parallel}+{\mathbf{v}}_{\perp}^{\prime}$
. To compute
${\mathbf{v}}_{\perp}^{\prime}$
, we construct the vectors
${\mathbf{v}}_{\parallel}$
,
${\mathbf{v}}_{\perp}$
, and an intermediate vector
$\mathbf{w}$
, as follows:

The vector
${\mathbf{v}}_{\parallel}$
is the portion of
$\mathbf{v}$
that is parallel
to
$\hat{\mathbf{n}}$
. Another way of saying this is that
${\mathbf{v}}_{\parallel}$
is
the value of
$\mathbf{v}$
projected onto
$\hat{\mathbf{n}}$
. From
Section 2.11.2,
we know that
${\mathbf{v}}_{\parallel}=(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}$
.

The vector
${\mathbf{v}}_{\perp}$
is the portion of
$\mathbf{v}$
that is perpendicular to
$\hat{\mathbf{n}}$
. Since
$\mathbf{v}={\mathbf{v}}_{\parallel}+{\mathbf{v}}_{\perp}$
,
${\mathbf{v}}_{\perp}$
can be
computed by
$\mathbf{v}{\mathbf{v}}_{\parallel}$
.
${\mathbf{v}}_{\perp}$
is the result of
projecting
$\mathbf{v}$
onto the plane perpendicular to
$\hat{\mathbf{n}}$
.

The vector
$\mathbf{w}$
is mutually perpendicular to
${\mathbf{v}}_{\parallel}$
and
${\mathbf{v}}_{\perp}$
and has the same length as
${\mathbf{v}}_{\perp}$
. It can be constructed by rotating
${\mathbf{v}}_{\perp}$
$90{}^{\mathrm{o}}$
about
$\hat{\mathbf{n}}$
;
thus we see that its value is easily computed by
$\mathbf{w}=\hat{\mathbf{n}}\times {\mathbf{v}}_{\perp}$
.
These vectors are shown in Figure 5.5.
How do these vectors help us compute
${\mathbf{v}}_{\perp}^{\prime}$
? Notice that
$\mathbf{w}$
and
${\mathbf{v}}_{\perp}$
form a
2D coordinate space, with
${\mathbf{v}}_{\perp}$
as the “
$x$
axis” and
$\mathbf{w}$
as the “
$y$
axis.”
(Note that the two vectors don't necessarily have unit length.)
${\mathbf{v}}_{\perp}^{\prime}$
is the result of
rotating
${\mathbf{v}}^{\prime}$
in this plane by the angle
$\theta $
. Note that this is almost identical
to rotating an angle into standard position. Section 1.4.4 showed
that the endpoints of a unit ray rotated by an angle
$\theta $
are
$\mathrm{cos}\theta $
and
$\mathrm{sin}\theta $
. The only difference here is that our ray is not a unit ray, and we are using
${\mathbf{v}}_{\perp}$
and
$\mathbf{w}$
as our basis vectors. Thus,
${\mathbf{v}}_{\perp}^{\prime}$
can be computed as
$${\mathbf{v}}_{\perp}^{\prime}=\mathrm{cos}\theta {\mathbf{v}}_{\perp}+\mathrm{sin}\theta \mathbf{w}.$$
Let's summarize the vectors we have computed:
$$\begin{array}{rl}{\mathbf{v}}_{\parallel}& =(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}},\\ {\mathbf{v}}_{\perp}& =\mathbf{v}{\mathbf{v}}_{\parallel}\\ & =\mathbf{v}(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}},\\ \mathbf{w}& =\hat{\mathbf{n}}\times {\mathbf{v}}_{\perp}\\ & =\hat{\mathbf{n}}\times (\mathbf{v}{\mathbf{v}}_{\parallel})\\ & =\hat{\mathbf{n}}\times \mathbf{v}\hat{\mathbf{n}}\times {\mathbf{v}}_{\parallel}\\ & =\hat{\mathbf{n}}\times \mathbf{v}\mathbf{0}\\ & =\hat{\mathbf{n}}\times \mathbf{v},\\ {\mathbf{v}}_{\perp}^{\prime}& =\mathrm{cos}\theta {\mathbf{v}}_{\perp}+\mathrm{sin}\theta \mathbf{w}\\ & =\mathrm{cos}\theta (\mathbf{v}(\mathbf{v}\cdot \hat{\mathbf{n}}),\hat{\mathbf{n}})+\mathrm{sin}\theta (\hat{\mathbf{n}}\times \mathbf{v}).\end{array}$$
Substituting for
${\mathbf{v}}^{\prime}$
, we have
$$\begin{array}{}\text{(5.1)}& \begin{array}{rl}{\mathbf{v}}^{\prime}& ={\mathbf{v}}_{\perp}^{\prime}+{\mathbf{v}}_{\parallel}\\ & =\mathrm{cos}\theta (\mathbf{v}(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}})+\mathrm{sin}\theta (\hat{\mathbf{n}}\times \mathbf{v})+(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}.\end{array}\end{array}$$
Equation (5.1) allows us to rotate any arbitrary vector about any arbitrary
axis. We could perform arbitrary rotation transformations armed only with this equation, so in a
sense we are done—the remaining arithmetic is essentially a notational change that expresses
Equation (5.1) as a matrix multiplication.
Now that we have expressed
${\mathbf{v}}^{\prime}$
in terms of
$\mathbf{v}$
,
$\hat{\mathbf{n}}$
, and
$\theta $
,
we can compute what the basis vectors are after transformation and construct our matrix. We're
just presenting the results here; a reader interested in following each step can check out
Exercise 2.24:
$$\begin{array}{rlrl}\mathbf{p}& =\left[\begin{array}{ccc}1& 0& 0\end{array}\right],& {\mathbf{p}}^{\prime}& ={\left[\begin{array}{c}{{n}_{x}}^{2}(1\mathrm{cos}\theta )+\mathrm{cos}\theta \\ {n}_{x}{n}_{y}(1\mathrm{cos}\theta )+{n}_{z}\mathrm{sin}\theta \\ {n}_{x}{n}_{z}(1\mathrm{cos}\theta ){n}_{y}\mathrm{sin}\theta \end{array}\right]}^{\mathrm{T}},\\ \mathbf{q}& =\left[\begin{array}{ccc}0& 1& 0\end{array}\right],& {\mathbf{q}}^{\prime}& ={\left[\begin{array}{c}{n}_{x}{n}_{y}(1\mathrm{cos}\theta ){n}_{z}\mathrm{sin}\theta \\ {{n}_{y}}^{2}(1\mathrm{cos}\theta )+\mathrm{cos}\theta \\ {n}_{y}{n}_{z}(1\mathrm{cos}\theta )+{n}_{x}\mathrm{sin}\theta \end{array}\right]}^{\mathrm{T}},\\ \mathbf{r}& =\left[\begin{array}{ccc}0& 0& 1\end{array}\right],& {\mathbf{r}}^{\prime}& ={\left[\begin{array}{c}{n}_{x}{n}_{z}(1\mathrm{cos}\theta )+{n}_{y}\mathrm{sin}\theta \\ {n}_{y}{n}_{z}(1\mathrm{cos}\theta ){n}_{x}\mathrm{sin}\theta \\ {{n}_{z}}^{2}(1\mathrm{cos}\theta )+\mathrm{cos}\theta \end{array}\right]}^{\mathrm{T}}.\end{array}$$
Note that
${\mathbf{p}}^{\prime}$
and friends are actually row vectors, we are just writing them as
transposed column vectors to fit on the page.
Constructing the matrix from these basis vectors, we get
3D matrix to rotate about an arbitrary axis
$$\begin{array}{rl}& \mathbf{R}(\hat{\mathbf{n}},\theta )=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\\ {\mathbf{r}}^{\prime}\end{array}\right]\\ & =\left[\begin{array}{ccc}{{n}_{x}}^{2}(1\mathrm{cos}\theta )+\mathrm{cos}\theta & {n}_{x}{n}_{y}(1\mathrm{cos}\theta )+{n}_{z}\mathrm{sin}\theta & {n}_{x}{n}_{z}(1\mathrm{cos}\theta ){n}_{y}\mathrm{sin}\theta \\ {n}_{x}{n}_{y}(1\mathrm{cos}\theta ){n}_{z}\mathrm{sin}\theta & {{n}_{y}}^{2}(1\mathrm{cos}\theta )+\mathrm{cos}\theta & {n}_{y}{n}_{z}(1\mathrm{cos}\theta )+{n}_{x}\mathrm{sin}\theta \\ {n}_{x}{n}_{z}(1\mathrm{cos}\theta )+{n}_{y}\mathrm{sin}\theta & {n}_{y}{n}_{z}(1\mathrm{cos}\theta ){n}_{x}\mathrm{sin}\theta & {{n}_{z}}^{2}(1\mathrm{cos}\theta )+\mathrm{cos}\theta \end{array}\right].\end{array}$$
5.2Scale
We can scale an object to make it proportionally bigger or smaller by a factor of
$k$
. If we
apply this scale to the entire object, thus “dilating” the object about the origin, we are
performing a uniform scale. Uniform scale preserves angles and proportions. Lengths
increase or decrease uniformly by a factor of
$k$
, areas by a factor of
${k}^{2}$
, and volumes (in
3D) by a factor of
${k}^{3}$
.
If we wish to “stretch” or “squash” the object, we can apply different scale factors in
different directions, resulting in nonuniform scale. Nonuniform scale does not preserve
angles. Lengths, areas, and volumes are adjusted by a factor that varies according to the
orientation relative to the direction of scale.
If
$\leftk\right<1$
, then the object gets “shorter” in that direction. If
$\leftk\right>1$
, then the
object gets “longer.” If
$k=0$
, then we have an orthographic projection, discussed in
Section 5.3. If
$k<0$
, then we have a reflection, covered in
Section 5.4. For the remainder of this section, we will assume that
$k>0$
.
Section 5.2.1 begins with the simple case of scaling along the cardinal axes.
Then Section 5.2.2 examines the general case, scaling along an arbitrary
axis.
5.2.1Scaling along the Cardinal Axes
The simplest scale operation applies a separate scale factor along each cardinal axis. The scale
along an axis is applied about the perpendicular axis (in 2D) or plane (in 3D). If
the scale factors for all axes are equal, then the scale is uniform; otherwise, it is nonuniform.
In 2D, we have two scale factors,
${k}_{x}$
and
${k}_{y}$
.
Figure 5.6 shows an object with various scale values for
${k}_{x}$
and
${k}_{y}$
.
As is intuitively obvious, the basis vectors
$\mathbf{p}$
and
$\mathbf{q}$
are independently
affected by the corresponding scale factors:
$$\begin{array}{rlrclcr}{\mathbf{p}}^{\prime}& =& {k}_{x}\mathbf{p}& =& {k}_{x}\left[\begin{array}{cc}1& 0\end{array}\right]& =& \left[\begin{array}{cc}{k}_{x}& 0\end{array}\right],\\ {\mathbf{q}}^{\prime}& =& {k}_{y}\mathbf{q}& =& {k}_{y}\left[\begin{array}{cc}0& 1\end{array}\right]& =& \left[\begin{array}{cc}0& {k}_{y}\end{array}\right].\end{array}$$
Constructing the 2D scale matrix
$\mathbf{S}({k}_{x},{k}_{y})$
from these basis vectors, we get
$$\mathbf{S}({k}_{x},{k}_{y})=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\end{array}\right]=\left[\begin{array}{cc}{k}_{x}& 0\\ 0& {k}_{y}\end{array}\right].$$
2D matrix to scale on cardinal axes
For 3D, we add a third scale factor
${k}_{z}$
, and the 3D scale matrix is then given by
3D matrix to scale on cardinal axes
$$\mathbf{S}({k}_{x},{k}_{y},{k}_{z})=\left[\begin{array}{ccc}{k}_{x}& 0& 0\\ 0& {k}_{y}& 0\\ 0& 0& {k}_{z}\end{array}\right].$$
If we multiply any arbitrary vector by this matrix, then, as expected, each component is scaled
by the appropriate scale factor:
$$\left[\begin{array}{ccc}x& y& z\end{array}\right]\left[\begin{array}{ccc}{k}_{x}& 0& 0\\ 0& {k}_{y}& 0\\ 0& 0& {k}_{z}\end{array}\right]=\left[\begin{array}{ccc}{k}_{x}x& {k}_{y}y& {k}_{z}z\end{array}\right].$$
5.2.2Scaling in an Arbitrary Direction
We can apply scale independent of the coordinate system used by scaling in an arbitrary
direction. We define
$\hat{\mathbf{n}}$
to be the unit vector parallel to the direction of scale, and
$k$
to be the scale factor to be applied about the line (in 2D) or plane (in 3D) that passes
through the origin and is perpendicular to
$\hat{\mathbf{n}}$
. We are scaling along
$\hat{\mathbf{n}}$
, not about
$\hat{\mathbf{n}}$
.
To derive a matrix that scales along an arbitrary axis, we'll use an approach similar to the one
used in Section 5.1.3 for rotation about an arbitrary axis. Let's
derive an expression that, given an arbitrary vector
$\mathbf{v}$
, computes
${\mathbf{v}}^{\prime}$
in
terms of
$\mathbf{v}$
,
$\hat{\mathbf{n}}$
, and
$k$
. As before, we separate
$\mathbf{v}$
into two
values,
${\mathbf{v}}_{\parallel}$
and
${\mathbf{v}}_{\perp}$
, which are parallel and perpendicular to
$\hat{\mathbf{n}}$
,
respectively, such that
$\mathbf{v}={\mathbf{v}}_{\parallel}+{\mathbf{v}}_{\perp}$
. The parallel portion,
${\mathbf{v}}_{\parallel}$
,
is the projection of
$\mathbf{v}$
onto
$\hat{\mathbf{n}}$
. From
Section 2.11.2, we know that
${\mathbf{v}}_{\parallel}=(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}$
. Since
${\mathbf{v}}_{\perp}$
is perpendicular to
$\hat{\mathbf{n}}$
, it will not be
affected by the scale operation. Thus
${\mathbf{v}}^{\prime}={\mathbf{v}}_{\parallel}^{\prime}+{\mathbf{v}}_{\perp}$
, and all we have
left to do is compute the value of
${\mathbf{v}}_{\parallel}^{\prime}$
. Since
${\mathbf{v}}_{\parallel}$
is parallel to the
direction of scale,
${\mathbf{v}}_{\parallel}^{\prime}$
is trivially given by
$k{\mathbf{v}}_{\parallel}$
. This is shown in
Figure 5.7.
Summarizing the known vectors and substituting gives us
$$\begin{array}{rl}\mathbf{v}& ={\mathbf{v}}_{\parallel}+{\mathbf{v}}_{\perp},\\ {\mathbf{v}}_{\parallel}& =(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}},\\ {\mathbf{v}}_{\perp}^{\prime}& ={\mathbf{v}}_{\perp}\\ & =\mathbf{v}{\mathbf{v}}_{\parallel}\\ & =\mathbf{v}(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}},\\ {\mathbf{v}}_{\parallel}^{\prime}& =k{\mathbf{v}}_{\parallel}\\ & =k(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}},\\ {\mathbf{v}}^{\prime}& ={\mathbf{v}}_{\perp}^{\prime}+{\mathbf{v}}_{\parallel}^{\prime}\\ & =\mathbf{v}(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}+k(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}\\ & =\mathbf{v}+(k1)(\mathbf{v}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}.\end{array}$$
Now that we know how to scale an arbitrary vector, we can compute the value of the basis vectors
after scale. We derive the first 2D basis vector; the other basis vector is similar, and so we
merely present the results. (Note that column vectors are used in the equations below strictly
to make the equations format nicely on the page.):
$$\begin{array}{rl}\mathbf{p}& =\left[\begin{array}{cc}1& 0\end{array}\right],\\ {\mathbf{p}}^{\prime}& =\mathbf{p}+(k1)(\mathbf{p}\cdot \hat{\mathbf{n}})\hat{\mathbf{n}}=\left[\begin{array}{c}1\\ 0\end{array}\right]+(k1)(\left[\begin{array}{c}1\\ 0\end{array}\right]\cdot \left[\begin{array}{c}{n}_{x}\\ {n}_{y}\end{array}\right])\left[\begin{array}{c}{n}_{x}\\ {n}_{y}\end{array}\right]\\ & =\left[\begin{array}{c}1\\ 0\end{array}\right]+(k1){n}_{x}\left[\begin{array}{c}{n}_{x}\\ {n}_{y}\end{array}\right]=\left[\begin{array}{c}1\\ 0\end{array}\right]+\left[\begin{array}{c}(k1){{n}_{x}}^{2}\\ (k1){n}_{x}{n}_{y}\end{array}\right]\\ & =\left[\begin{array}{c}1+(k1){{n}_{x}}^{2}\\ (k1){n}_{x}{n}_{y}\end{array}\right],\\ \mathbf{q}& =\left[\begin{array}{cc}0& 1\end{array}\right],\\ {\mathbf{q}}^{\prime}& =\left[\begin{array}{c}(k1){n}_{x}{n}_{y}\\ 1+(k1){{n}_{y}}^{2}\end{array}\right].\end{array}$$
Forming a matrix from the basis vectors, we arrive at the 2D matrix to scale by a factor of
$k$
in an arbitrary direction specified by the unit vector
$\hat{\mathbf{n}}$
:
2D matrix to scale in an arbitrary direction
$$\mathbf{S}(\hat{\mathbf{n}},k)=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\end{array}\right]=\left[\begin{array}{cc}1+(k1){{n}_{x}}^{2}& (k1){n}_{x}{n}_{y}\\ (k1){n}_{x}{n}_{y}& 1+(k1){{n}_{y}}^{2}\end{array}\right].$$
In 3D, the values of the basis vectors are computed by
$$\begin{array}{rlrl}\mathbf{p}& =\left[\begin{array}{ccc}1& 0& 0\end{array}\right],& {\mathbf{p}}^{\prime}& ={\left[\begin{array}{c}1+(k1){{n}_{x}}^{2}\\ (k1){n}_{x}{n}_{y}\\ (k1){n}_{x}{n}_{z}\end{array}\right]}^{\mathrm{T}},\\ \mathbf{q}& =\left[\begin{array}{ccc}0& 1& 0\end{array}\right],& {\mathbf{q}}^{\prime}& ={\left[\begin{array}{c}(k1){n}_{x}{n}_{y}\\ 1+(k1){{n}_{y}}^{2}\\ (k1){n}_{y}{n}_{z}\end{array}\right]}^{\mathrm{T}},\\ \mathbf{r}& =\left[\begin{array}{ccc}0& 0& 1\end{array}\right],& {\mathbf{r}}^{\prime}& ={\left[\begin{array}{c}(k1){n}_{x}{n}_{z}\\ (k1){n}_{y}{n}_{z}\\ 1+(k1){{n}_{z}}^{2}\end{array}\right]}^{\mathrm{T}}.\end{array}$$
A suspicious reader wondering if we just made that up can step through the derivation in
Exercise 2.23.
Finally, the 3D matrix to scale by a factor of
$k$
in an arbitrary direction specified by the
unit vector
$\hat{\mathbf{n}}$
is
3D matrix to scale in an arbitrary direction
$$\begin{array}{rl}& \mathbf{S}(\hat{\mathbf{n}},k)=\left[\begin{array}{c}{\mathbf{p}}^{\prime}\\ {\mathbf{q}}^{\prime}\\ {\mathbf{r}}^{\prime}\end{array}\right]\\ & =\left[\begin{array}{ccc}1+(k1){{n}_{x}}^{2}& (k1){n}_{x}{n}_{y}& (k1){n}_{x}{n}_{z}\\ (k1){n}_{x}{n}_{y}& 1+(k1){{n}_{y}}^{2}& (k1){n}_{y}{n}_{z}\\ (k1){n}_{x}{n}_{z}& (k1){n}_{y}{n}_{z}& 1+(k1){{n}_{z}}^{2}\end{array}\right].\end{array}$$
5.3Orthographic Projection
In general, the term projection refers to any dimensionreducing operation. As we
discussed in Section 5.2, one way we can achieve projection is to use a scale factor of
zero in a direction. In this case, all the points are flattened or projected onto the
perpendicular axis (in 2D) or plane (in 3D). This type of projection is an orthographic
projection, also known as a parallel projection, since the lines from the original points
to their projected counterparts are parallel. We present another type of projection,
perspective projection, in Section 6.5.
First, Section 5.3.1 discusses orthographic projection onto
a cardinal axis or plane, and then Section 5.3.2 examines
the general case.
5.3.1Projecting onto a Cardinal Axis or Plane
The simplest type of projection occurs when we project onto a cardinal axis (in 2D) or plane (in
3D). This is illustrated in Figure 5.8.
Projection onto a cardinal axis or plane most frequently occurs not by actual transformation, but
by simply discarding one of the coordinates while assigning the data into a variable of lesser
dimension. For example, we may turn a 3D object into a 2D object by discarding the
$z$
components
of the points and copying only
$x$
and
$y$
.
However, we can also project onto a cardinal axis or plane by using a scale value of zero on the
perpendicular axis. For completeness, we present the matrices for these transformations:
Projecting onto a cardinal axis
$$\begin{array}{rl}{\mathbf{P}}_{x}& =\mathbf{S}(\left[\begin{array}{cc}0& 1\end{array}\right],0)=\left[\begin{array}{cc}1& 0\\ 0& 0\end{array}\right],\\ {\mathbf{P}}_{y}& =\mathbf{S}(\left[\begin{array}{cc}1& 0\end{array}\right],0)=\left[\begin{array}{cc}0& 0\\ 0& 1\end{array}\right],\end{array}$$
Projecting onto a cardinal plane
$$\begin{array}{rl}{\mathbf{P}}_{xy}& =\mathbf{S}(\left[\begin{array}{ccc}0& 0& 1\end{array}\right],0)=\left[\begin{array}{ccc}1& 0& 0\\ 0& 1& 0\\ 0& 0& 0\end{array}\right],\\ {\mathbf{P}}_{xz}& =\mathbf{S}(\left[\begin{array}{ccc}0& 1& 0\end{array}\right],0)=\left[\begin{array}{ccc}1& 0& 0\\ 0& 0& 0\\ 0& 0& 1\end{array}\right],\\ {\mathbf{P}}_{yz}& =\mathbf{S}(\left[\begin{array}{ccc}1& 0& 0\end{array}\right],0)=\left[\begin{array}{ccc}0& 0& 0\\ 0& 1& 0\\ 0& 0& 1\end{array}\right].\end{array}$$
5.3.2Projecting onto an Arbitrary Line or Plane
We can also project onto any arbitrary line (in 2D) or plane (in 3D). As before, since we are
not considering translation, the line or plane must pass through the origin. The projection will
be defined by a unit vector
$\hat{\mathbf{n}}$
that is perpendicular to the line or plane.
We can derive the matrix to project in an arbitrary direction by applying a zero scale factor
along this direction, using the equations we developed in Section 5.2.2. In
2D, we have
2D matrix to project onto an arbitrary line
$$\begin{array}{r}\begin{array}{rl}\mathbf{P}(\hat{\mathbf{n}})=\mathbf{S}(\hat{\mathbf{n}},0)& =\left[\begin{array}{cc}1+(01){{n}_{x}}^{2}& (01){n}_{x}{n}_{y}\\ (01){n}_{x}{n}_{y}& 1+(01){{n}_{y}}^{2}\end{array}\right]\\ & =\left[\begin{array}{cc}1{{n}_{x}}^{2}& {n}_{x}{n}_{y}\\ {n}_{x}{n}_{y}& 1{{n}_{y}}^{2}\end{array}\right].\end{array}\end{array}$$
Remember that
$\hat{\mathbf{n}}$
is perpendicular to the line onto which we are projecting, not
parallel to it. In 3D, we project onto the plane perpendicular to
$\hat{\mathbf{n}}$
:
3D matrix to project onto an arbitrary plane
$$\begin{array}{rl}\mathbf{P}(\hat{\mathbf{n}})=\mathbf{S}(\hat{\mathbf{n}},0)& =\left[\begin{array}{ccc}1+(01){{n}_{x}}^{2}& (01){n}_{x}{n}_{y}& (01){n}_{x}{n}_{z}\\ (01){n}_{x}{n}_{y}& 1+(01){{n}_{y}}^{2}& (01){n}_{y}{n}_{z}\\ (01){n}_{x}{n}_{z}& (01){n}_{y}{n}_{z}& 1+(01){{n}_{z}}^{2}\end{array}\right]\\ & =\left[\begin{array}{ccc}1{{n}_{x}}^{2}& {n}_{x}{n}_{y}& {n}_{x}{n}_{z}\\ {n}_{x}{n}_{y}& 1{{n}_{y}}^{2}& {n}_{y}{n}_{z}\\ {n}_{x}{n}_{z}& {n}_{y}{n}_{z}& 1{{n}_{z}}^{2}\end{array}\right].\end{array}$$
5.4Reflection
Reflection (also called mirroring) is a transformation that “flips” the object about a
line (in 2D) or a plane (in 3D). Figure 5.9 shows the result of reflecting an
object about the
$x$
 and
$y$
axis.
Reflection can be accomplished by applying a scale factor of
$1$
. Let
$\hat{\mathbf{n}}$
be a 2D
unit vector. Then the matrix that performs a reflection about the axis of reflection that passes
through the origin and is perpendicular to
$\hat{\mathbf{n}}$
is given by
$$\begin{array}{r}\begin{array}{rl}\mathbf{R}(\hat{\mathbf{n}})=\mathbf{S}(\hat{\mathbf{n}},1)& =\left[\begin{array}{cc}1+(11){{n}_{x}}^{2}& (11){n}_{x}{n}_{y}\\ (11){n}_{x}{n}_{y}& 1+(11){{n}_{y}}^{2}\end{array}\right]\\ & =\left[\begin{array}{cc}12{{n}_{x}}^{2}& 2{n}_{x}{n}_{y}\\ 2{n}_{x}{n}_{y}& 12{{n}_{y}}^{2}\end{array}\right].\end{array}\end{array}$$
2D matrix to reflect about an arbitrary axis
In 3D, we have a reflecting plane instead of axis. For the transformation to be linear,
the plane must contain the origin, in which case the matrix to perform the reflection is
$$\begin{array}{rl}\mathbf{R}(\hat{\mathbf{n}})& =\mathbf{S}(\hat{\mathbf{n}},1)\\ & =\left[\begin{array}{ccc}1+(11){{n}_{x}}^{2}& (11){n}_{x}{n}_{y}& (11){n}_{x}{n}_{z}\\ (11){n}_{x}{n}_{y}& 1+(11){{n}_{y}}^{2}& (11){n}_{y}{n}_{z}\\ (11){n}_{x}{n}_{z}& (11){n}_{y}{n}_{z}& 1+(11){{n}_{z}}^{2}\end{array}\right]\\ & =\left[\begin{array}{ccc}12{{n}_{x}}^{2}& 2{n}_{x}{n}_{y}& 2{n}_{x}{n}_{z}\\ 2{n}_{x}{n}_{y}& 12{{n}_{y}}^{2}& 2{n}_{y}{n}_{z}\\ 2{n}_{x}{n}_{z}& 2{n}_{y}{n}_{z}& 12{{n}_{z}}^{2}\end{array}\right].\end{array}$$
3D matrix to reflect about an arbitrary plane
Notice that an object can be “reflected” only once. If we reflect it again (even about a
different axis or plane) then the object is flipped back to “right side out,” and it is the
same as if we had rotated the object from its initial position. An example of this is shown in
the bottomleft corner of Figure 5.9.
5.5Shearing
Shearing is a transformation that “skews” the coordinate space, stretching it nonuniformly.
Angles are not preserved; however, surprisingly, areas and volumes are. The basic idea is to add
a multiple of one coordinate to the other. For example, in 2D, we might take a multiple of
$y$
and add it to
$x$
, so that
${x}^{\prime}=x+sy$
. This is shown in Figure 5.10.
The matrix that performs this shear is
$${\mathbf{H}}_{x}(s)=\left[\begin{array}{cc}1& 0\\ s& 1\end{array}\right],$$
where the notation
${\mathbf{H}}_{x}$
denotes that the
$x$
coordinate is sheared by the other
coordinate,
$y$
. The parameter
$s$
controls the amount and direction of the shearing. The other
2D shear matrix,
${\mathbf{H}}_{y}$
, is
$${\mathbf{H}}_{y}(s)=\left[\begin{array}{cc}1& s\\ 0& 1\end{array}\right].$$
In 3D, we can take one coordinate and add different multiples of that coordinate to the other two
coordinates. The notation
${\mathbf{H}}_{xy}$
indicates that the
$x$
 and
$y$
coordinates are
shifted by the other coordinate,
$z$
. We present these matrices for completeness:
$$\begin{array}{rl}{\mathbf{H}}_{xy}(s,t)& =\left[\begin{array}{ccc}1& 0& 0\\ 0& 1& 0\\ s& t& 1\end{array}\right],\\ {\mathbf{H}}_{xz}(s,t)& =\left[\begin{array}{ccc}1& 0& 0\\ s& 1& t\\ 0& 0& 1\end{array}\right],\\ {\mathbf{H}}_{yz}(s,t)& =\left[\begin{array}{ccc}1& s& t\\ 0& 1& 0\\ 0& 0& 1\end{array}\right].\end{array}$$
3D shear matrices
Shearing is a seldomused transform. It is also known as a skew transform. Combining
shearing and scaling (uniform or nonuniform) creates a transformation that is indistinguishable
from a transformation containing rotation and nonuniform scale.
This section shows how to take a sequence of transformation matrices and combine (or
concatenate) them into one single transformation matrix. This new matrix represents the
cumulative result of applying all of the original transformations in order. It's actually quite
easy. The transformation that results from applying the transformation with matrix
$\mathbf{A}$
followed by the transformation with matrix
$\mathbf{B}$
has matrix
$\mathbf{A}\mathbf{B}$
. That is, matrix
multiplication is how we compose transformations represented as matrices.
One very common example of this is in rendering. Imagine there is an object at an arbitrary
position and orientation in the world. We wish to render this object given a camera in any
position and orientation. To do this, we must take the vertices of the object (assuming we are
rendering some sort of triangle mesh) and transform them from object space into world space. This
transform is known as the model transform, which we denote
${\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{w}\mathrm{l}\mathrm{d}}$
. From there, we transform worldspace vertices with the
view transform, denoted
${\mathbf{M}}_{\mathrm{w}\mathrm{l}\mathrm{d}\to \mathrm{c}\mathrm{a}\mathrm{m}}$
, into camera space.
The math involved is summarized by
$$\begin{array}{rl}{\mathbf{p}}_{\mathrm{w}\mathrm{l}\mathrm{d}}& ={\mathbf{p}}_{\mathrm{o}\mathrm{b}\mathrm{j}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{w}\mathrm{l}\mathrm{d}},\\ {\mathbf{p}}_{\mathrm{c}\mathrm{a}\mathrm{m}}& ={\mathbf{p}}_{\mathrm{w}\mathrm{l}\mathrm{d}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{w}\mathrm{l}\mathrm{d}\to \mathrm{c}\mathrm{a}\mathrm{m}}\\ & =({\mathbf{p}}_{\mathrm{o}\mathrm{b}\mathrm{j}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{w}\mathrm{l}\mathrm{d}}){\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{w}\mathrm{l}\mathrm{d}\to \mathrm{c}\mathrm{a}\mathrm{m}}.\end{array}$$
From Section 4.1.6, we know that matrix multiplication is
associative, and so we could compute one matrix to transform directly from object to camera
space:
$$\begin{array}{rl}{\mathbf{p}}_{\mathrm{c}\mathrm{a}\mathrm{m}}& =({\mathbf{p}}_{\mathrm{o}\mathrm{b}\mathrm{j}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{w}\mathrm{l}\mathrm{d}}){\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{w}\mathrm{l}\mathrm{d}\to \mathrm{c}\mathrm{a}\mathrm{m}}\\ & ={\mathbf{p}}_{\mathrm{o}\mathrm{b}\mathrm{j}}({\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{w}\mathrm{l}\mathrm{d}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{w}\mathrm{l}\mathrm{d}\to \mathrm{c}\mathrm{a}\mathrm{m}}).\end{array}$$
Thus, we can concatenate the matrices outside the vertex loop, and have only one matrix
multiplication inside the loop (remember there are many vertices):
$$\begin{array}{rl}{\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{c}\mathrm{a}\mathrm{m}}& ={\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{w}\mathrm{l}\mathrm{d}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{w}\mathrm{l}\mathrm{d}\to \mathrm{c}\mathrm{a}\mathrm{m}},\\ {\mathbf{p}}_{\mathrm{c}\mathrm{a}\mathrm{m}}& ={\mathbf{p}}_{\mathrm{o}\mathrm{b}\mathrm{j}}{\textstyle \phantom{\rule{thinmathspace}{0ex}}}{\mathbf{M}}_{\mathrm{o}\mathrm{b}\mathrm{j}\to \mathrm{c}\mathrm{a}\mathrm{m}}.\end{array}$$
So we see that matrix concatenation works from an algebraic perspective by using the associative
property of matrix multiplication. Let's see if we can get a more geometric interpretation of
what's going on. Recall from Section 4.2, our breakthrough
discovery, that the rows of a matrix contain the result of transforming the standard basis
vectors. This is true even in the case of multiple transformations. Notice that in the matrix
product
$\mathbf{A}\mathbf{B}$
, each resulting row is the product of the corresponding row from
$\mathbf{A}$
times the matrix
$\mathbf{B}$
. In other words, let the row vectors
${\mathbf{a}}_{1}$
,
${\mathbf{a}}_{2}$
, and
${\mathbf{a}}_{3}$
stand for the rows of
$\mathbf{A}$
. Then matrix multiplication
can alternatively be written as
$$\begin{array}{rlrl}\mathbf{A}& =\left[\begin{array}{c}{\mathbf{a}}_{1}\\ {\mathbf{a}}_{2}\\ {\mathbf{a}}_{3}\end{array}\right],& \mathbf{A}\mathbf{B}& =\left(\left[\begin{array}{c}{\mathbf{a}}_{1}\\ {\mathbf{a}}_{2}\\ {\mathbf{a}}_{3}\end{array}\right]\mathbf{B}\right)=\left[\begin{array}{c}{\mathbf{a}}_{1}\mathbf{B}\\ {\mathbf{a}}_{2}\mathbf{B}\\ {\mathbf{a}}_{3}\mathbf{B}\end{array}\right].\end{array}$$
This explicitly shows that the rows of the product of
$\mathbf{A}\mathbf{B}$
are actually the
result of transforming the basis vectors in
$\mathbf{A}$
by
$\mathbf{B}$
.
We can classify transformations according to several criteria. This section discuss classes of
transformations. For each class, we describe the properties of the transformations that belong to
that class and specify which of the primitive transformations from
Sections 5.1 through 5.5 belong to
that class. The classes of transformations are not mutually exclusive, nor do they necessarily
follow an “order” or “hierarchy,” with each one more or less restrictive than the next.
When we discuss transformations in general, we may make use of the synonymous terms mapping
or function. In the most general sense, a mapping is simply a rule that takes an input and
produces an output. We denote that the mapping
$F$
maps
$a$
to
$b$
by writing
$F(a)=b$
(read
“
$F$
of
$a$
equals
$b$
”). Of course, we are primarily interested in the transformations that can
be expressed by using matrix multiplication, but it is important to note that other mappings are
possible.
This section also mentions the determinant of a matrix. We're getting a bit ahead of
ourselves here, since a full explanation of determinants isn't given until
Section 6.1. For now, just know that the determinant of a matrix is
a scalar quantity that is very useful for making certain highlevel, shall we say,
determinations about the matrix.
We met linear functions informally in Section 4.2.
Mathematically, a mapping
$F(\mathbf{a})$
is linear if
Conditions satisfied if
$\mathit{F}$
is a linear mapping
$$\begin{array}{rl}\text{(5.2)}& F(\mathbf{a}+\mathbf{b})& =F(\mathbf{a})+F(\mathbf{b})& \text{and}\\ \text{(5.3)}& F(k\mathbf{a})& =kF(\mathbf{a}).\end{array}$$
This is a fancy way of stating that the mapping
$F$
is linear if it preserves the basic operations
of addition and multiplication by a scalar. If we add two vectors, and then perform the
transformation, we get the same result as if we perform the transformation on the two vectors
individually and then add the transformed vectors. Likewise, if we scale a vector and then
transform it, we should get the same resulting vector as when we transform the vector and then
scale it.
There are two important implications of this definition of linear
transformation. First, the mapping
$F(\mathbf{a})=\mathbf{a}\mathbf{M}$
, where
$\mathbf{M}$
is any square matrix, is
a linear transformation, because
Matrix multiplication satisfies Equation (5.2)
$$\begin{array}{r}F(\mathbf{a}+\mathbf{b})=(\mathbf{a}+\mathbf{b})\mathbf{M}=\mathbf{a}\mathbf{M}+\mathbf{b}\mathbf{M}=F(\mathbf{a})+F(\mathbf{b})\end{array}$$
and
Matrix multiplication satisfies Equation (5.3)
$$\begin{array}{r}F(k\mathbf{a})=(k\mathbf{a})\mathbf{M}=k(\mathbf{a}\mathbf{M})=kF(\mathbf{a}).\end{array}$$
In other words:
Any transformation that can be accomplished with matrix
multiplication is a linear transformation.
Second, any linear transformation will transform the zero vector
into the zero vector. If
$F(\mathbf{0})=\mathbf{a},\mathbf{a}\ne \mathbf{0}$
, then
$F$
cannot be a linear mapping, since
$F(k\mathbf{0})=\mathbf{a}$
and therefore
$F(k\mathbf{0})\ne kF(\mathbf{0})$
. Because of this,
Linear transformations do not contain translation.
Since all of the transformations we discussed in
Sections 5.1
through 5.5 can be expressed using
matrix multiplication, they are all linear transformations.
In some literature, a linear transformation is defined as one in
which parallel lines remain parallel after transformation. This
is almost completely accurate, with two exceptions. First,
parallel lines remain parallel after translation, but translation
is not a linear transformation. Second, what about projection?
When a line is projected and becomes a single point, can we
consider that point “parallel” to anything? Excluding these
technicalities, the intuition is correct: a linear transformation
may “stretch” things, but straight lines are not “warped” and
parallel lines remain parallel.
An affine transformation is a linear transformation
followed by translation. Thus, the set of affine transformations
is a superset of the set of linear transformations: any linear
transformation is an affine translation, but not all affine
transformations are linear transformations.
Since all of the transformations discussed in this chapter are linear transformations, they are all
also affine transformations (though none of them have a translation portion). Any transformation
of the form
${\mathbf{v}}^{\prime}=\mathbf{v}\mathbf{M}+\mathbf{b}$
is an affine transformation.
A transformation is invertible if there exists an opposite transformation, known as the
inverse of
$F$
, that “undoes” the original transformation. In other words, a mapping
$F(\mathbf{a})$
is invertible if there exists an inverse mapping
${F}^{1}$
such that
$${F}^{1}(F(\mathbf{a}))=F({F}^{1}(\mathbf{a}))=\mathbf{a}$$
for all
$\mathbf{a}$
. Notice that this implies that
${F}^{1}$
is
also invertible.
There are nonaffine invertible transformations, but we will not consider them for the moment. For
now, let's concentrate on determining if an affine transformation is invertible. As already
stated, an affine transformation is a linear transformation followed by a translation. Obviously,
we can always “undo” the translation portion by simply translating by the opposite amount. So
the question becomes whether the linear transformation is invertible.
Intuitively, we know that all of the transformations other than projection can be “undone.” If
we rotate, scale, reflect, or skew, we can always “unrotate,” “unscale,” “unreflect,” or
“unskew.” But when an object is projected, we effectively discard one or more dimensions' worth
of information, and this information cannot be recovered. Thus, all of the primitive
transformations other than projection are invertible.
Since any linear transformation can be expressed as multiplication by a matrix, finding the inverse
of a linear transformation is equivalent to finding the inverse of a matrix. We discuss how to do
this in Section 6.2. If the matrix has no inverse, we say that it is
singular, and the transformation is noninvertible. The determinant of an invertible matrix
is nonzero.
In a nonsingular matrix, the zero vector is the only input vector that is mapped to the zero
vector in the output space; all other vectors are mapped to some other nonzero vector. In a
singular matrix, however, there exists an entire subspace of the input vectors, known as
the
null space of the matrix, that is mapped to the zero vector. For example, consider a
matrix that projects orthographically onto a plane containing the origin. The null space of this
matrix consists of the line of vectors perpendicular to the plane, since they are all mapped to
the origin.
When a square matrix is singular, its basis vectors are not linearly independent (see
Section 3.3.3). If the basis vectors are linearly independent, then
they have full rank, and coordinates of any given vector in the span are uniquely determined. If
the vectors are linearly dependent, then there is a portion of the full
$n$
dimensional space
that is not in the span of the basis. Consider two vectors
$\mathbf{a}$
and
$\mathbf{b}$
, which
differ by a vector
$\mathbf{n}$
that lies in the null space of a matrix
$\mathbf{M}$
, such that
$\mathbf{b}=\mathbf{a}+\mathbf{n}$
. Due to the linear nature of matrix multiplication,
$\mathbf{M}$
maps
$\mathbf{a}$
and
$\mathbf{b}$
to the same output:
$$\begin{array}{rl}\mathbf{b}\mathbf{M}& =(\mathbf{a}+\mathbf{n})\mathbf{M}\\ & =\mathbf{a}\mathbf{M}+\mathbf{n}\mathbf{M}& & (\text{Matrix multiplication is linear and distributes})\\ & =\mathbf{a}\mathbf{M}+\mathbf{0}& & (\mathbf{n}\text{}\text{is in the null space of}\text{}\mathbf{M})\\ & =\mathbf{a}\mathbf{M}.\end{array}$$
A transformation is anglepreserving if the angle between two
vectors is not altered in either magnitude or direction after
transformation. Only translation, rotation, and uniform scale are
anglepreserving transformations. An anglepreserving matrix
preserves proportions. We do not consider reflection an
anglepreserving transformation because even though the magnitude of
angle between two vectors is the same after transformation, the
direction of angle may be inverted. All anglepreserving
transformations are affine and invertible.
Orthogonal is a term that is used to describe a matrix whose rows form an orthonormal basis.
Remember from Section 3.3.3 that the basic idea is that the axes are
perpendicular to each other and have unit length. Orthogonal transformations are interesting
because it is easy to compute their inverse and they arise frequently in practice. We talk more
about orthogonal matrices in Section 6.3.
Translation, rotation, and reflection are the only orthogonal transformations. All orthogonal
transformations are affine and invertible. Lengths, angles, areas, and volumes are all preserved;
however in saying this, we must be careful as to our precise definition of angle, area, and volume,
since reflection is an orthogonal transformation and we just got through saying in the previous
section that we didn't consider reflection to be an anglepreserving transformation. Perhaps we
should be more precise and say that orthogonal matrices preserve the magnitudes of angles,
areas, and volumes, but possibly not the signs.
As Chapter 6 shows, the determinant of an orthogonal matrix is
$\pm 1$
.
5.7.6Rigid Body Transformations
A rigid body transformation is one that changes the
location and orientation of an object, but not its shape. All
angles, lengths, areas, and volumes are preserved. Translation
and rotation are the only rigid body transformations. Reflection
is not considered a rigid body transformation.
Rigid body transformations are also known as proper transformations. All rigid body
transformations are orthogonal, anglepreserving, invertible, and affine. Rigid body transforms
are the most restrictive class of transforms discussed in this section, but they are also
extremely common in practice.
The determinant of any rigid body transformation matrix is 1.
Table 5.1 summarizes the various classes of transformations. In this
table, a Y means that the transformation in that row always has the property associated with that
column. The absence of a Y does not mean “never”; rather, it means “not always.”
Exercises

Does the matrix below express a linear transformation? Affine?
$$\left[\begin{array}{ccc}34& 1.7& \pi \\ \sqrt{2}& 0& 18\\ 4& 9& 1.3\end{array}\right]$$

Construct a matrix to rotate
$22{}^{\mathrm{o}}$
about the
$x$
axis.

Construct a matrix to rotate
$30{}^{\mathrm{o}}$
about the
$y$
axis.

Construct a matrix to rotate
$15{}^{\mathrm{o}}$
about the axis
$[0.267,0.535,0.802]$
.

Construct a matrix that doubles the height, width, and length of an
object in 3D.

Construct a matrix to scale by a factor of 5 about the plane
through the origin perpendicular to the vector
$[0.267,0.535,0.802]$
.

Construct a matrix to orthographically project onto the plane
through the origin perpendicular to the vector
$[0.267,0.535,0.802]$
.

Construct a matrix to reflect orthographically about the plane
through the origin perpendicular to the vector
$[0.267,0.535,0.802]$
.

An object initially had its axes and origin coincident with the
world axes and origin. It was then rotated
$30{}^{\mathrm{o}}$
about the
$y$
axis and then
$22{}^{\mathrm{o}}$
about the world
$x$
axis.

(a)What is the matrix that can be used to transform row vectors from object
space to world space?
 (b)What about the matrix to transform vectors from world space to object space?
 (c)Express the object's
$z$
axis using upright coordinates.
Upside down
Boy, you turn me
Inside out
And round and round
— Upside Down (1980) by Diana Ross