i
i
i
i
i
i
i
i
58 4. Transforms
Figure 4.2. Example of rotation around a specific point p.
Figure 4.2. Since a rotation around a point is characterized by the fact
that the point itself is unaffected by the rotation, the transform starts by
translating the object so that p coincides with the origin, which is done
with T(p). Thereafter follows the actual rotation: R
z
(φ). Finally, the
object has to be translated back to its original position using T(p). The
resulting transform, X,isthengivenby
X = T(p)R
z
(φ)T(p). (4.7)
4.1.3 Scaling
A scaling matrix, S(s)=S(s
x
,s
y
,s
z
), scales an entity with factors s
x
, s
y
,
and s
z
along the x-, y-, and z-directions respectively. This means that a
scaling matrix can be used to enlarge or diminish an object. The larger the
s
i
, i ∈{x, y, z}, the larger the scaled entity gets in that direction. Setting
any of the components of s to 1 naturally avoids a change in scaling in that
direction. Equation 4.8 shows S:
S(s)=
s
x
000
0 s
y
00
00s
z
0
0001
. (4.8)
Figure 4.4 on page 62 illustrates the effect of a scaling matrix. The scaling
operation is called uniform if s
x
= s
y
= s
z
and nonuniform otherwise.
Sometimes the terms isotropic and anisotropic scaling are used instead of
uniform and nonuniform. The inverse is S
1
(s)=S(1/s
x
, 1/s
y
, 1/s
z
).
Using homogeneous coordinates, another valid way to create a uniform
scaling matrix is by manipulating matrix element at position (3, 3), i.e., the
i
i
i
i
i
i
i
i
4.1. Basic Transforms 59
element at the lower right corner. This value affects the w-component of
the homogeneous coordinate, and so scales every coordinate transformed by
the matrix. For example, to scale uniformly by a factor of 5, the elements at
(0, 0), (1, 1), and (2, 2) in the scaling matrix can be set to 5, or the element
at (3, 3) can be set to 1/5. The two different matrices for performing this
are shown below:
S =
5000
0500
0050
0001
, S
=
100 0
010 0
001 0
0001/5
. (4.9)
In contrast to using S for uniform scaling, using S
must always be followed
by homogenization. This may be inefficient, since it involves divides in the
homogenization process; if the element at the lower right (position (3, 3))
is 1, no divides are necessary. Of course, if the system always does this
division without testing for 1, then there is no extra cost.
A negative value on one or three of the components of s gives a re-
flection matrix, also called a mirror matrix.
2
If only two scale factors are
1, then we will rotate π radians. Reflection matrices usually require spe-
cial treatment when detected. For example, a triangle with vertices in a
counterclockwise order will get a clockwise order when transformed by a
reflection matrix. This order change can cause incorrect lighting and back-
face culling to occur. To detect whether a given matrix reflects in some
manner, compute the determinant of the upper left 3 × 3elementsofthe
matrix. If the value is negative, the matrix is reflective.
E
XAMPLE:SCALING IN A CERTAIN DIRECTION . The scaling matrix S scales
along only the x-, y-, and z-axes. If scaling should be performed in other
directions, a compound transform is needed. Assume that scaling should
be done along the axes of the orthonormal, right-oriented vectors f
x
, f
y
,
and f
z
. First, construct the matrix F as below:
F =
f
x
f
y
f
z
0
0001
. (4.10)
The idea is to make the coordinate system given by the three axes coincide
with the standard axes, then use the standard scaling matrix, and then
transform back. The first step is carried out by multiplying with the trans-
pose, i.e., the inverse, of F. Then the actual scaling is done, followed by a
transform back. The transform is shown in Equation 4.11:
X = FS(s)F
T
. (4.11)
2
According to some definitions of a reflection matrix, the negative component(s) must
equal 1.
i
i
i
i
i
i
i
i
60 4. Transforms
Figure 4.3. The effect of shearing the unit square with H
xz
(s). Both the y-andz-values
are unaffected by the transform, while the x-value is the sum of the old x-value and s
multiplied by the z-value, causing the square to be tilted.
4.1.4 Shearing
Another class of transforms is the set of shearing matrices. These can,
for example, be used in games to distort an entire scene in order to cre-
ate a psychedelic effect or to create fuzzy reflections by jittering (see Sec-
tion 9.3.1). There are six basic shearing matrices,
3
and they are denoted
H
xy
(s), H
xz
(s), H
yx
(s), H
yz
(s), H
zx
(s), and H
zy
(s). The first subscript
is used to denote which coordinate is being changed by the shear matrix,
while the second subscript indicates the coordinate which does the shear-
ing. An example of a shear matrix, H
xz
(s), is shown in Equation 4.12.
Observe that the subscript can be used to find the position of the param-
eter s in the matrix below; the x (whose numeric index is 0) identifies row
zero, and the z (whose numeric index is 2) identifies column two, and so
the s is located there:
H
xz
(s)=
10s 0
0100
0010
0001
. (4.12)
The effect of multiplying this matrix with a point p yields a point: (p
x
+
sp
z
p
y
p
z
)
T
. Graphically, this is shown for the unit square in Figure 4.3.
The inverse of H
ij
(s)(shearingtheith coordinate with respect to the jth
coordinate, where i = j), is generated by shearing in the opposite direction,
that is, H
1
ij
(s)=H
ij
(s).
3
Actually, there are only six shearing matrices, because we shear in planes orthogonal
to the main axes. However, a general shear matrix can shear orthogonally to any plane.
i
i
i
i
i
i
i
i
4.1. Basic Transforms 61
Some computer graphics texts [348, 349] use a slightly different kind of
shear matrix:
H
xy
(s, t)=
10s 0
01t 0
0010
0001
. (4.13)
Here, however, both subscripts are used to denote that these coordinates
are to be sheared by the third coordinate. The connection between these
two different kinds of descriptions is H
ij
(s, t)=H
ik
(s)H
jk
(t), where k is
used as an index to the third coordinate. The right matrix to use is a
matter of taste and API support.
Finally, it should be noted that since the determinant of any shear
matrix |H| = 1, this is a volume preserving transformation.
4.1.5 Concatenation of Transforms
Due to the noncommutativity of the multiplication operation on matrices,
the order in which the matrices occur matters. Concatenation of transforms
is therefore said to be order-dependent.
As an example of order dependency, consider two matrices, S and R.
S(2, 0.5, 1) scales the x-component by a factor two and the y-component
by a factor 0.5. R
z
(π/6) rotates π/6 radians counterclockwise around the
z-axis (which points outwards from page of this book). These matrices can
be multiplied in two ways, with the results being totally different. The two
cases are shown in Figure 4.4.
The obvious reason to concatenate a sequence of matrices into a single
one is to gain efficiency. For example, imagine that you have an object that
has several thousand vertices, and that this object must be scaled, rotated,
and finally translated. Now, instead of multiplying all vertices with each
of the three matrices, the three matrices are concatenated into a single
matrix. This single matrix is then applied to the vertices. This composite
matrix is C = TRS. Note the order here: The scaling matrix, S, should
be applied to the vertices first, and therefore appears to the right in the
composition. This ordering implies that TRSp =(T(R(Sp))).
4
It is worth noting that while matrix concatenation is order-dependent,
the matrices can be grouped as desired. For example, say that with TRSp
you would like to compute the rigid-body motion transform TR once. It
4
Another valid notational scheme sometimes seen in computer graphics uses matrices
with translation vectors in the bottom row. In this scheme, the order of matrices would
be reversed, i.e., the order of application would read from left to right. Vectors and
matrices in this notation are said to be in row-major form since the vectors are rows. In
this book, we use column-major form.
i
i
i
i
i
i
i
i
62 4. Transforms
Figure 4.4. This illustrates the order dependency when multiplying matrices. In the
top row, the rotation matrix R
z
(π/6) is applied followed by a scaling, S(s), where
s =(2, 0.5, 1). The composite matrix is then S(s)R
z
(π/6). In the bottom row, the
matrices are applied in the reverse order, yielding R
z
(π/6)S(s). The results are clearly
different. It generally holds that MN = NM, for arbitrary matrices M and N.
is valid to group these two matrices together, (TR)(Sp), and replace with
the intermediate result. Thus, matrix concatenation is associative.
4.1.6 The Rigid-Body Transform
When a person grabs a solid object, say a pen from a table, and moves it to
another location, perhaps to her shirt pocket, only the object’s orientation
and location change, while the shape of the object generally is not affected.
Such a transform, consisting of concatenations of only translations and
rotations, is called a rigid-body transform and has the characteristic of
preserving lengths, angles, and handedness.
Any rigid-body matrix, X, can be written as the concatenation of a
translation matrix, T(t), and a rotation matrix, R.Thus,X has the
appearance of the matrix in Equation 4.14:
X = T(t)R =
r
00
r
01
r
02
t
x
r
10
r
11
r
12
t
y
r
20
r
21
r
22
t
z
0001
. (4.14)
The inverse of X is computed as X
1
=(T(t)R)
1
= R
1
T(t)
1
=
R
T
T(t). Thus, to compute the inverse, the upper left 3 ×3matrixofR
is transposed, and the translation values of T change sign. These two new
matrices are multiplied together in opposite order to obtain the inverse.
..................Content has been hidden....................

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