


















Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



















Lecture 13: Matrix Representations for Affine and Projective Transformations
thou shalt set apart unto the LORD all that openeth the matrix Exodus 13:
1. Matrix Representations for Affine Transformations
In the previous lecture we derived formulas for affine and projective transformations using the
techniques of vector geometry and vector algebra. Formulas expressed in vector algebra are
effective for computing individual transformations, but these formulas are not efficient for
composing transformations. Therefore in this lecture we are going to derive matrix representations
for each of the classical transformations of Computer Graphics so that we will be able to compose
these transformations by matrix multiplication.
To fix our notation, denote the origin by O and the three unit vectors along the
x , y , z
coordinate axes by
i , j , k. Then in 3-dimensions for any vector v and any point P , there are
constants
( v 1
, v 2
, v 3
) and
( p 1
, p 2
, p 3
) such that
v = v 1
i + v 2
j + v 3
k
P = O + p 1
i + p 2
j + p 3
k.
The constants
( v 1
, v 2
, v 3
) and
( p 1
, p 2
, p 3
) are the rectangular coordinates of v and P , and we often
abuse notation and write
v = ( v 1
, v 2
, v 3
) and
P = ( p 1
, p 2
, p 3
Now let A be an affine transformation. Then since A preserves linear and affine combinations
A ( v ) = v 1
A ( i ) + v 2
A ( j ) + v 3
A ( k )
A ( P ) = A ( O ) + p 1
A ( i ) + p 2
A ( j ) + p 3
A ( k ).
Thus if we know the value of A on the three vectors
i , j , k and on the single point O , then we know
the value of A on every vector v and every point P -- that is, any affine transformation A is
completely determined by the four values
A ( O ), A ( i ), A ( j ), A ( k ).
Since affine transformations map points to points and vectors to vectors, there are constants
( a ij
) such that
A ( i ) = a 11
i + a 12
j + a 13
k = ( a 11
, a 12
, a 13
A ( j ) = a 21
i + a 22
j + a 23
k = ( a 21
, a 22
, a 23
A ( k ) = a 31
i + a 32
j + a 33
k = ( a 31
, a 32
, a 33
A ( O ) = O + a 41
i + a 42
j + a 43
k = ( a 41
, a 42
, a 43
Therefore the 12 numbers
( a ij
) completely characterize the affine transformation A. It seems
natural then that we should represent A by a 4 × 3 matrix and write
A ( i )
A ( j )
A ( k )
a 11
a 12
a 13
a 21
a 22
a 23
a 31
a 32
a 33
a 41
a 42
a 43
But there is something not quite right about this
4 × 3 matrix. If we represent a transformation
by a matrix, then we expect that if we multiply the coordinates of a point or a vector by the matrix
we should get the result of the transformation applied to the point or vector. However, points and
vectors in 3-dimensions have only 3 coordinates, whereas this matrix has 4 rows.
To resolve this inconsistency, we shall introduce affine coordinates for points and vectors, and
4 × 4 matrices to represent affine transformations. Recall that in 2-dimensions we insert a third
coordinate, an affine coordinate, for points and vectors: the affine coordinate for points is 1, the
affine coordinate for vectors is 0. This affine coordinate allows us to represent affine
transformations in the plane by
3 × 3 matrices. We shall follow similar conventions in 3-space; in
3-dimensions we insert a fourth, affine coordinate for points and for vectors. Again the affine
coordinate for points is 1, the affine coordinate for vectors is 0. Following this convention,
A ( i ) 0
A ( j ) 0
A ( k ) 0
a 11
a 12
a 13
a 21
a 22
a 23
a 31
a 32
a 33
a 41
a 42
a 43
Now for vectors we have
A ( v ) = v 1
A ( i ) + v 2
A ( j ) + v 3
A ( k ) = v 1
, v 2
, v 3
A ( i ) 0
A ( j ) 0
A ( k ) 0
or equivalently
A ( v ) = v 1
, v 2
, v 3
a 11
a 12
a 13
a 21
a 22
a 23
a 31
a 32
a 33
a 41
a 42
a 43
= ( v ,0)∗ A.
Similarly, for points
A ( P ) = A ( O ) + p 1
A ( i ) + p 2
A ( j ) + p 3
A ( k ) = p 1
, p 2
, p 3
A ( i ) 0
A ( j ) 0
A ( k ) 0
or equivalently
= 3 × 3 Identity Matrix (2.5)
u
T ∗ u ˜ =
u 1
u 2
u 3
∗ u ˜ 1
u ˜ 2
u ˜
u 1
u ˜ 1
u 1
u ˜ 2
u 1
u ˜ 3
u 2
u ˜ 1
u 2
u ˜ 2
u 2
u ˜ 3
u 3
u ˜ 1
u 3
u ˜ 2
u 3
u ˜ 3
u × _ =
0 u 3
− u 2
− u 3
0 u 1
u 2
− u 1
It follows easily by direct computation from Equations (2.5), (2.6), (2.7) that
v ∗ I = v
v ∗( u
T ∗ u ˜ ) = ( v ∗ u
T ) ∗ u ˜ = ( v • u ) u ˜
v ∗( u × _) = u × v.
Thus I represents the identity transformation;
u
T ∗ u ˜ represents the dot product with u (or parallel
projection onto u when
u^ ˜ = u ); and
u × _ represents the cross product with u. Hence
c 1
v + c 2
( v • u ) u ˜ + c 3
u × v = v ∗ c 1
I + c 2
u
T ∗ u ˜ + c 3
u × _
Therefore using Equation (2,8), we can easily find the matrix representing the linear transformations
A
mechanically in the following manner:
A ( v ) = c 1
v + c 2
( v • u ) u ˜ + c 3
u × v
A
= c 1
I + c 2
u
T ∗ u ˜ + c 3
u × _
2.2 Translation Vectors. To find the translation vector
w A
, observe that each of the affine
transformations A from the previous lecture, except for translation, has a fixed point Q -- that is, a
point Q for which
Now for any point P ,
Therefore since A is an affine transformation,
Moreover, since
P − Q is a vector, we know from Section 2.1 that
A
A
A
Hence by Equations (2.10) and (2.11),
A
A
A
A
But by Equation (2.3)
A
Therefore, we conclude from Equations (2.12) and (2.13) that
w A
A
where Q is any fixed point of the affine transformation A.
With Equations (2.9) and (2.14) for
A
and
w A
in hand, we are now ready to derive matrix
representations for each of the standard transformations of 3-dimensional Computer Graphics.
3. Rigid Motions
Rigid motions in 3-dimensions are composites of three basic transformations: translation,
rotation, and mirror image.
3.1 Translation. Let w be a translation vector. For any point P and any vector v ,
v
new = v = v ∗ I
new = P + w = P ∗ I + w
Therefore the matrix
Trans ( w ) representing translations is simply
Trans ( w ) =
w 1
Example 3.1: The matrix representing translation parallel to the x -axis by the distance d is given
by
Trans ( d i ) =
di 1
d 0 0 1
Similarly, the matrices representing translation parallel to the y or z -axes by the distance d are given
by
Trans ( d j ) =
0 d 0 1
and
Trans ( d k ) =
0 0 d 1
Rot ( Origin , k ,θ) =
Rot ( k ,θ ) 0
cos θ sin θ 0 0
−sin θ cos θ 0 0
Similarly, the matrices representing rotation around the x and y -axes by the angle
θ are given by
Rot ( Origin , i ,θ) =
0 cos θ sin θ 0
0 −sin θ cos θ 0
and
Rot ( Origin , j ,θ) =
cos θ 0 −sin θ 0
sin θ 0 cos θ 0
3.3 Mirror Image. Let S be a mirror plane specified by a point Q on S and a unit vector n normal
to S. Denote by
Mir ( Q , n ) the
4 × 4 matrix representing the mirror image of points in the plane S ,
and denote by
Mir ( n ) the upper
3 × 3 submatrix of
Mir ( Q , n ). Then by Equation (2.14) since Q
remains fixed under mirror image,
Mir ( Q , n ) =
Mir ( n ) 0
Moreover, for mirror image (see Lecture 12, Section 6.2)
v
new = v − 2( v • n ) n.
Therefore we can find
Mir ( n ) by invoking Equation (2.9)
v
new = v − 2( v • n ) n
Mir ( n ) = I − 2 n
T ∗ n.
Now notice that
I − Mir ( n ) = 2 n
T ∗ n ,
so
T ∗ n ) = 2( Q • n ) n.
Therefore by Equations (3.6) and (3.7)
Mir ( Q , n ) =
I − 2 n
T ∗ n 0
2( Q • n ) n 1
Example 3.3: Suppose that the mirror plane is the
xy -plane. Then we can choose
Q = Origin = (0, 0 ,0) and
n = k = (0,0, 1 ). By Equations (2.6)
k
T ∗ k =
Therefore
Mir ( Origin , k ) =
I − 2 k
T ∗ k 0
2( Origin • n ) n 1
Similarly, the matrices representing mirror images in the
xz -plane and
yz -plane are
Mir ( Origin , j ) =
and
Mir ( Origin , i ) =
4 Scaling
We are interested in both uniform and non-uniform scaling.
4.1 Uniform Scaling. Uniform scaling is defined by specifying a point Q from which to scale
distance and a scale factor s. For any point P and any vector v (see Lecture 12, Section 6.2),
v
new = sv = v ∗ ( s I )
new = s P + ( 1 − s ) Q = P ∗( s I ) + ( 1 − s ) Q.
Therefore the matrix
Scale ( Q , s ) representing uniform scaling about the point Q by the scale factor
s is given by
Scale ( Q , s ) =
s I 0
( 1 − s ) Q 1
Example 4.1: To scale uniformly about the origin by the scale factor s , set
Q = Origin = (0, 0 ,0).
Then by Equation (4.1)
Scale ( Origin , s ) =
s I 0
( 1 − s ) Origin 1
s 0 0 0
0 s 0 0
0 0 s 0
Scale ( Origin , i , s ) =
s 0 0 0
and
Scale ( Origin , j , s ) =
0 s 0 0
5. Projections
Orthogonal projection is an affine transformation, but perspective projection is not affine.
Therefore in this section we will be concerned only with orthogonal projections. Parallel
projections -- projections into a fixed plane parallel to a fixed direction -- are also affine. These
projections are covered in Exercise 2. Perspective projections will be investigated in detail in
Section 6.
5.1 Orthogonal Projection. Let the plane S into which points are projected be defined by a point
Q and a unit normal vector n , and denote by
Orth ( Q , n ) the
4 × 4 matrix representing orthogonal
projection into the plane S. The formulas for orthogonal projection are (see Lecture 12, Section
v
new = v − ( v • n ) n
new
Notice that these formulas are almost exactly the same as the formulas for mirror image, except for
the missing factors of 2. Therefore using the same analysis we used for mirror image, we arrive at
Ortho ( Q , n ) =
I − n
T ∗ n 0
( Q • n ) n 1
which is the same matrix as
Mir ( Q , n ) in Equation (3.8), except for the missing factors of 2.
Example 5.1: Suppose that the projection plane is the
xy -plane. Then we can choose
Q = Origin = (0, 0 ,0) and
n = k = (0,0, 1 ). By Equations (2.6)
k
T ∗ k =
Therefore
Ortho ( Origin , k ) =
I − k
T ∗ k 0
( Origin • n ) n 1
Similarly, the matrices representing orthogonal projections into the
xz -plane and
yz -plane are
Ortho ( Origin , j ) =
and
Ortho ( Origin , i ) =
6. Perspective
Unlike all of the other transformations that we have investigated so far, perspective projection is
not an affine transformation because perspective projection is not a well-defined transformation at
every point nor is perspective well-defined for any vector. Nevertheless, we shall see shortly that we
can still represent perspective projections by
4 × 4 matrices.
6.1 Projective Transformations and Homogeneous Coordinates. Perspective projection is
defined by specifying an eye point
E = ( e 1
, e 2
, e 3
) and a plane S into which to project the image.
The plane S is specified, as usual, by a point
Q = ( q 1
, q 2
, q 3
) on S and a unit vector
n = ( n 1
, n 2
, n 3
normal to S.
The image of an arbitrary point
P = ( x , y , z ) under perspective projection from the eye point
E = ( e 1
, e 2
, e 3
) to the plane S is given by the expression (see Lecture 12, Section 6.2)
( E − P ) • n
or in terms of coordinates
x
( e 1
− q 1
) n 1
− q 2
) n 2
− q 3
) n
x + ( q 1
− p 1
) n 1
− p 2
) n 2
− p 3
) n
e 1
− n 1
x − n 2
y − n 3
z + e 1
n 1
n 2
n 3
y
( e 1
− q 1
) n 1
− q 2
) n 2
− q 3
) n
y + ( q 1
− p 1
) n 1
− p 2
) n 2
− p 3
) n
e 2
− n 1
x − n 2
y − n 3
z + e 1
n 1
n 2
n 3
z
( e 1
− q 1
) n 1
− q 2
) n 2
− q 3
) n
z + ( q 1
− p 1
) n 1
− p 2
) n 2
− p 3
) n
e 3
− n 1
x − n 2
y − n 3
z + e 1
n 1
n 2
n 3
Notice that since the point P appears in both the numerator and the denominator on the right hand
side of Equation (6.1), the variables
x , y , z appear in both the numerator and the denominator of the
expressions for the coordinates
x
new , y
new , z
new
. Transformations where
x , y , z appear in both the
numerator and the denominator are called projective transformations. In order to represent
perspective projection by matrix multiplication, we need to be able to represent projective
transformations using matrix multiplication. So far we can only invoke matrices to represent linear
and affine transformations.
We can now express projective transformations by 4 equations in the homogeneous
coordinates
( x , y , z , w ) :
x
new = a 11
x + a 21
y + a 31
z + a 41
y
new = a 12
x + a 22
y + a 32
z + a 42
z
new = a 13
x + a 23
y + a 33
z + a 43
w
new = a 14
x + a 24
y + a 34
z + a 44
( x y z 1 ) ∗
a 11
a 12
a 13
a 14
a 21
a 2
a 23
a 24
a 31
a 32
a 33
a 34
a 41
a 42
a 43
a 44
Thus, using homogeneous coordinates, we can represent projective transformations by arbitrary
4 × 4 matrices, where the last column captures the denominator. Another advantage of
homogeneous coordinates is that we can postpone division until we actually need a numerical result.
6.2 Matrices for Perspective Projections. Let us return now to perspective projection. Recall
that the formula for perspective is
( E − P ) • n
where E is the eye point and S is the projection plane, specified by a point
Q on S and a unit vector
n normal to S. Using homogenous coordinates, we can place the denominator in the fourth
coordinate and write
new
Expanding the terms on the right hand side of Equation (6.2) gives
new
Now observe that
( P • n ) E = ( P ∗ n
T )∗ E = P ∗( n
T ∗ E ).
Therefore, by Equations (6.3) and (6.4), the numerator of
new is
T ∗ E )
Moreover, the denominator of
new is
− P • n + E • n = P ∗(− n
T ) + E • n.
Therefore it follows that
new , 1 ) = ( P ,1)∗
T ∗ E − n
T
( Q • n ) E E • n
Thus, with the convention that the fourth coordinate represents the denominator, the
4 × 4 matrix
Persp ( E , Q , n ) representing perspective projection from the eye point E to the plane S is given by
Persp ( E , Q , n ) =
T ∗ E − n
T
( Q • n ) E E • n
Example 6.1: Suppose that the eye is located along the z -axis at
E = (0, 0 ,1) and perspective plane
is the
xy -plane. Then we can choose
Q = Origin = (0, 0 ,0) and
n = k = (0,0, 1 ). By Equations (2.6)
k
T ∗ E =
Therefore by Equation (6.5)
Persp ( E , Origin , k ) =
T ∗ E − k
T
( Origin • k ) E E • k
Thus the projective transformation representing perspective projection into the
xy -plane is
x
new = x , y
new = y , z
new = 0 , w
new = 1 − z ⇔ x
new = x / 1 − z , y
new = y / 1 − z , z
new = 0.
7. Summary
Below we summarize the main themes of this lecture. Also listed below for your convenience
are the matrix representations for each of the transformations that we have studied in this lecture.
7.1 Matrix Representations for Affine and Projective Transformations. The core content of
this lecture are
4 × 4 matrix representations for each of the basic affine and projective
transformations -- translation, rotation, mirror image, uniform and non-uniform scaling, and
orthogonal and perspective projection -- of 3-dimensional Computer Graphics.
Every affine transformation A is completely determined by the four values
A ( O ), A ( i ), A ( j ), A ( k ) , and these values form the rows of the matrix representation for A -- that is
A ( i ) 0
A ( j ) 0
A ( k ) 0
Thus, matrix representations for affine transformations all have the form:
A
w A
3 × 3 Linear Transformation Matrix 0
Translation Vector 1
7.2 Matrices for Affine and Projective Transformations.
Translation -- by the vector w
Trans ( w ) =
w 1
Rotation -- around the line L determined by the point Q and the unit direction vector u by the
angle
θ
Rot ( Q , u ,θ) =
Rot ( u ,θ) 0
Rot ( u ,θ) = (cos θ) I + ( 1 − cos θ)( u
T ∗ u ) + (sinθ)( u × _)
Mirror Image -- in the plane S determined by the point Q and the unit normal n
Mir ( Q , n ) =
I − 2 n
T ∗ n 0
2( Q • n ) n 1
Uniform Scaling -- around the point Q by the scale factor s
Scale ( Q , s ) =
s I 0
( 1 − s ) Q 1
Non-Uniform Scaling -- around the point Q by the scale factor s in the direction u
Scale ( Q , u , s ) =
I + ( s − 1 ) u
T ∗ u 0
( 1 − s )( Q • u ) u 1
Orthogonal Projection -- into the plane S determined by the point Q and the unit normal n
Ortho ( Q , n ) =
I − n
T ∗ n 0
( Q • n ) n 1
Perspective Projection -- from the eye point E into the plane S determined by the point Q and
the unit normal vector n
Persp ( E , Q , n ) =
T ∗ E − n
T
( Q • n ) E E • n
Exercises:
S = Shearing plane
n = Unit vector perpendicular to S
Q = Point on S
u = Unit vector in S (i.e. unit vector perpendicular to n )
φ = Shear angle
Recall that the formulas for shear are
v
new = v + tan( φ)( v • n ) u
new
a. Show that the
4 × 4 matrix representing shear is given by
Shear ( Q , n , u , φ) =
I + ( tan φ)( n
T ∗ u ) 0
− tan φ( Q • n ) u 1
b. Suppose that
i. S is the xy- plane,
ii. u is the unit vector along the x -axis,
iii.
φ = 45
o
Write down the explicit entries of the
4 × 4 matrix
Shear ( Q , n , u , φ).
direction u. As usual the plane S is defined by a point Q and a unit normal vector n. Recall that the
formulas for parallel projection are
v
new = v −
v • n
u • n
u
new = P −
( P − Q ) • n
u • n
u
a. Show that the
4 × 4 matrix representing parallel projection is given by
PProj ( Q , n , u ) =
n
T ∗ u
u • n
Q • n
u • n
u 1
b. Suppose that
i. S is the xy-plane ,
ii.
u is the unit vector parallel to the vector
Write down the explicit entries of the
4 × 4 matrix PProj ( Q , n , u ).
3 × 3 matrix, and let
v , w be arbitrary vectors.
a. Show that
( u ∗ M ) × ( v ∗ M ) = Det ( M )( u × v ) ∗ M
− T
b. Conclude from part a and Exercises 3,4 that
i.
ii.
c. Interpret the results in part b geometrically.
v 1
, v 2
be unit vectors, and let
u = v 1
× v 2
a. Show that the matrix
Rot ( u ) = ( v 1
u
T ∗ u
1 + v 1
rotates the vector
v 1
into the vector
v 2
b. Interpret this result geometrically.
Mir ( Q , n ) = Scale ( Q , n ,− 1 ). Interpret this result geometrically.
Mir ( n ) = − Rot ( n , π ). Interpret this result geometrically.
4 × 4
be the
4 × 4 identity matrix. Show that on points
Ortho ( Q , n )= I 4 × 4
a. A maps straight lines to straight lines.
b. A preserves ratios of distances along straight lines -- that is, if
P , Q , R are collinear, then
a. T maps straight lines to straight lines.
b. T does not necessarily preserve ratios of distances along straight lines. That is, give an
example to show that if
P , Q , R are collinear, then
P , Q , R , S is defined by
cr ( P , Q , R , S ) =
Show that if T is a projective transformation, then T preserves cross ratios -- that is, show that
v 1
, v 2
, v 3
be three linearly independent vectors in 3-space.
a. Show that in 3-dimensions there is a unique affine transformation A that maps
P , v 1
, v 2
, v 3
to
Q , w 1
, w 2
, w 3
b. Show that if u is an arbitrary vector, then
A ( u ) =
Det u v 2
v
w 1
u v
w 2
v 2
3
Det v 1
v 2
v
c. Verify that the matrix representing this affine transformation A is given by
v 1
v 2
v 3
− 1
w 1
w 2
w 3
d. Show that Equation (1.1) is a special case of the matrix in part c.
1
2
3
4
be four non-collinear points in 3-space.
a. Show that in 3-dimensions there is a unique affine transformation A that maps four non-
collinear points
1
2
3
4
to four arbitrary points
1
2
3
4
b. Show that if R is an arbitrary point, then
Det
2
3
4
1
1
3
4
2
1
2
4
3
1
2
3
4
Det
1
2
3
4
c. Verify that the matrix representing this affine transformation A is given by
1
2
3
4
− 1
1
2
3
4