i
i
i
i
i
i
i
i
6
Transformation Matrices
The machinery of linear algebra can be used to express many of the operations
required to arrange objects in a 3D scene, view them with cameras, and get them
onto the screen. Geometric transformations like rotation, translation, scaling, and
projection can be accomplished with matrix multiplication, and the transforma-
tion matrices used to do this are the subject of this chapter.
We will show how a set of points transforms if the points are represented as
offset vectors from the origin, and we will use the clock shown in Figure 6.1 as
an example of a point set. So think of the clock as a bunch of points that are the
ends of vectors whose tails are at the origin. We also discuss how these transforms
operate differently on locations (points), displacement vectors, and surface normal
vectors.
6.1 2D Linear Transformations
We can use a 2 × 2 matrix to change, or transform, a 2D vector:
a
11
a
12
a
21
a
22

x
y
=
a
11
x + a
12
y
a
21
x + a
22
y
.
This kind of operation, which takes in a 2-vector and produces another 2-vector
by a simple matrix multiplication, is a linear transformation.
By this simple formula we can achieve a variety of useful transformations,
depending on what we put in the entries of the matrix, as will be discussed in
111
i
i
i
i
i
i
i
i
112 6. Transformation Matrices
the following sections. For our purposes, consider moving along the x-axis a
horizontal move and along the y-axis, a vertical move.
6.1.1 Scaling
The most basic transform is a scale along the coordinate axes. This transform can
change length and possibly direction:
scale(s
x
,s
y
) =
s
x
0
0 s
y
.
Note what this matrix does to a vector with Cartesian components (x, y):
s
x
0
0 s
y

x
y
=
s
x
x
s
y
y
.
So just by looking at the matrix of an axis-aligned scale we can read off the two
scale factors.
Example. The matrix that shrinks x and y uniformly by a factor of two is (Fig-
ure 6.1)
scale(0.5, 0.5) =
0.50
00.5
.
A matrix which halves in the horizontal and increases by three-halves in the ver-
tical is (see Figure 6.2)
scale(0.5, 1.5) =
0.50
01.5
.
Figure 6.1. Scaling uniformly by half for each axis: The axis-aligned scale matrix has
the proportion of change in each of the diagonal elements and zeroes in the off-diagonal
elements.
i
i
i
i
i
i
i
i
6.1. 2D Linear Transformations 113
Figure 6.2. Scaling non-uniformly in
x
and
y
: The scaling matrix is diagonal with non-equal
elements. Note that the square outline of the clock becomes a rectangle and the circular
face becomes an ellipse.
6.1.2 Shearing
A shear is something that pushes things sideways, producing something like a
deck of cards across which you push your hand; the bottom card stays put and
cards move more the closer they are to the top of the deck. The horizontal and
vertical shear matrices are
shear-x(s) =
1 s
01
, shear-y(s) =
10
s 1
.
Example. The transform that shears horizontally so that vertical lines become 45
lines leaning towards the right is (see Figure 6.3)
shear-x(1) =
11
01
.
Figure 6.3. An
x
-shear matrix moves points to the right in proportion to their
y
-coordinate.
Now the square outline of the clock becomes a parallelogram and, as with scaling, the circular
face of the clock becomes an ellipse.
i
i
i
i
i
i
i
i
114 6. Transformation Matrices
Figure 6.4. A
y
-shear matrix moves points up in proportion to their
x
-coordinate.
An analogous transform vertically is (see Figure 6.4)
shear-y(1) =
10
11
.
In both cases the square outline of the sheared clock becomes a parallelogram,
In fact, the image of a cir-
cle under any matrix trans-
formation is an ellipse.
and the circular face of the sheared clock becomes an ellipse.
Another way to think of a shear is in terms of rotation of only the vertical
(or horizontal) axes. The shear transform that takes a vertical axis and tilts it
clockwise by an angle φ is
1tanφ
01
.
Similarly, the shear matrix which rotates the horizontal axis counterclockwise by
angle φ is
10
tan φ 1
.
6.1.3 Rotation
Suppose we want to rotate a vector a by an angle φ counterclockwise to get
vector b (Figure 6.5). If a makes an angle α with the x-axis, and its length is
r = x
2
a
+ y
2
a
, then we know that
x
a
= r cos α,
y
a
= r sin α.
i
i
i
i
i
i
i
i
6.1. 2D Linear Transformations 115
Because b is a rotation of a, it also has length r. Because it is rotated an angle
φ from a, b makes an angle (α + φ) with the x-axis. Using the trigonometric
addition identities (Section 2.3.3):
Figure 6.5. The geometry
for Equation (6.1).
x
b
= r cos(α + φ)=r cos α cos φ r sin α sin φ,
y
b
= r sin(α + φ)=r sin α cos φ + r cos α sin φ.
(6.1)
Substituting x
a
= r cos α and y
a
= r sin α gives
x
b
= x
a
cos φ y
a
sin φ,
y
b
= y
a
cos φ + x
a
sin φ.
In matrix form, the transformation that takes a to b is then
rotate(φ) =
cos φ sin φ
sin φ cos φ
.
Example. A matrix that rotates vectors by π/4 radians (45 degrees) is (see Fig-
ure 6.6)
cos
π
4
sin
π
4
sin
π
4
cos
π
4
=
0.707 0.707
0.707 0.707
.
(0,1)
(0,1)
(-.707,.707)
(.707,.707)
Figure 6.6. A rotation by 45 degrees. Note that the rotation is counterclockwise and that
cos(45
) = sin(45
) .707.
A matrix that rotates by π/6 radians (30 degrees) in the clockwise direction is
a rotation by π/6 radians in our framework (see Figure 6.7):
cos
π
6
sin
π
6
sin
π
6
cos
π
6
=
0.866 0.5
0.50.866
.
..................Content has been hidden....................

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