5
Geometrical
Transformations
This chapter introduces the basic 2D and 3D geomeu-ical transformations used in
computer gr•phics. The translation. scaling, and rotalion transformations discussed here
arc essential 10 many graphics applications and will be referred 10 extensively io
succeeding chapters. The transformations are used directly by application progrorns
and within many graphics subroutine packages. A city-planning application program .,.uuld
use uanslation LO place symbols for buildings and crees at appropriate positions,
rotation to orient the symbols. and scaling Lo size the symbols. rn general, many
applications use lhe geometric lrllnsformations tochange the position, orientation, and
size of objects (also called symbols or1empla1es) in a drawing. In Chapter 6, 3D
rotation, translation. and scaling will be used as pan of the process of creating 2D
renditions of 30 objects. In Chapter 7, we see how a contemporary grophics package
uses uansformntions as pan of iLS implementation and also
makes them available 10 application programs.
5.1 2D TRANSFORMATIONS
Wecan1ro11sla1e points in the (x, y) plane to new positions by adding translation amounts LO
thecoordinates oflhe poinLS. Foreacll point P(x,y) to be moYCd byd, units parallel 10
lhcx axis and by d, units parallel to lhe y axis to !he new point P'(x. y'), we can write
;c' = X + d,, y' = y + d,. (5.1)
If we define the column vectors
(5.2)
201
202 Geometrical Transfonnations
y y
(4,
Cl 5) ( 7, 5)
(7, 1i..,..,..110, 1)
L..L-'-'---'-'....., ......_......., ._.... ._.. x
Before translation After translation
Fig. 5.1 Translation of a house.
then (5. I) can be expressed more concisely as
P' = P + T. (5.3)
We couJd translate an object by applying Eq. (5.1) toevery point of theobject. Because
each line in an object is made up of an infinite number of points, however, this process
=uld talce an infinitely long time. Fortunately, we can translate aU the points on a line
by translating only the line's endpoints and by drawing a new line between the
translated endpoints; this is also true of scaling (stretching) and rotation. Figure 5.1
shows the effect of translating the outline of a house by (3, -4).
Points can be scaled (stretched) bys. along thex axis and by Sr along they axis into
new
points by the multiplications
x' = s, • X, y' = s,. y. (5.4)
In matrix form, this is
[;'.] = [ci !]·[;] or P' = S • P, (5.5)
where S is the matrix in Eq. (5.5).
In Fig. 5.2, the house is scaled by½in x and¼in y. Notice that the scaling is about
the origin: The house is smaller and is closer to theorigin. If thescale factors were greater
than I, the house =uld be both larger and further from the origjn. Techniques for scaling
about some point other than the origin are discussed in Section 5.2. The proportions of
[Link] have also changed: a differential scaling, in which s, ,l s,, has been used. With
a uniform
scaling, in which s, = s,, the proportions are unaffected.
y y
(4
Cl , 5) (7, 5)
'--'--'-'- . . . . ._._._. X.
Before scaling After scaling
Fig. 5.2 Scaling of a house. The scaling is nonuniform, and the house changes
position.
5.1 20 Transformations 203
y y
(4.9, 7.8)
L..L..L..1...1..L--'--'-'-'-'-.._•x L..L..L..I....... ...L.I....L.L...I...L...+ )C
Before rotation After rotation
Fig. 5.3 Rotation of a house. The house also changes position.
Points can be rotated through an angle e about the origin. A rotation is defined
mathematicalJy by
X
1
= X' cose - y • Sine, y' = X • sine + y • cose. (5.6)
In matrix form, we have
[X] or =R.
[yx'']
[cose -sine] . P' p
sine cose y ' (5.7)
where R is the rotation matrix in Eq. (5.7). Figure 5.3 shows the rotation of the house
=
by 45°. As with scaling, rotation is about the origin; rotation about an arbitrary point is
discussed in Section 5.2.
Positive angles are measured counterclockwise from x toward y. For negative (clock
wise) angles, the identities cos(-8) = cose and sin(-8) = -sine can be used to modify
Eqs. (5.6) and (5.7).
Equation (5.6) is easilyderived from Fig. 5.4, in which a rotation by etransforms P(x,
y) into P'(x',y'). Because the rotation is about theorigin, thedistances from'the origin to P
and to P', labeled r in the figure, are equal. By simple trigonometry, we find that
x = r • cos<J,, y = r • sin</> (5.8)
and
x' = r • cos(e + 4') = r • cos<J, • cose - r • sin</> • sine,
(5.9)
y' = r • sin(l:I + 4') = r • cos<J, • sinl:I + r • sin</> • cose.
Substituting Eq. (5.8) into Eq. (5.9) yields Eq. (5.6).
P{x', y')
P<,x, y)
roos (9 + ;) rcos;
Fig. 5.4 Derivation of the rotation equation.
204 Geometrical Transformations
5.2 HOMOGENEOUS COORDINATES AND MATRIX
REPRESENTATION OF 2D TRANSFORMATIONS
The matrix representations for translation, scaling, and rotation are, respectively,
P' = T + P, (5.3)
P' = S • P, (5.5)
P' = R • P. (5.7)
Unfortunately, translation is treated differently (as an addition) from scaling and rotation
(as multiplications). We would like to be able to treat all three transfonnations in a
consistent way, so that they can be combined easily.
If points are expressed in homogeneous coordinates, all three transfonnations can be
treated as multiplications. Homogeneous coordinates were first developed in geometry
[MAXW46; MAXWSI] and have been applied subsequently in graphics [ROBE65;
BLIN77b; BLIN78a]. Numerous graphics subroutine packages and display processors work
with homogeneous coordinates and transformations.
In homogeneous coordinates, we add a third coordinate to a point. Instead of being
represented by a pair of numbers (x, y), each point is represented by a triple(x, y, W). At
the
same time, we say that two sets of homogeneous coordinates (x, y, W) and (x', y', W')
represent the same point if and only if one is a multiple of theother. Thus, (2, 3, 6) and
(4, 6, 12)are the same points represented by different coordinate triples. That is, each point
has many different homogeneous coordinate representations. Also, at least one of the
homogeneous coordinates must be nonzero: (0, 0, 0) is not allowed. If the W coordinate
is nonzero, we can divide through by it: (x, y, W) representS the same point as (x!W,
y/W, I).
When Wis nonzero, we nonnally do this division, and the numbers x/W and y/W are called
the Cartesian coordinates of the homogeneous point. The points with W = 0 are called
pointS at infinity, and will not appear very often in our [Link].
Triples of coordinates typically represent pointS in 3-space, but here we are using them
to represent points in 2-space. The connection is this: If we take all the triples
representing the same point-that is, all triples of the fonn (rx, ry, rW), with I cl 0-we
get a line in 3-space. Thus, each homogeneous poim represents a line in 3-space. If we
homogenize the
point (divide by W), we get a point of the form (x, y, I). Thus, the homogenized pointS
fonn the plane defined by the equation W = I in (x, y, W)-space. Figure 5.5 shows this
w p
W = 1 plane
y
Fig. 5.5 The XYW homogeneous coordinate space, with the W = 1 plane and point
P(X, Y, W) projected onto the W = 1 plane.
Coordinates and Matrix Representation of 20 Transformations 206
relationship. ints atinfinity are not represented on this plane.
Because points are now three-clement column vectors, transformation matrices, which
multiply a point vector to produce another point vector, must be 3 x 3. In lhe 3 x 3 matrix
form for homogeneous coordinates, the translation equations Eq. (5.1) are
(5.10)
Wecaution the reader that some graphics textbooks, including (FOLE82), use a convention
of premultlplying matrices by row vectors, rather than postmultlplyingby column vectors.
Matrices must be ttansposcd to go from one convention to the other, just as the row and
column vectors are transposed:
Equation (5. I0) can be expressed differently as
P' = T(d., d.,) • P, (5.11)
T(d., d,) = I
O0 ldd,, (5.12)
I .
[
0 0 I
What happens if a point P is translated byT(d"', d11) to P' and then rranslated by T(d,,,
d.,J to P"?The result we c:Jtpect intuitively is a net translation T(d,, + d,,, d,, + d.,,).
To confirm this intuition, we start with the givens:
P' = T(d..,, d") • P, (5.13)
P" = T (dn, d.,,) • P'. (5.14)
Now, substituting Eq. (5.13) into Eq. (5.14), we obtain
P" = T(d,,,, dy,) • (T(d,., d1,) • P) = (T(d.,, d.,,) • T(d," d,,)) • P. (5.15)
The matri,t product T(d,,. d.,,) • T(d,,, d,,> is
I O
O ld
d.,]· [ I
OO 0 d,, +d.,l
I d,.+dr,. (5.16)
d •11] - [ I
[ l d , , - 0
001 001 0 0 I
The net translation is indeed T(d., + d,., d,, + dy,). The matrix product is variously
referred to as the compounding, catenation, [Link] composition ofT(d,.,d1,)
and T(d,,, dr,). Here, we shall normaHy use the term composition.
Similarly, the scaling equations Eq. (5.4) are represented in matrix form as
(5.17)
208 Geometrical Transformations
Defining
s, 0 OJ
S(s,. sJ 0 s, 0 , (5.18)
=[ 0 0 I
we have
P' = S(s,, s,) • P. (5.19)
Just as [Link] are additive, weexpect that successive scalings should be
multiplicative. Given
P' = S(s,,. s,.) •
(5.20)
P,
(5.21)
P" = S(s.,, s,J •
P',
then, substituting Eq. (5.20) int.o Eq. (5.21). we get
P" = S(s.,, s,,) • (S(s.. , s,,) • P) = (S(s.,, s,,) • S(s,., s,,)) • (5.22)
P.
'The matrix product S(s.,, s,J • S(s.,, s,,) is
s, , O s., s,,0•
0 0 O J [s " [s.,• O (5.23)
[ s,, 0 • 0
0 =
0 s,,
J0
0 .
s,, J
001 001 0 0 I
Thus, the scalings arc indeed multipUcative.
Finally, the rotation equations Eq. (5.6) can be represented as
x y ' 'J
[ =[ - 0OJ • (5.24)
s9m9 csois [xyJ .
n99
I O O I I
Letting
cos9 -sin9
R(6) = sin9 cos9 (5.25)
[ 0 0
we have
P' = R(9) • P. (5.26)
Showing that IWO successive rorations are additive is left as Exercise 5.2.
In the upper-left 2 x 2 submalrix of Eq. (5.25), consider each of the two rows as
vec1ors. 'The vectors can be shown to have three properties:
I. Each is a unit YCCtor
2. Each is perpendicular to the other (their dot product is [Link]'O)
3. The 6m and second vcctors will be rotated by R(6) to Iie on the positive x and
y axes, respectively (in the presence of conditions I and 2, this is equivalent to
thesubmalrix having a determinant of I).
6.2 Coordinates and Matrix Representation of 20 Transformations 207
The first two properties are also true of the columns of the 2 x 2 submatrix. The two
directions are those into which vectors along the positive x and y axes are rotated. These
properties suggest two useful ways to go about deriving a rotation matrix when we know
the effect desired from the rotation. A matrix having these properties is called special
orthogonal.
[;;, ;; l
A transformation matrix of the form
(5.27)
where the upper2 x 2 submatrix is orthogonal, preserves angles and lengths. That is, a unit
square remains a unit square, and becomes neither a rhombus with unit sides, nor a square
with nonunit sides. Such transformations are also called rigid-body transformations,
because the body or object being transformed is not distorted in any way. An arbitrary
sequence of rotation and translation matrices creates a matrix of this form.
Whai can be said about the product of an arbitrary sequence of rotation, translation,
and scale matrices? They are called affine transformations, and have the property of
preserving parallelism of lines, but not lengths and angles. Figure 5.6 shows the results
of applying a -45° rotation and then a nonuniform scaling to the unit cube. It is clear
that neither angles nor length.s have been preserved by this sequence, but parallel lines
have remained parallel. Further rotation, scale, and translation operations will not
cause the
parallel lines to cease being parallel. R(8). S(s., s,), and T(d,, d1) are also affine.
Another type of primitive transformation, shear transformations, are also affine.
[Link] shear transformations are of two kinds: a shear along the x axis and a
shear along theyaxis. Figure 5.7 shows theeffect of shearing the unit cube alongeachaxis.
The operation is represented by the matrix
SH, = [
0 0
i-
I
(5.28)
The term a in the shear matrix is the proportionality constant. Notice that the product
SH,[x y IJTis [x + ay y IJT, clearly demonstrating the proportional change in x as a
function of y.
□ Unit cube Scale in x,
not in y
Fig. 5.6 Aunitcubeis rotatedby -45° andisnonuniformly scaled. Theresult is
anaffine transformation of the unit cube, in which parallelism of•lines is maintained, but
neither angles nor lengths are maintained.
208 Geometrical Transformations
The unit cube Sheared In The unit cube sheared
the ,c direction In the y direction
Fig. 5.7 The primitive-shear operations appfied 10 the unit cube. In each case, the
lengths of the oblique fines are now greater than 1.
Similarly, the matrix
(5.29)
shears along the,, axis.
5.3 COMPOSITION OF 20 TRANSFORMATIONS
The idea of oomposition was iniroduced in the precedingsection. Here, we usecomposition
10 combine the fundamental R.. S, and T matrices to produce desired general results.
The basic purpose of composing transformations is to gain efficiency by applying a
single composed transformation 10 a point, rather than applying a series of
transformations, one after the other.
Consider the ro1ation of an object about some arl>iuary point P1. Because we know how
10 rooue only about the origin, ""'C conYl!rt our original (difficult) problem into three
separate (easy) problems. Thus, 10 rotate about P1. we need a sequence of three
fundamental transformations:
I. Translate such that P1 is at the origin
2. Rotate
3. Translate such that the point at the origin returns 10 P1•
This sequence is illus1roted io Fig. 5.8, in which our house is rotated about P1(x1, y1).
The first uanslatioo is by (-x1• -y1). whereas the later crnnslation is by the inverse (x1• y1).
The result is rather different from that of applying just the rotation.
The net transformation is
T(x • yI) • R(0) • T(-x., - yI) =[ x,l [coslJ -sinll
y, • sinll cosl/
Ol [ I
0 •
1
0 0 I 0O O I 0
cos8 -sinll .r1(1- cos(!) + y1sin8]
...[ si 8 cos8 y1(1 - cos(!) - x1sinlJ . (5.30)
0 I
5.3 Composition of 2D Transformations 209
y y y y
'-----+X
Original house Alter translation JI '--------------•x
After rotation After transJatlon
ol P1 to ongin
10ofiglnal P1
Fig. 5.8 Rotation of a house about the point P1 by an angle 8.
A similar approach is used toscale an objectabout an arbitrary point P1. First, translate
such that P1 goes to the origin. then scale, then translate back to P1. In this case, the net
transformation is
T(x,, Y1)
• S(.s,, sJ • T(-xi, -y1)
=
[i 0 x1
I
]
[
· 0
s,
0OJ
·0[I
o
I
-x,l
-y,
Y
s0
I J
0 I O O I 0 0 I
s, 0 x1(I - s.)l
= 0 Sy y1(1 s,) . (5.31)
[
0 0
Suppose we wish to scale, rotate, and position the house shown In Fig. 5.9 with P1 as
the center for the rotation and [Link]. The sequence is 10 translate P, to the origin, to
perform thescaling and rotation. and then to translate from theorigin to the new position P1
where the house is to be placed. A data structure that rccoo:ls this transformation might
contain the scale factor(s), rotation angle, and translation amountS. and the order in which
the rransformations were applied, or it might simply record the composite tran. formation
matrix:
(5.32)
If M1 and M2 each represent a fundamental translation, scaling, or rotation, when is M1
• Me • Mr • M1? That is, when do M, and M, commute? In general, of course, matrix
multiplicationis nor commuuuivc. H =- itiseasy to show that, in the following
special cases, commutativity holds:
Original Translate P1 Scale Rotate Translate 10
house to origin final position p2
Fig. 5.9 Rotation of a house about the point P,, and placement such that what was at
P, is at P1.
210 Geometrical Transformations
Mi M2
Translate Translate
Scale Scale
Rotate Rotate
Scale (with s, = srl Rotate
In these cases, we need not be concerned about the order of matrix manipulation.
5.4 THE WINDOW-TO-VIEWPORT TRANSFORMATION
Some graphics packages allow the programmer tospecify output primitive coordinates in a
floating-point world-coordinate system, using whatever units are meaningful to the
application program: angstroms, microns. meters, miles, light-years, and so on. The term
world is used because the application program is representing a world that is being
interactively created or displayed to the user.
Given that output primitives are specified in world coordinates, the graphics subroutine
package must be told bow to map oorld coordinates onto screen coordinates (we use the
specific term screen coordinates to relate this discussion specifically to SRGP, but that
hardcopy output devices might be used, in which case the term device coordinates would
be more appropriate). We could do this mapping by having the application programmer
provide the graphics package with a transformation matrix to effect the mapping. Another
way is to have the application programmer specify a rectangular region in world
coordinates, called the world-coordinatewindow, and a corresponding rectangular region
in screen coordinates, called the viewport, into which the world-coordinate window is to be
mapped. The transformation that maps the window into the viewpo11 is applied to all of
the output primitives in world coordinates, thus mapping them into screen coordinates.
Figure
5.10 shows this concept. As seen in this figure, if the window and viewport do not have the
same height-to-width ratio, a nonuniform scaling occurs. If the application program
changes the window or viewport, then new output primitives drawn onto the screen will be
affected by the change. Existing output primitives are not affected by such a change.
The modifier world-coordinate is used with window to emphasize that we are not
discussing a window-manager window, which is a different and more recent concept, and
Maximum range
1----------, oscfreen
coordinates
Window Viewport
World coordinates Screen coordinates
Fig. 5.10 Thewindow in world coordinates and the viewport in screen coordinates
determine the mapping that is applied to all the output primitives in world coordinates.