i
i
i
i
i
i
i
i
Chapter 4
Transforms
“What if angry vectors veer
Round your sleeping head, and form.
There’s never need to fear
Violence of the poor world’s abstract storm.”
—Robert Penn Warren
A transform is an operation that takes entities such as points, vectors, or
colors and converts them in some way. For the computer graphics prac-
titioner, it is extremely important to master transforms. With them, you
can position, reshape, and animate objects, lights, and cameras. You can
also ensure that all computations are carried out in the same coordinate
system, and project objects onto a plane in different ways. These are only a
few of the operations that can be performed with transforms, but they are
sufficient to demonstrate the importance of the transform’s role in real-time
graphics, or, for that matter, in any kind of computer graphics.
A linear transform is one that preserves vector addition and scalar mul-
tiplication. Specifically,
f(x)+f(y)=f(x + y),
kf(x)=f(kx).
(4.1)
As an example, f(x)=5x is a transform that takes a vector and multiplies
each element by five. This type of transform is linear, as any two vectors
multiplied by five and then added will be the same as adding the vectors and
then multiplying. The scalar multiplication condition is clearly fulfilled.
This function is called a scaling transform, as it changes the scale (size) of
an object. The rotation transform is another linear transform that rotates
a vector about the origin. Scaling and rotation transforms, in fact all linear
transforms for 3-element vectors, can be represented using a 3 ×3matrix.
53
i
i
i
i
i
i
i
i
54 4. Transforms
However, this size of matrix is usually not large enough. A function for a
three element vector x such as f(x)=x+(7, 3, 2) is not linear. Performing
this function on two separate vectors will add each value of (7, 3, 2) twice
to form the result. Adding a fixed vector to another vector performs a
translation, e.g., it moves all locations by the same amount. This is a
useful type of transform, and we would like to combine various transforms,
e.g., scale an object to be half as large, then move it to a different location.
Keeping functions in the simple forms used so far makes it difficult to easily
combine them.
Combining linear transforms and translations can be done using an
affine transform, typically stored as a 4 ×4 matrix. An affine transform is
one that performs a linear transform and then a translation. To represent
4-element vectors we use homogeneous notation, denoting points and direc-
tions in the same way (using bold lowercase letters). A direction vector is
represented as v =(v
x
v
y
v
z
0)
T
and a point as v =(v
x
v
y
v
z
1)
T
.
Throughout the chapter, we will make extensive use of the terminology
explained in Appendix A. You may wish to review this appendix now,
especially Section A.4, page 905, on homogeneous notation.
All translation, rotation, scaling, reflection, and shearing matrices are
affine. The main characteristic of an affine matrix is that it preserves
the parallelism of lines, but not necessarily lengths and angles. An affine
transform may also be any sequence of concatenations of individual affine
transforms.
This chapter will begin with the most essential, basic affine trans-
forms. These are indeed very basic, and this section could be seen as a
“reference manual” for simple transforms. More specialized matrices are
then described, followed by a discussion and description of quaternions,
a powerful transform tool. Then follows vertex blending and morphing,
which are two simple but more powerful ways of expressing animations
of meshes. Finally, projection matrices are described. Most of these
transforms, their notations, functions, and properties are summarized in
Table 4.1.
Transforms are a basic tool for manipulating geometry. Most graphics
application programming interfaces (APIs) include matrix operations that
implement many of the transforms discussed in this chapter. However, it
is still worthwhile to understand the real matrices and their interaction
behind the function calls. Knowing what the matrix does after such a
function call is a start, but understanding the properties of the matrix
itself will take you further. For example, such an understanding enables
you to discern when you are dealing with an orthogonal matrix, whose
inverse is its transpose (see page 904), making for faster matrix inversions.
Knowledge like this can lead to accelerated code.
i
i
i
i
i
i
i
i
4.1. Basic Transforms 55
Notation Name Characteristics
T(t) translation matrix Moves a point.
Affine.
R
x
(ρ) rotation matrix Rotates ρ radians
around the x-axis.
Similar notation for
the y-andz-axes.
Orthogonal & affine.
R rotation matrix Any rotation matrix.
Orthogonal & affine.
S(s) scaling matrix Scales along all x-, y-, and
z-axes according to s.
Affine.
H
ij
(s) shear matrix Shears component i by a
factor s,withrespectto
component j.
i, j ∈{x, y, z}.Ane.
E(h, p, r) Euler transform Orientation matrix given
by the Euler angles
head (yaw), pitch, roll.
Orthogonal & affine.
P
o
(s) orthographic projection Parallel projects
onto some plane or to a
volume. Affine.
P
p
(s) perspective projection Projects with perspective
onto a plane or to a
volume.
slerp(
ˆ
q,
ˆ
r,t) slerp transform Creates an interpolated
quaternion with respect to
the quaternions
ˆ
q and
ˆ
r,
and the parameter t.
Table 4.1. Summary of most of the transforms discussed in this chapter.
4.1 Basic Transforms
This section describes the most basic transforms, such as translation, rota-
tion, scaling, shearing, transform concatenation, the rigid-body transform,
normal transform (which is not so normal), and computation of inverses.
For the experienced reader, this can be used as a reference manual for sim-
ple transforms, and for the novice, it can serve as an introduction to the
subject. This material is necessary background for the rest of this chap-
ter and for other chapters in this book. We start with the simplest of
transforms—the translation.
i
i
i
i
i
i
i
i
56 4. Transforms
Figure 4.1. The square on the left is transformed with a translation matrix T(5, 2, 0),
whereby the square is moved 5 distance units to the right and 2 upwards.
4.1.1 Translation
A change from one location to another is represented by a translation ma-
trix, T. This matrix translates an entity by a vector t =(t
x
,t
y
,t
z
). T is
given below by Equation 4.2:
T(t)=T(t
x
,t
y
,t
z
)=
100t
x
010t
y
001t
z
000 1
. (4.2)
An example of the effect of the translation transform is shown in Figure 4.1.
It is easily shown that the multiplication of a point p =(p
x
,p
y
,p
z
, 1) with
T(t) yields a new point p
=(p
x
+ t
x
,p
y
+ t
y
,p
z
+ t
z
, 1), which is clearly
a translation. Notice that a vector v =(v
x
,v
y
,v
z
, 0) is left unaffected by
a multiplication by T, because a direction vector cannot be translated.
In contrast, both points and vectors are affected by the rest of the affine
transforms. The inverse of a translation matrix is T
1
(t)=T(t), that
is, the vector t is negated.
4.1.2 Rotation
A rotation transform rotates a vector (position or direction) by a given
angle around a given axis passing through the origin. Like a translation
matrix, it is a rigid-body transform, i.e., it preserves the distances between
points transformed, and preserves handedness (i.e., it never causes left
and right to swap sides). These two types of transforms are clearly useful
in computer graphics for positioning and orienting objects. An orienta-
tion matrix is a rotation matrix associated with a camera view or object
that defines its orientation in space, i.e., its directions for up and forward.
Commonly-used rotation matrices are R
x
(φ), R
y
(φ), and R
z
(φ), which
i
i
i
i
i
i
i
i
4.1. Basic Transforms 57
rotate an entity φ radians around the x-, y-, and z-axes respectively. They
are given by Equations 4.3–4.5:
R
x
(φ)=
10 0 0
0cosφ sin φ 0
0sinφ cos φ 0
00 0 1
, (4.3)
R
y
(φ)=
cos φ 0sinφ 0
0 100
sin φ 0cosφ 0
0 001
, (4.4)
R
z
(φ)=
cos φ sin φ 00
sin φ cos φ 00
0010
0001
. (4.5)
For every 3 × 3 rotation matrix,
1
R, that rotates φ radians around any
axis, the trace (see page 898 for a definition) is constant independent of
the axis, and is computed as [742]:
tr(R)=1+2cosφ. (4.6)
The effect of a rotation matrix may be seen in Figure 4.4 on page 62. What
characterizes a rotation matrix, R
i
(φ), besides the fact that it rotates φ
radians around axis i, is that it leaves all points on the rotation axis, i,
unchanged. Note that R will also be used to denote a rotation matrix
around any axis. The axis rotation matrices given above can be used in
a series of three transforms to perform any arbitrary axis rotation. This
procedure is discussed in Section 4.2.1. Performing a rotation around an
arbitrary axis directly is covered in Section 4.2.4.
All rotation matrices have a determinant of one and are orthogonal ,
easily verified using the definition of orthogonal matrices given on page
904 in Appendix A. This also holds for concatenations of any number of
these transforms. There is another way to obtain the inverse: R
1
i
(φ)=
R
i
(φ), i.e., rotate in the opposite direction around the same axis. Also,
the determinant of a rotation matrix is always one, since the matrix is
orthogonal.
E
XAMPLE:ROTAT I O N AROUND A POIN T. Assume that we want to rotate
an object by φ radians around the z-axis, with the center of rotation being
a certain point, p. What is the transform? This scenario is depicted in
1
If the bottom row and rightmost column is deleted from a 4 × 4matrix,a3× 3
matrix is obtained.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset