i
i
i
i
i
i
i
i
134 6. A Pocket 3D Theory Reference
This transformation will allo w us to move the point with coordinates (x, y, z)
to the point with coordinates (x + dx, y + dy, z + dz). That is, the translated
point becomes p
= T
t
p or
x + dx
y + dy
z + dz
1
=
100dx
010dy
001dz
000 1
x
y
z
1
.
6.6.2 Scaling
Scaling is represented by the general transformation matrix:
T
s
=
s
x
000
0 s
y
00
00s
z
0
0001
.
Essentially this allows us to scale (expand or contract) a position vector p
with components (x, y, z) by the factors s
x
along the x-axis, s
y
along the y-
axis and s
z
along the z-axis. Thus, for example, if we scaled the three vertex
positions of a polygon, we could effectively change its size, i.e., make it larger
or smaller. The scaled point p
is given by p
= T
s
p or
xs
x
ys
y
zs
z
1
=
s
x
000
0 s
y
00
00s
z
0
0001
x
y
z
1
.
6.6.3 Rotation
In two dimensions, there is only one way to rotate, and it is around a point.
In three dimensions, we rotate around axes instead, and there are three of
them to consider, each bearing different formulae. Thus a rotation is spec-
ified by both an axis of rotation and the angle of the rotation. It is a fairly
simple trigonometric calculation to obtain a transformation matrix for a rota-
tion about one of the coordinate axes. When the rotation is to be performed
around an arbitrary vector based at a given point, the transformation matrix
must be assembled from a combination of r otations about the Cartesian co-
ordinate axes and possibly a translation. This is outlined in more detail in
Section 6.6.5.
i
i
i
i
i
i
i
i
6.6. Transformations 135
Figure 6.11. Rotations, anticlockwise looking along the axis of rotation, towards the
origin.
Rotate About the z-Axis
To rotate round the z-axis by an angle , the transformation matrix is
T
z
( ) =
cos
sin 00
sin
cos 00
0010
0001
. (6.6)
We can see how the rotational transformations are obtained by consid-
ering a positive (anticlockwise) rotation of a point P by
round the z-axis
(which points out of the page). Before rotation, P lies at a distance l from the
origin and at an angle
to the x-axis(seeFigure6.12).The(x, y)-coordinate
of P is (l cos , l sin ). After rotation by , P is moved to P
and its coordi-
nates are (l cos( + ), l sin( + )). Expanding the trigonometric sum gives
expressions for the coordinates of P
:
P
x
= l cos cos l sin sin ,
P
y
= l cos sin + l sin cos .
Since l cos
is the x-coordinate of P and l sin is the y-coordinate of P,
the coordinates of P
becomes
i
i
i
i
i
i
i
i
136 6. A Pocket 3D Theory Reference
Figure 6.12. Rotation of point P by an angle θ round the z-axis.
P
x
= P
x
cos P
y
sin ,
P
y
= P
x
sin + P
y
cos .
Writing this in matrix form, we have
P
x
P
y
=
cos sin
sin cos

P
x
P
y
.
There is no change in the z-component of P, and thus this result can
be expanded into the familiar 4 × 4 matrix form by simply inserting the
appropriate terms to give
P
x
P
y
P
z
1
=
cos
sin 00
sin
cos 00
0010
0001
P
x
P
y
P
z
1
.
Rotation About the y-Axis
To rotate round the y-axis by an angle , the transformation m atrix is
T
y
( ) =
cos
0 sin 0
0 100
sin
0cos 0
0 001
.
i
i
i
i
i
i
i
i
6.6. Transformations 137
Again, it is possible to derive this transformation using the principles
described previously for rotation around the z-axis, as can the transformation
for the rotation about the x-axis.
Rotation About the x-Axis
To rotate round the x-axis by an angle , the transformation matrix is
T
x
( ) =
10 0 0
0cos sin 0
0 sin
cos 0
00 0 1
.
Note that as illustrated in Figure 6.11,
is positive if the rotation
takes place in a clockwise sense when looking from the origin along the
axis of rotation. This is consistent with a right-handed coordinate
system.
6.6.4 Combining Transformations
Section 6.6 introduced the key concept of a transformation applied to a po-
sition vector. In many cases, we are interested in what happens when several
operations are applied in sequence to a model or one of its points (vertices).
For example, move the point P 10 units forward, r otate it 20 degrees round the
z-axis and shift it 15 units along the x-axis. Each transformation is represented
by a single 4 ×4 matrix, and the compound transformation is constructed as
a sequence of single transformations as follows:
p
= T
1
p;
p

= T
2
p
;
p

= T
3
p

.
Where p
and p

are intermediate position vectors and p

is the end
vector after the application of the three transformations. The above sequence
can be combined into
p

= T
3
T
2
T
1
p.
The product of the transformations T
3
T
2
T
1
gives a single matrix T .Com-
bining transformations in this way has a wonderful efficiency: if a large model
has 50,000 vertices and we need to apply 10 transformations, by combining
i
i
i
i
i
i
i
i
138 6. A Pocket 3D Theory Reference
Figure 6.13. Effect of transformations applied in a different order.
the transformations into a single matrix, 450,000 matrix multiplications can
be av oided.
It is important to remember that the result of applying a sequence of
transformations depends on the order in which they are applied. T
3
T
2
T
1
is
not the same compound transformation as T
2
T
3
T
1
. Figure 6.13 shows the
effect of applying the transformations in a different or der.
There is one subtle point about transformations that ought to be stressed.
The parameters of a transformation (angle of rotation etc.) are all relative
to a global frame of reference. It is sometimes useful to think in terms of
a local frame of reference that is itself transformed relative to a global frame.
This idea will be explored when we discuss keyframe and character animation.
However, it is important to bear in mind that when a final scene is assembled
for rendering, all coordinates must be specified in the same frame of refer ence.
6.6.5 Rotation About an Arbitrary Axis
The transformation corresponding to rotation of an angle around an ar-
bitrary vector (for example, that shown between the two points P
0
and P
1
in Figure 6.14) cannot readily be written in a form similar to the rotation
matrices about the coordinate axes.
The desired transformation matrix is obtained by combining a sequence
of basic translation and rotation matrices. (Once a single 4 × 4 matrix h as
..................Content has been hidden....................

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