














Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of affine transformations in two dimensions, covering translation, rotation, scaling, and shear. It provides mathematical equations and visualizations to help understand these transformations and their effects on points and vectors.
Typology: Study notes
1 / 22
This page cannot be seen from the preview
Don't miss anything!















Lecture 4: Affine Transformations
for Satan himself is transformed into an angel of light. 2 Corinthians 11:
1. Transformations
Transformations are the lifeblood of geometry. Euclidean geometry is based on rigid motions
-- translation and rotation -- transformations that preserve distances and angles. Congruent
triangles are triangles where corresponding lengths and angles match.
Transformations generate geometry. The turtle uses translation (FORWARD), rotation
(TURN), and uniform scaling (RESIZE) to generate curves by moving about on the plane. We can
also apply translation (SHIFT), rotation (SPIN), and uniform scaling (SCALE) to build new shapes
from previously defined turtle programs. These three transformations -- translation, rotation and
uniform scaling -- are called conformal transformations. Conformal transformations preserve
angles, but not distances. Similar triangles are triangles where corresponding angles agree, but the
lengths of corresponding sides are scaled. The ability to scale is what allows the turtle to generate
self-similar fractals like the Sierpinski gasket.
In Computer Graphics transformations are employed to position, orient, and scale objects as
well as to model shape. Much of elementary Computational Geometry and Computer Graphics is
based upon an understanding of the effects of different fundamental transformations.
The transformations that appear most often in 2-dimensional Computer Graphics are the affine
transformations. Affine transformations are composites of four basic types of transformations:
translation, rotation, scaling (uniform and non-uniform), and shear. Affine transformations do not
necessarily preserve either distances or angles, but affine transformations map straight lines to
straight lines and affine transformations preserve ratios of distances along straight lines (see Figure
1). For example, affine transformations map midpoints to midpoints. In this lecture we are going
to develop explicit formulas for various affine transformations; in the next lecture we will use these
affine transformations as an alternative to turtle programs to model shapes for Computer Graphics.
€
€
€
€
€
€
€
a
b ′
Figure 1: An affine transformation A maps lines to lines and preserves ratios of distances along
straight lines. Thus
A ( Q ) lies on the line joining
A ( P ) and
A ( R ) , and
a^ ′ / b ′ = a / b.
A word of warning before we begin. There is a good deal of linear algebra in this chapter.
Don’t panic. Though there is a lot of algebra, the details are all fairly straightforward. The bulk of
this chapter is devoted to deriving matrix representations for the affine transformations which will
be used in subsequent chapters to generate shapes for 2-dimensional Computer Graphics. All the
matrices that you will need later on are listed at the end of this chapter, so you will not have to slog
through these derivations every time you require a specific matrix; you can find these matrices
easily whenever you need them. Persevere now because there will be a big payoff shortly.
2. Conformal Transformations
Among the most important affine transformations are the conformal transformations:
translation, rotation, and uniform scaling. We shall begin our study of affine transformations by
developing explicit matrix representations for these conformal transformations.
To fix our notation, we will use upper case letters
P , Q , R ,K from the middle of the alphabet to
denote points and lower case letters
u , v , w ,K from the end of the alphabet to denote vectors. Lower
case letters with subscripts will denote rectangular coordinates. Thus, for example, we shall write
P = ( p 1 , p 2 ) to denote that
( p 1 , p 2 ) are the rectangular coordinates of the point P. Similarly, we
shall write
v = ( v 1 , v 2 ) to denote that
( v 1 , v 2 ) are the rectangular coordinates of the vector v.
2.1 Translation. We have already encountered translation in our study of Turtle Graphics (see
Figure 2). To translate a point
P = ( p 1 , p 2 ) by a vector
w = ( w 1 , w 2 ), we set
new = P + w (1)
or in terms of coordinates
p 1
new = p 1
p 2
new = p 2
Vectors are unaffected by translation, so
v
new = v.
We can rewrite these equations in matrix form. Let I denote the
2 × 2 identity matrix; then
new = P ∗ I + w
v
new = v ∗ I.
€
€
€
€
new
€
v new
Figure 2: Translation. Points are affected by translation; vectors are not affected by translation.
2.3 Uniform Scaling. Uniform scaling also appears in Turtle Graphics. To scale a vector
v = ( v 1 , v 2 ) by a factor s , we simply set
v
new = sv (5)
or in terms of coordinates
v 1
new = sv 1
v 2
new = sv 2
Introducing the scaling matrix
Scale ( s ) =
s 0
0 s
we can rewrite Equation (5) in matrix form as
v
new = v ∗ Scale ( s ).
Again, in affine geometry we want not only to scale vectors, but also to scale uniformly the
distance of points from a fixed point. Since
P = Q + ( P − Q ) , scaling the distance of an arbitrary
point P from a fixed point Q by the factor s is equivalent to scaling the length of the vector
by the factor s and then adding the resulting vector to Q (see Figure 4). Thus the formula for
scaling the distance of an arbitrary point P from a fixed point Q by the factor s is
new = Q + ( P − Q ) ∗ Scale ( s ) = P ∗ Scale ( s ) + Q ∗ (^) ( I − Scale ( s )). (6)
Notice that if Q is the origin, then this formula reduces to
new = P ∗ Scale ( s ) ,
so
Scale ( s ) is also the matrix that represents uniformly scaling the distance of points from the
origin.
new
€
{
Figure 4: Uniform scaling about a fixed point Q. Since the point Q is fixed and since
P = Q + ( P − Q ) , scaling the distance of a point P from the point Q by the factor s is equivalent to
scaling the vector P − Q by the factor s and then adding the resulting vector to Q.
3. The Algebra of Affine Transformations
The three conformal transformations -- translation, rotation, and uniform scaling -- all have the
following form: there exists a matrix M and a vector w such that
v
new = v ∗ M
new = P ∗ M + w.
In fact, this form characterizes all affine transformations. That is, a transformation is said to be
affine if and only if there is a matrix M and a vector w so that Equation (7) is satisfied.
The matrix M represents a linear transformation on vectors. Recall that a transformation L on
vectors is linear if
L ( u + v ) = L ( u ) + L ( v )
L ( cv ) = cL ( v ).
Matrix multiplication represents a linear transformation because matrix multiplication distributes
through vector addition and commutes with scalar multiplication -- that is,
( u + v ) ∗ M = u ∗ M + v ∗ M
( cv ) ∗ M = c ( v ∗ M ).
The vector w in Equation (7) represents translation on the points. Thus an affine
transformation can always be decomposed into a linear transformation followed by a translation.
Notice that adding a constant vector to a vector is not a linear transformation, since adding a
constant vector does not satisfy Equation (8) (see Exercise 1). Therefore translation cannot be
represented by a
2 × 2 matrix.
Affine transformations can also be characterized abstractly in a manner similar to linear
transformations. A transformation A is said to be affine if A maps points to points, A maps vectors
to vectors, and
A ( u + v ) = A ( u ) + A ( v )
A ( c v ) = c A ( v )
A ( P + v ) = A ( P ) + A ( v ).
The first two equalities in Equation (9) say that an affine transformation is a linear transformation
on vectors; the third equality asserts that affine transformations are well behaved with respect to the
addition of points and vectors. You should check that with this definition, translation is indeed an
affine transformation.
In terms of coordinates, linear transformations can be written as
x
new = a x + b y
y
new = c x + d y
⇔ ( x
new , y
new ) = ( x , y ) ∗
a c
b d
5. Affine Coordinates and Affine Matrices
Linear transformations are typically represented by matrices because composing two linear
transformations is equivalent to multiplying the corresponding matrices. We would like to have the
same facility with affine transformations -- that is, we would like to be able to compose two affine
transformations by multiplying their matrix representations. Unfortunately, our current
representation of an affine transformation in terms of a transformation matrix M and a translation
vector w does not work so well when we want to compose two affine transformations. In order to
overcome this difficulty, we shall now introduce a clever device called affine coordinates.
Points and vectors are both represented by pairs of rectangular coordinates, but points and
vectors are different types of objects with different behaviors for the same affine transformations.
For example, points are affected by translation, but vectors are not. We are now going to introduce
a third coordinate -- an affine coordinate -- to distinguish between points and vectors. Affine
coordinates will also allow us to represent each affine transformation using a single
3 × 3 matrix
and to compose any two affine transformations by matrix multiplication.
Since points are affected by translation and vectors are not, the affine coordinate for a point is
1 ; the affine coordinate for a vector is
P = ( p 1 , p 2 , 1 ) for
points and
v = ( v 1 , v 2 ,0) for vectors.
Affine transformations can now be represented by
3 × 3 affine matrices. An affine matrix is a
3 × 3 matrix where the third column is
T
. The affine transformation
v
new = v ∗ M
new = P ∗ M + w
represented by the
2 × 2 transformation matrix M and the translation vector w can be rewritten
using affine coordinates in terms of a single
3 × 3 affine matrix
w 1
Now
( v
new , 0) = ( v , 0) ∗
M = ( v , 0) ∗
w 1
=^ ( v^ ∗^ M ,^ 0)
new , 1 ) = ( P , 1 ) ∗
w 1
=^ ( P^ ∗^ M^ +^ w ,^1 ).
Notice how the affine coordinate -- 0 for vectors and 1 for points -- is correctly reproduced by
multiplication with the last column of the matrix
M. Notice too that the 0 in the third coordinate for
vectors effectively insures that vectors ignore the translation represented by the vector w.
6. Conformal Transformations -- Revisited
To illustrate some specific examples of affine matrices, below we show how to represent the
standard conformal transformations -- translation, rotation, and uniform scaling -- in terms of
affine matrices. These results follow easily from Equations (1), (4), and (6).
Translation -- by the vector
w = ( w 1 , w 2
Trans ( w ) =
w 1
w 1 w 2
Rotation -- around the Origin through the angle
θ
Rot ( Origin ,θ) =
Rot ( θ) 0
cos( θ) sin( θ) 0
−sin(θ) cos( θ) 0
Rotation -- around the point
Q = ( q 1 , q 2 ) through the angle
θ
Rot ( Q ,θ) =
Rot ( θ) 0
Q ∗ (^) ( I − Rot ( θ)) 1
cos( θ) sin(θ) 0
−sin(θ) cos( θ) 0
q 1 (^1 −^ cos(^ θ)) +^ q 2 sin( θ) − q 1 sin(θ) + q 2 (^1 −^ cos(^ θ)) 1
Uniform Scaling -- around the Origin by the factor s
Scale ( Origin , s ) =
s I 0
s 0 0
0 s 0
Uniform Scaling -- around the point
Q = ( q 1 , q 2 ) by the factor s
Scale ( Q , s ) =
s I 0
Q ∗( 1 − s ) I 1
s 0 0
0 s 0
( 1 − s ) q 1 ( 1 − s ) q 2
7. General Affine Transformations
We shall now develop
3 × 3 matrix representations for arbitrary affine transformations. The
two most general ways of specifying an affine transformation of the plane are by specifying either
the image of one point and two linearly independent vectors or by specifying the image of three
non-collinear points. We shall treat each of these cases in turn.
a c 0
b d 0
e f 1
Thus
u
∗ 0
v
∗ 0
∗ 1
Snew
u 0
v 0
Sold
a c 0
b d 0
e f 1
M
Solving for M yields
old
− 1 ∗ S new
or equivalently
u 0
v 0
− 1
u
∗ 0
v
∗ 0
∗ 1
u 1 u 2
v 1 v 2
q 1 q 2
− 1
u 1
∗ u 2
∗ 0
v 1
∗ v 2
∗ 0
q 1
∗ q 2
∗ 1
To compute M explicitly, we need only invert a
3 × 3 affine matrix. But for a nonsingular
3 × 3 affine matrix, the inverse can easily be written explicitly; for the formula, see Exercise 13a.
An alternative explicit formula for the matrix M without inverses is provided in Exercise 21.
7.2 Non-Uniform Scaling. One application of our preceding approach to general affine
transformations is a formula for non-uniform scaling. Uniform scaling scales distances by the
same amount in all directions; non-uniform scaling scales distances by different amounts in
different directions. We are interested in non-uniform scaling for many reasons. For example, we
can apply non-uniform scaling to generate an ellipse by scaling a circle from its center along a fixed
direction (see Figure 8). To scale the distance from a fixed point Q along an arbitrary direction w
by a scale factor s, we shall now apply our method for generating arbitrary affine transformations
by specifying the image of one point and two linearly independent vectors (see Figure 9).
Figure 8: Scaling a circle from its center along a fixed direction generates an ellipse.
€
Q
€
w
€
€
w ⊥
€
Q
€
€ s w
w ⊥
Figure 9: Scaling from the fixed point Q in the direction w by the scale factor s. The point Q is
fixed, the vector w is scaled by s, and the orthogonal vector
w
⊥ remains fixed. Thus non-uniform
scaling maps a square into a rectangle.
Let
Scale ( Q , w , s ) denote the matrix that represents the affine transformation which scales the
distance from a fixed point Q along an arbitrary direction w by a scale factor s. To find the
matrix
Scale ( Q , w , s ) , we need to know the image of one point and two linearly independent vectors.
Consider the point
Q and the vectors w and
w
⊥ , where
w
⊥ is a vector of the same length as w
perpendicular to w. It is easy to see how the transformation
Scale ( Q , w , s ) affects
Q , w , w
⊥ :
Q → Q because Q is a fixed point of the transformation.
w → s w because distances are scaled by the factor s along the direction w.
w
⊥ → w
⊥ because distances along the vector
w
⊥ are not changed, since
w
⊥ is
orthogonal to the scaling direction w.
Therefore by the results of the previous section:
Scale ( Q , w , s ) =
w 0
w
⊥ 0
− 1
∗
s w 0
w
⊥ 0
Now recall that if
w = ( w 1 , w 2 ), then
w
⊥ = (− w 2 , w 1 ). Therefore in terms of coordinates
Scale ( Q , w , s ) =
w 1 w 2
− w 2 w 1
q 1 q 2
− 1
∗
s w 1 s w 2
− w 2 w 1
q 1 q 2
An explicit formula for the matrix
Scale ( Q , w , s ) without inverses is provided in Exercise 20.
If Q is the origin and w is the unit vector along the x -axis, then w
⊥ is the unit vector along the
y -axis, so
1
∗ 1
2
∗ 1
3
∗ 1
Pnew
1
2
3
Pold
a c 0
b d 0
e f 1
M
Solving for M yields
old
− 1 ∗ P new
or equivalently if
k = ( x k , y k ) and
k
∗ = ( x k
∗ , y k
∗ ) for
k = 1 , 2 , 3 , then
1
2
3
− 1
1
∗ 1
2
∗ 1
3
∗ 1
x 1 y 1
x 2 y 2
x 3 y 3
− 1
x 1
∗ y 1
∗ 1
x 2
∗ y 2
∗ 1
x 3
∗ y 3
∗ 1
To compute M explicitly, we need only invert a
3 × 3 matrix whose last column is
T
. This
inverse can easily be written explicitly; for the formula, see Exercise 13b. An alternative explicit
formula for the matrix M without inverses is provided in Exercise 21.
Notice the similarity between the right hand side of Equation (14) and the right hand side of
Equation (13) in Section 7.1 for the matrix representing the affine transformation defined by the
image of one point and two linearly independent vectors. The only differences are the ones
appearing in the first two rows of the third columns, indicating that two vectors have been replaced
by two points.
8. Summary
Below is a brief summary of the main high level concepts that you need to remember from this
lecture. Also listed below for your convenience are the
3 × 3 matrix representations for all the
affine transformations that we have discussed in this lecture.
8.1 Affine Transformations and Affine Coordinates. Affine transformations are the
fundamental transformations of 2-dimensional Computer Graphics. There are several different
ways of characterizing affine transformations:
2 × 2 matrix M and a vector w such that
A ( v ) = v ∗ M
A ( P ) = P ∗ M + w.
3 × 3 affine matrix M such that
(^ A ( v ),^0 ) =^ ( v ,^ 0)∗^ M
(^ A ( P ),^1 ) =^ ( P ,^1 )∗^ M
A ( u + v ) = A ( u ) + A ( v )
A ( c v ) = c A ( v )
A ( P + v ) = A ( P ) + A ( v ).
preserves ratios of distances along lines.
Affine transformations include the standard conformal transformations -- translation, rotation,
and uniform scaling -- of Turtle Graphics, but affine transformations also incorporate other
transformations such as non-uniform scaling. Every affine transformation can be uniquely
specified either by the image of one point and two linearly independent vectors or by the image of
three non-collinear points.
Affine coordinates are used to distinguish between points and vectors. The affine coordinate
of a point is 1; the affine coordinate of a vector is 0. Affine coordinates can be applied to represent
all affine transformations by
3 × 3 matrices of the form,
w 1
so that
( v
new , 0) = ( v ,0) ∗ M
new , 1 ) = ( P , 1 ) ∗ M.
These matrix representations allow us to compose affine transformations using matrix
multiplication.
The affine transformations of Computer Graphics are closely related to the linear
transformations of standard linear algebra. In fact, in terms of matrix representations
Affine Transformation =
Linear 0
Transformation 0
Translation 1
In Table 1 we provide a more detailed comparison of the differences between affine and linear
transformations.
Rotation -- around the Origin through the angle
θ
Rot ( Origin ,θ) =
Rot ( θ) 0
cos( θ) sin( θ) 0
−sin(θ) cos( θ) 0
Rotation -- around the point
Q = ( q 1 , q 2 ) through the angle
θ
Rot ( Q ,θ) =
Rot ( θ) 0
Q ∗ (^) ( I − Rot ( θ)) 1
cos( θ) sin(θ) 0
−sin(θ) cos( θ) 0
q 1 (^1 −^ cos(^ θ)) +^ q 2 sin( θ) − q 1 sin(θ) + q 2 (^1 −^ cos(^ θ)) 1
Uniform Scaling -- around the Origin by the factor s
Scale ( Origin , s ) =
s I 0
s 0 0
0 s 0
Uniform Scaling -- around the point
Q = ( q 1 , q 2 ) by the factor s
Scale ( Q , s ) =
s I 0
Q ∗( 1 − s ) I 1
s 0 0
0 s 0
( 1 − s ) q 1 ( 1 − s ) q 2
Non- Uniform Scaling -- around point
Q = ( q 1 , q 2 ) in direction
w = ( w 1 , w 2 ) by the factor s
Scale ( Q , w , s ) =
w 1 w 2
− w 2 w 1
q 1 q 2
− 1
∗
s w 1 s w 2
− w 2 w 1
q 1 q 2
Scaling from the Origin along the x-axis by the factor s
Scale ( Origin , i , s ) =
s 0 0
Scaling from the Origin along the y-axis by the factor s
Scale ( Origin , j , s ) =
0 s 0
Image of One Point
Q = ( x 3 , y 3 ) and Two Vectors
v 1 = ( x 1 , y 1
v 2 = ( x 2 , y 2
Image ( v 1 , v 2
x 1 y 1
x 2 y 2
x 3 y 3
− 1
x 1
∗ y 1
∗ 0
x 2
∗ y 2
∗ 0
x 3
∗ y 3
∗ 1
Image of Three Non-Collinear Points
1 = ( x 1 , y 1
2 = ( x 2 , y 2
3 = ( x 3 , y 3
Image ( P 1
2
3
x 1 y 1
x 2 y 2
x 3 y 3
− 1
x 1
∗ y 1
∗ 1
x 2
∗ y 2
∗ 1
x 3
∗ y 3
∗ 1
Inverses
x 1 y 1
x 2 y 2
x 3 y 3
− 1
y 2 − y 1
− x 2 x 1
x 2 y 3 − y 2 x 3 y 1 x 3 − x 1 y 3 x 1 y 2 − y 1 x 2
x 1 y 2 − y 1 x 2
x 1 y 1
x 2 y 2
x 3 y 3
− 1
y 2 − y 3 y 3 − y 1 y 1 − y 2
x 3 − x 2 x 1 − x 3 x 2 − x 1
x 2 y 3 − y 2 x 3 y 1 x 3 − x 1 y 3 x 1 y 2 − y 1 x 3
x 1 ( y 2 − y 3 ) + x 2 ( y 3 − y 1 ) + x 3 ( y 1 − y 2 ( ))
Exercises:
w ( v ) = v + w and
w ( P ) = P + w. Show that
w ( v ) is not a linear transformation on
vectors, but that
w ( P ) is an affine transformation on points.
new = ( 1 − s ) Q + sP.
w Q denote the vector from the origin to the point Q. Without appealing to coordinates and
without explicitly multiplying matrices, explain why:
i.
Rot ( Q ,θ) = Trans (− w Q ) ∗ Rot ( θ) ∗ Trans ( w Q
ii. Scale ( Q , s ) = Trans (− w Q ) ∗ Scale ( s ) ∗ Trans ( w Q
(Hint: Give a geometric interpretation for formulas i and ii.)
a.
x 1 y 1
x 2 y 2
x 3 y 3
y 2 − y 1
− x 2 x 1
x 2 y 3 − y 2 x 3 y 1 x 3 − x 1 y 3 x 1 y 2 − y 1 x 2
x 1 y 2 − y 1 x 2
b.
x 1 y 1
x 2 y 2
x 3 y 3
y 2 − y 3 y 3 − y 1 y 1 − y 2
x 3 − x 2 x 1 − x 3 x 2 − x 1
x 2 y 3 − y 2 x 3 y 1 x 3 − x 1 y 3 x 1 y 2 − y 1 x 2
x 1 ( y 2 − y 3 ) + x 2 ( y 3 − y 1 ) + x 3 ( y 1 − y 2 ( ))
one vector that is not parallel to the line determined by the two points.
b. Let
1
∗ , P 2
∗ , v
∗ be the images of
1
2 , v under the affine transformation A. Find the
3 × 3 matrix M that represents the affine transformation A.
a. the image of one point and one vector.
b. the image of two points.
ScaleFactor ( M ) = det( M ).
Mirror ( Q , w ) denote the matrix representing the transformation that mirrors points and
vectors in the line determined by the point Q and the direction vector w.
a. Show that
i.
Mirror ( Q , w ) =
w 0
w
⊥ 0
− 1
∗
w 0
− w
⊥ 0
= Scale ( Q , w
⊥ ,− 1 )
b. Conclude that the matrices representing mirroring in the x and y -axes are given by
ii.
Mirror ( Origin , i ) =
iii. Mirror ( Origin , j ) =
w , w
⊥ into a parallelogram by tilting the edge
w
⊥ so that
w new
⊥ makes an angle of
θ with
w
⊥ (see
Figure 10). Show that:
a.
Shear ( Q , w , w
⊥ ,θ) =
w 0
w
⊥ 0
− 1
w 0
tan( θ) w + w
⊥ 0
b.
Shear ( Origin , i , j ,θ) =
tan( θ) 1 0
c.
det Shear ( Q , w , w
⊥ ,θ)
d. Shear preserves area.
€
Q
€
€
w €
w
⊥
€
Q
€
€
w €
w
⊥
€
θ
€
w new
⊥
Figure 10: Shear maps the rectangle with vertex Q and sides
w , w
⊥ into a parallelogram by tilting
the edge
w
⊥ so that
w new
⊥ makes an angle of
θ with
w
⊥ .
rotation, 1 shear, and 2 non-uniform scalings.
A ( v ) = v + ( s − 1 )
v • w
w • w
w , where
v • w = v 1 w 1
a. Show that
i.
A ( w ) = s w
ii.
A ( w
⊥ ) = w
⊥
iii.
v = α w + β w
⊥ ⇒ A ( v ) = s α w + β w
⊥ .
b. Conclude from part a that
iv.
v ∗ Scale ( Q , w , s ) = v + ( s − 1 )
v • w
w • w
w.
c. Using the result of part b , show that for every point P
v. P ∗ Scale ( Q , w , s ) = P + ( s − 1 )
( P − Q ) • w
w • w
w.