i
i
i
i
i
i
i
i
136 6. Transformation Matrices
the coordinates of the city geometry, expressing them as coordinates in the car’s
coordinate system. Both ways will lead to exactly the same matrix that is applied
to the geometry outside the car.
If the game also supports an overhead view to show where the car is in the
city, the buildings and streets need to be drawn in xed positions while the car
needs to move from frame to frame. The same two interpretations apply: we
can think of the changing transformation as moving the car from its canonical
position to its current location in the world; or we can think of the transformation
as simply changing the coordinates of the car’s geometry, which is originally
expressed in terms of a coordinate system attached to the car, to express them
instead in a coordinatesystem xed relative to the city. The change-of-coordinates
interpretation makes it clear that the matrices used in these two modes (city-to-car
coordinate change vs. car-to-city coordinate change) are inverses of one another.
The idea of changing coordinate systems is much like the idea of type conver-
sions in programming. Before we can add a oating-point number to an integer,
we need to convert the integer to oating point or the oating-point number to an
integer, depending on our needs, so that the types match. And before we can draw
the city and the car together, we need to convert the city to car coordinates or the
car to city coordinates, depending on our needs, so that the coordinates match.
When managing multiple coordinate systems, it’s easy to get confused and
wind up with objects in the wrong coordinates, causing them to show up in un-
expected places. But with systematic thinking about transformations between
coordinate systems, you can reliably get the transformations right.
Geometrically, a coordinate system, or coordinate frame, consists of an origin
and a basis—a set of three vectors. Orthonormal bases are so convenient that
In 2D, of course, there are
two basis vectors.
we’ll normally assume frames are orthonormal unless otherwise specied. In a
frame with origin p and basis {u, v, w}, the coordinates (u, v, w) describe the
point
p + uu + vv + ww.
When we store these vectors in the computer, they need to be represented in
terms of some coordinate system. To get things started, we have to designate
some canonical coordinate system, often called “global” or “world” coordinates,
which is used to describe all other systems. In the city example, we might adopt
the street grid and use the convention that the x-axis points along Main Street,
the y-axis points up, and the z-axis points along Central Avenue. Then when we
write the origin and basis of the car frame in terms of these coordinates it is clear
what we mean.
In 2D our convention is is to use the point o for the origin, and x and y for
In 2D, right handed means
y is counter-clockwise from
x.
the right-handed orthonormal basis vectors x and y (Figure 6.20).
i
i
i
i
i
i
i
i
6.5. Coordinate Transformations 137
Figure 6.20. The point p can be represented in terms of either coordinate system.
Another coordinate system might have an origin e and right-handed orthonor-
mal basis vectors u and v. Note that typically the canonical data o, x,andy are
never stored explicitly. They are the frame-of-reference for all other coordinate
systems. In that coordinate system, we often write down the location of p as an
ordered pair, which is shorthand for a full vector expression:
p =(x
p
,y
p
) o + x
p
x + y
p
y.
For example, in Figure 6.20, (x
p
,y
p
)=(2.5, 0.9). Note that the pair (x
p
,y
p
)
implicitly assumes the origin o. Similarly, we can express p in terms of another
equation:
p =(u
p
,v
p
) e + u
p
u + v
p
v.
In Figure 6.20, this has (u
p
,v
p
)=(0.5, 0.7). Again, the origin e is left as an
implicit part of the coordinate system associated with u and v.
We can express this same relationship using matrix machinery, like this:
x
p
y
p
1
=
10x
e
01y
e
00 1
x
u
x
v
0
y
u
y
v
0
001
u
p
v
p
1
=
x
u
x
v
x
e
y
u
y
v
y
e
001
u
p
v
p
1
.
Note that this assumes we have the point e and vectors u and v stored in canonical
coordinates; the (x, y)-coordinate system is the rst among equals. In terms of the
basic types of transformations we’ve discussed in this chapter, this is a rotation
(involving u and v) followed by a translation (involving e). Looking at the matrix
for the rotation and translation together, you can see it’s very easy to write down:
we just put u, v,ande into the columns of a matrix, with the usual [0 0 1] in the
third row. To make this even clearer we can write the matrix like this:
p
xy
=
uve
001
p
uv
.
We call this matrix the frame-to-canonical matrix for the (u, v) frame. It takes
points expressed in the (u, v) frame and converts them to the same points ex-
pressed in the canonical frame.
The name “frame-to-
canonical” is based on
thinking about changing
the coordinates of a vector
from one system to an-
other. Thinking in terms of
moving vectors around, the
frame-to-canonical matrix
maps the canonical frame
to the (
u
,
v
)frame.
i
i
i
i
i
i
i
i
138 6. Transformation Matrices
To go in the other direction we have
u
p
v
p
1
=
x
u
y
u
0
x
v
y
v
0
001
10x
e
01y
e
00 1
x
p
y
p
1
.
This is a translation followed by a rotation; they are the inverses of the rotation and
translation we used to build the frame-to-canonical matrix, and when multiplied
together they produce the inverse of the frame-to-canonical matrix, which is (not
surprisingly) called the canonical-to-frame matrix:
p
uv
=
uve
001
1
p
xy
.
The canonical-to-frame matrix takes points expressed in the canonical frame and
converts them to the same points expressed in the (u,v) frame. We have written
this matrix as the inverse of the frame-to-canonical matrix because it can’t im-
mediately be written down using the canonical coordinates of e, u,andv .But
remember that all coordinate systems are equivalent; it’s only our convention of
storing vectors in terms of x-andy-coordinates that creates this seeming asym-
metry. The canonical-to-frame matrix can be expressed simply in terms of the (u,
v) coordinates of o, x,andy:
p
uv
=
x
uv
y
uv
o
uv
001
p
xy
.
All these ideas work strictly analogously in 3D, where we have
x
p
y
p
z
p
1
=
100x
e
010y
e
001z
e
000 1
x
u
x
v
x
w
0
y
u
y
v
y
w
0
z
u
z
v
z
w
0
0001
u
p
v
p
w
p
1
p
xyz
=
uvwe
0001
p
uvw
,
(6.8)
and
u
p
v
p
w
p
1
=
x
u
y
u
z
u
0
x
v
y
v
z
v
0
x
w
y
w
z
w
0
0001
100x
e
010y
e
001z
e
000 1
x
p
y
p
z
p
1
p
uvw
=
uvwe
0001
1
p
xyz
.
(6.9)
i
i
i
i
i
i
i
i
6.5. Coordinate Transformations 139
Frequently Asked Questions
Can’t I just hardcode transforms rather than use the matrix formalisms?
Yes, but in practice it is harder to derive, harder to debug, and not any more ef-
cient. Also, all current graphics APIs use this matrix formalism so it must be
understood even to use graphics libraries.
The bottom row of the matrix is always (0,0,0,1). Do I have to store it?
You do not have to store it unless you include perspective transforms (Chapter 7).
Notes
The derivation of the transformation properties of normals is based on Proper-
ties of Surface Normal Transformations (Turkowski, 1990). In many treatments
through the mid-1990s, vectors were represented as row vectors and premulti-
plied, e.g., b = aM. In our notation this would be b
T
= a
T
M
T
. If you want to
nd a rotation matrix R that takes one vector a to a vector b of the same length:
b = Ra you could use two rotations constructed from orthonormalbases. A more
efcient method is given in Efficiently Building a Matrix to Rotate One Vector to
Another (Akenine-M¨oller et al., 2008).
Exercises
1. Write down the 4 ×4 3D matrix to move by (x
m
,y
m
,z
m
).
2. Write down the 4 ×4 3D matrix to rotate by an angle θ about the y-axis.
3. Write down the 4 ×4 3D matrix to scale an object by 50% in all directions.
4. Write the 2D rotation matrix that rotates by 90 degrees clockwise.
5. Write the matrix from Exercise 4 as a product of three shear matrices.
6. Find the inverse of the rigid body transformation:
Rt
000 1
where R is a 3 ×3 rotation matrix and t is a 3-vector.
i
i
i
i
i
i
i
i
140 6. Transformation Matrices
7. Show that the inverse of the matrix for an afne transformation (one that
has all zeros in the bottom row except for a one in the lower right entry)
also has the same form.
8. Describe in words what this 2D transform matrix does:
0 11
101
001
.
9. Write down the 3×3 matrix that rotates a 2D point by angle θ about a point
p =(x
p
,y
p
).
10. Write down the 4 ×4 rotation matrix that takes the orthonormal 3D vectors
u =(x
u
,y
u
,z
u
), v =(x
v
,y
v
,z
v
),andw =(x
w
,y
w
,z
w
), to orthonormal
3D vectors a =(x
a
,y
a
,z
a
), b =(x
b
,y
b
,z
b
),andc =(x
c
,y
c
,z
c
),So
Mu = a, M v = b,andM w = c.
11. What is the inverse matrix for the answer to the previous problem?
..................Content has been hidden....................

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