Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

Reading

Required:

Š Watt, Section 1.1.


Further reading:

Š Foley, et al, Chapter 5.1-5.5.


Š David F. Rogers and J. Alan Adams,
Mathematical Elements for Computer Graphics,
4. Affine transformations 2nd Ed., McGraw-Hill, New York, 1990, Chapter 2.

Geometric transformations Representation

Geometric transformations will map points in one We can represent a point, p = (x,y), in the plane
space to points in another: (x',y',z') = f(x,y,z).
Š as a column vector
These tranformations can be very simple, such as ªxº
scaling each coordinate, or complex, such as non- «y»
linear twists and bends.
¬ ¼
Š as a row vector
We'll focus on transformations that can be >x y@
represented easily with matrix operations.

We'll start in 2D...


Representation, cont. Two-dimensional transformations

We can represent a 2-D transformation M by a Here's all you get with a 2 x 2 transformation matrix
matrix M:
ªa b º ª x 'º ªa b º ª x º
«c d » « y '» « c d » « y »
¬ ¼ ¬ ¼ ¬ ¼¬ ¼

If p is a column vector, M goes on the left:


So:
p' Mp x ' ax  by
ª x 'º ªa b º ª x º y ' cx  dy
« y '» « c d » « y »
¬ ¼ ¬ ¼¬ ¼
We will develop some intimacy with the elements
If p is a row vector, MT goes on the right: a, b, c, d…

p' pMT
ªa c º
>x' y '@ >x y@« »
¬b d ¼

We will use column vectors.

Identity Scaling

Suppose we choose a=d=1, b=c=0: Suppose we set b=c=0, but let a and d take on any
positive value:
Š Gives the identity matrix:
Š Gives a scaling matrix:
ª1 0º ªa 0 º
«0 d »
« 0 1» ¬ ¼
¬ ¼
Š Provides differential (non-uniform) scaling in
Š Doesn't move the points at all x and y:
x ' ax
y ' dy
y y

ª2 0 º
«0 2 »
2 2 ¬ ¼
1 1
x x
1 2 1 2
y

ª1 2 0 º
« 0 2»
2 ¬ ¼
1
x
1 2
______________ ____________

Suppose we keep b=c=0, but let either a or d go Now let's leave a=d=1 and experiment b. . . .
negative.
The matrix
Examples: ª1 bº
« 0 1»
¬ ¼
gives:

ª 1 0 º ª1 0 º x' x  by
« 0 1» «0 1» y' y
¬ ¼ ¬ ¼

y y

y y

x x ª 1 1º
1 1 «0 1»
¬ ¼

x x
1 1

Effect on unit square, cont.

:L
q
cu
iM
xfm
rl2
n
ag
w
o
t'sh
e Observe:
theu
nitsq
:
are
u
Š Origin invariant under M
Š M can be determined just by knowing how the
ªa b º corners (1,0) and (0,1) are mapped
« c d » >p q r s @ >p' q' r' s' @
¬ ¼ Š a and d give x- and y-scaling
Š b and c give x- and y-shearing
ªa b º ª0 1 1 0 º ª0 a a  b b º
« c d » « 0 0 1 1» « 0 c c  d d »
¬ ¼¬ ¼ ¬ ¼

y y

s r
1

p q x x
1
Rotation Linear transformations

From our observations of the effect on the unit The unit square observations also tell us the 2x2
square, it should be easy to write down a matrix for matrix transformation implies that we are
“rotation about the origin”: representing a point
p' inMapnew coordinate system:
ªa b º ª x º
y y «c d » « y »
¬ ¼¬ ¼
ªxº
>u v @ « »
1 ¬y¼
x ˜u  y ˜ v
x T x
1

ª 1º
Š « »o where u=[a c]T and v=[b d]T are vectors that define a
¬0 ¼ new basis for a linear space.
ª0 º The transformation to this new basis (a.k.a., change
Š « »o
¬ 1¼ of basis) is a linear transformation.

Thus,
ª º
M R(T ) «« »
»
«¬ »¼

Limitations of the 2 x 2 matrix Affine transformations

A 2 x 2 linear transformation matrix allows In order to incorporate the idea that both the basis
and the origin can change, we augment the linear
Š Scaling space u, v with an origin t.
Š Rotation
Š Reflection We call u, v, and t (basis and origin) a frame for an
Š Shearing affine space.

Then, we can represent a change of frame as:


Q: What important operation does that leave out?
p' x ˜u  y ˜ v  t

This change of frame is also known as an affine


transformation.

How do we write an affine transformation with


matrices?
Homogeneous coordinates Rotation about arbitrary points

Idea is to loft the problem up into 3-space, adding a Until now, we have only considered rotation about
third component to every point: the origin.

ªxº With homogeneous coordinates, you can specify a


ªxº « »
«y» o «y» rotation, T, about any point q = [qx qy]T with a
¬ ¼ « »
¬ 1¼ matrix:

And then transform with a 3 x 3 matrix: y y y y

ª x'º ªxº ª1 0 t x º ª x º
« y ' » T (t) « y » «0 1 t » « y » θTTW
T
« » « » « y »« » q
¬«w ' ¼» ¬«1 ¼» ¬«0 0 1 »¼ «¬1 ¼» x x x x

y y

ª1 0 1 º
«0 1 1 2 » 1. Translate q to origin
1 1 « »
«¬0 0 1 »¼
2. Rotate
x x
1 1
3. Translate back

Note: Transformation order is important!!


. . . gives translation!

Points and vectors Barycentric coordinates

From now on, we can represent points as have an A set of points can be used to create an affine frame.
additional coordinate of w=1. Consider a triangle ABC and a point P:

Vectors have an additional coordinate of w=0. Thus,


a change of origin has no effect on vectors.

Q: What happens if we multiply a matrix by a vector?


We can form a frame with an origin C and the vectors
from C to the other vertices:

These representations reflect some of the rules of u AC v B C t C


affine operations on points and vectors:
We can then write P in this coordinate frame:
vector + vector o
scalar ˜ vector o P Du  E v  t
point - point o
point + vector o
point + point o

One useful combination of affine operations is:

p(t ) po  tu
The coordinates (D, E, J) are called the barycentric
Q: What does this describe? coordinates of P relative to A, B, and C.
Computing barycentric coordinates Cross products
In the triangle example: Consider the cross-product of two vectors, u and v.
What is the geometric interpretation of this cross-
product?

we can compute the barycentric coordinates of P:

ª Ax Bx C x º ªD º ª Px º A cross-product can be computed as:


DA EB JC «A By Cy » «E » «P »
« y »« » « y»
¬« 1 1 1 ¼» ¬« J ¼» ¬« 1 ¼» i j k
uu v ux uy uz
Simple matrix analysis gives the solution:
vx vy vz
Px Bx Cx Ax Px Cx Ax Bx Px (u y v z  uz v y )i  (uz v x  u x v z ) j  (u x v y  u y v x )k
Py By Cy Ay Py Cy Ay By Py ª u y v z  uz v y º
1 1 1 1 1 1 1 1 1 « »
D E J « uz v x  u x v z »
Ax Bx Cx Ax Bx Cx Ax Bx Cx «u x v y  u y v x »
¬ ¼
Ay By Cy Ay By Cy Ay By Cy
1 1 1 1 1 1 1 1 1 What happens when u and v lie in the x-y plane?
What is the area of the triangle they span?
Computing the determinant of the denominator
gives:
B x C y  B y C x  Ay C x  Ax C y  Ax B y  Ay B x

Barycentric coords from area ratios Affine and convex combinations


Now, let’s rearrange the equation from two slides
ago: Note that we seem to have added points together,
which we said was illegal, but as long as they have
coefficients that sum to one, it’s ok.
B x C y  B y C x  Ay C x  Ax C y  Ax B y  Ay B x
(B x  Ax )(C y  Ay )  (B y  Ay )(C x  Ax ) We call this an affine combination. More generally:

The determinant is then just the z-component of P D1A1    D n An


(B-A) x (C-A), which is two times the area of triangle
ABC! is a proper affine combination if:

n
Thus, we find:
¦
i 1
Di 1
SArea( PBC ) SArea( APC ) SArea( ABP )
D E J
SArea( ABC ) SArea( ABC ) SArea( ABC ) Note that if the Di ‘s are all positive, the result is more
specifically called a convex combination.
Where SArea(RST) is the signed area of a triangle,
which can be computed with cross-products. Q: Why is it called a convex combination?
Basic 3-D transformations: scaling Translation in 3D

Some of the 3-D transformations are just like the 2-D


ones. ª x 'º ª1 0 0 tx º ªxº
« y '» «0 1 0 ty » «y»
For example, scaling: « » « »« »
«z ' » «0 0 1 tz » «z »
ª x 'º ª sx 0 0 0º ª x º « » « »« »
« y '» «0 ¬1 ¼ ¬0 0 0 1 ¼ ¬1 ¼
sy 0 0» « y »
« » « »« »
«z ' » «0 0 sz 0» « z »
« » « »« »
¬1 ¼ ¬0 0 0 1¼ ¬1 ¼
y y

y y

x x

x x z z

z z

Rotation in 3D Shearing in 3D

Rotation now has more possibilities in 3D: Shearing is also more complicated. Here is one
example:

ª x 'º ª1 b 0 0º ª x º
ª1 0 0 0º
« y '» «0
«0 cosT  sinT 0» 1 0 0» « y »
R x (T ) « » « » « »« »
«0 sinT cosT 0» «z ' » «0 0 1 0» « z »
« » y « » « »« »
¬0 0 0 1¼
¬1 ¼ ¬0 0 0 1¼ ¬1 ¼
ª cosT 0 sinT 0º Ry
« 0 1 0 0»
R y (T ) « »
«  sinT 0 cosT 0» x
« » y
¬ 0 0 0 1¼ Rx y
Rz
ªcosT  sinT 0 0º z
« sinT cosT 0 0»
Rz (T ) « » Use right hand rule
« 0 0 1 0» x
« » x
¬ 0 0 0 1¼
z z

We call this a shear with respect to the x-z plane.


Preservation of affine combinations Properties of affine transformations
A transformation F is an affine transformation if it
preserves affine combinations: Here are some useful properties of affine
transformations:
F (D1A1    D n An ) D1F ( A1 )    D n F ( An )
Š Lines map to lines
where the Ai are points, and: Š Parallel lines remain parallel
n
Š Midpoints map to midpoints (in fact, ratios are
¦ Di 1 always preserved)
i 1

Clearly, the matrix form of F has this property.

One special example is a matrix that drops a


dimension. For example: r
t p'
: q'
ªxº s Æ s
ª1 0 0 0º « » ªxº q : r'
«0 1 0 0 » « y » «y» t
« » «z » « » p
«¬0 0 0 1»¼ « » «¬ 1 »¼
¬ 1¼
pq s p'q'
ratio
This transformation, known as an orthographic qr t q'r'
projection is an affine transformation.

We’ll use this fact later…

Summary

What to take away from this lecture:

Š All the names in boldface.


Š How points and transformations are
represented.
Š What all the elements of a 2 x 2 transformation
matrix do and how these generalize to 3 x 3
transformations.
Š What homogeneous coordinates are and how
they work for affine transformations.
Š How to concatenate transformations.
Š The rules for combining points and vectors
Š The mathematical properties of affine
transformations.

You might also like