+ All Categories
Home > Documents > Affine Transformations - University of Texas at Austin

Affine Transformations - University of Texas at Austin

Date post: 03-Feb-2022
Category:
Upload: others
View: 5 times
Download: 1 times
Share this document with a friend
33
University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell Affine Transformations
Transcript
Page 1: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell

Affine Transformations

Page 2: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 2

Logistics

Required reading:Watt, Section 1.1.

Further reading:Foley, et al, Chapter 5.1-5.5.David F. Rogers and J. Alan Adams, MathematicalElements for Computer Graphics, 2nd Ed., McGraw-Hill, New York, 1990, Chapter 2.

Logistics:HW #1 handed out MondayProject #1 due on Monday, artifact on followingMonday.

Page 3: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 3

Geometric transformations

Geometric transformations will map points in onespace to points in another: (x',y',z') = f(x,y,z).These transformations can be very simple, such asscaling each coordinate, or complex, such as non-linear twists and bends.We'll focus on transformations that can berepresented easily with matrix operations.We'll start in 2D...

Page 4: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 4

Representation

We can represent a point, p = (x,y), in the plane

as a column vector

as a row vector!

x

y

"

# $ %

& '

!

x y[ ]

Page 5: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 5

Representation, cont.

We can represent a 2-D transformation M by a matrix

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

If p is a row vector, MT goes on the right:

We will use column vectors.

!

" p = pMT

" x " y [ ] = x y[ ]a c

b d

#

$ %

&

' ( !

" p = Mp

" x

" y

#

$ % &

' ( =

a b

c d

#

$ %

&

' (

x

y

#

$ % &

' ( !

M =a b

c d

"

# $

%

& '

Page 6: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 6

Two-dimensional transformations

Here's all you get with a 2 x 2 transformationmatrix M:

So:

We will develop some intimacy with theelements a, b, c, d…

!

" x

" y

#

$ % &

' ( =

a b

c d

#

$ %

&

' (

x

y

#

$ % &

' (

!

" x = ax + by

" y = cx + dy

Page 7: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 7

Identity

Suppose we choose a=d=1, b=c=0:Gives the identity matrix:

Doesn't move the points at all!

1 0

0 1

"

# $

%

& '

Page 8: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 8

Scaling

Suppose b=c=0, but let a and d take on any positive value:Gives a scaling matrix:

Provides differential (non-uniform) scaling in x and y:

!

a 0

0 d

"

# $

%

& '

!

" x = ax

" y = dy

!

2 0

0 2

"

# $

%

& '

!

1 2 0

0 2

"

# $

%

& '

Page 9: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 9

Reflection

Suppose b=c=0, but let either a or d go negative.Examples:

!

"1 0

0 1

#

$ %

&

' (

!

1 0

0 "1

#

$ %

&

' (

Page 10: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 10

Shear

Now leave a=d=1 and experiment with bThe matrix

gives:!

1 b

0 1

"

# $

%

& '

!

" x = x + by

" y = y

!

1 1

0 1

"

# $

%

& '

Page 11: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 11

Effect on unit square

Let's see how a general 2 x 2 transformationM affects the unit square:

!

a b

c d

"

# $

%

& ' p q r s[ ] = ( p ( q ( r ( s [ ]

a b

c d

"

# $

%

& ' 0 1 1 0

0 0 1 1

"

# $

%

& ' =

0 a a + b b

0 c c + d d

"

# $

%

& '

Page 12: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 12

Effect on unit square, cont.

Observe:Origin invariant under MM can be determined just by knowing how thecorners (1,0) and (0,1) are mappeda and d give x- and y-scalingb and c give x- and y-shearing

Page 13: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 13

Rotation

From our observations of the effect on the unit square, itshould be easy to write down a matrix for “rotation aboutthe origin”:

Thus !

1

0

"

# $ %

& ' (

cos())

sin())

"

# $

%

& '

0

1

"

# $ %

& ' (

*sin())

cos())

"

# $

%

& '

!

MR

= R(") =cos(") #sin(")

sin(") cos(")

$

% &

'

( )

Page 14: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 14

Linear transformationsThe unit square observations also tell us the 2x2 matrix transformationimplies that we are representing a point in a new coordinate system:

where u=[a c]T and v=[b d]T are vectors that define a new basis for alinear space.The transformation to this new basis (a.k.a., change of basis) is alinear transformation.!

" p = Mp

=a b

c d

#

$ %

&

' ( x

y

#

$ % &

' (

= u v[ ]x

y

#

$ % &

' (

= x )u + y ) v

Page 15: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 15

Limitations of the 2 x 2 matrix

A 2 x 2 linear transformation matrix allowsScalingRotationReflectionShearing

Q: What important operation does thatleave out?

Page 16: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 16

Affine transformations

In order to incorporate the idea that both the basis and theorigin can change, we augment the linear space u, v withan origin t.Note that while u and v are basis vectors, the origin t is apoint.We call u, v, and t (basis and origin) a frame for an affinespace.Then, we can represent a change of frame as:

This change of frame is also known as an affinetransformation.How do we write an affine transformation with matrices?!

" p = x #u + y # v + t

Page 17: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 17

Homogeneous CoordinatesTo represent transformations among affine frames, we can loft theproblem up into 3-space, adding a third component to every point:

Note that [a c 0]T and [b d 0]T represent vectors and[tx ty 1]T, [x y 1]T and [x' y' 1]T represent points.

!

" p = Mp

=

a b tx

c d ty

0 0 1

#

$

% % %

&

'

( ( (

x

y

1

#

$

% % %

&

'

( ( (

= u v t[ ]

x

y

1

#

$

% % %

&

'

( ( (

= x )u + y ) v +1) t

Page 18: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 18

Homogeneous coordinatesThis allows us to perform translation as well as the linear

transformations as a matrix operation:

!

" p = MTp

" x

" y

1

#

$

% % %

&

'

( ( (

=

1 0 tx

0 1 ty

0 0 1

#

$

% % %

&

'

( ( (

x

y

1

#

$

% % %

&

'

( ( (

" x = x + tx

" y = y + ty

!

1 0 1

0 1 1 2

0 0 1

"

#

$ $ $

%

&

' ' '

Page 19: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 19

Rotation about arbitrary points

1. Translate q to origin2. Rotate3. Translate backLine up the matrices for these step in right to left order and multiply.

Note: Transformation order is important!!

Until now, we have only considered rotation about the origin.

With homogeneous coordinates, you can specify a rotation, Rq,about any point q = [qx qy 1]T with a matrix:

Page 20: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 20

Points and vectorsFrom now on, we can represent points as have an additional coordinate of w=1.

Vectors have an additional coordinate of w=0. Thus, a change of origin has noeffect on vectors.

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

These representations reflect some of the rules of affine operations on points andvectors:

One useful combination of affine operations is:

Q: What does this describe?

!

vector + vector "

vector # vector "

point $point "

point + vector "

point + point "

!

p(t) = p0 + tv

Page 21: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 21

Barycentric coordinatesA set of points can be used to create an affine frame. Consider atriangle ABC and a point p:

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

We can then write P in this coordinate frame

The coordinates (α, β, γ) are called the barycentric coordinates ofp relative to A, B, and C.

A

BC

p

!

!

p ="u+ #v + t

!

u = A"C v = B"C t = C

Page 22: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 22

Computing barycentric coordinatesFor the triangle example we can compute the barycentric

coordinates of P:

Cramer’s rule gives the solution:

Computing the determinant of the denominator gives:

!

"A + #B + $C =

Ax Bx Cx

Ay By Cy

1 1 1

%

&

' ' '

(

)

* * *

"

#

$

%

&

' ' '

(

)

* * *

=

px

py

1

%

&

' ' '

(

)

* * *

!

BxCy " ByCx + AyCx " AxCy + AxBy " AyBx!

" =

px Bx Cx

py By Cy

1 1 1

Ax Bx Cx

Ay By Cy

1 1 1

# =

Ax px Cx

Ay py Cy

1 1 1

Ax Bx Cx

Ay By Cy

1 1 1

$ =

Ax Bx px

Ay By py

1 1 1

Ax Bx Cx

Ay By Cy

1 1 1

Page 23: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 23

Cross productsConsider the cross-product of two vectors, u and v. What is

the geometric interpretation of this cross-product?A cross-product can be computed as:

What happens when u and v lie in the x-y plane? What is thearea of the triangle they span?

!

u" v =

i j k

ux uy uz

vx vy vz

= (uyvz # uzvy )i + (uzvx # uxvz)j+ (uxvy # uyvx )k

=

uyvz # uzvyuzvx # uxvzuxvy # uyvx

$

%

& & &

'

(

) ) )

Page 24: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 24

Barycentric coords from area ratiosNow, let’s rearrange the equation from two slides ago:

The determinant is then just the z-component of(B-A) × (C-A), which is two times the area of triangle ABC!Thus, we find:

Where SArea(RST) is the signed area of a triangle, which canbe computed with cross-products.

!

BxCy " ByCx + AyCx " AxCy + AxBy " AyBx

= (Bx " Ax )(Cy " Ay ) " (By " Ay )(Cx " Ax )

!

" =SArea(pBC)

SArea(ABC)# =

SArea(ApC)

SArea(ABC)$ =

SArea(ABp)

SArea(ABC)

Page 25: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 25

Affine and convex combinationsNote that we seem to have added points together, which we said wasillegal, but as long as they have coefficients that sum to one, it’s ok.

We call this an affine combination. More generally

is a proper affine combination if:

Note that if the αi ‘s are all positive, the result is more specifically called aconvex combination.

Q: Why is it called a convex combination?

1

1n

i

i

!=

="

!

p ="1p1 +K+"

npn

Page 26: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 26

Basic 3-D transformations: scaling

Some of the 3-D transformations are just likethe 2-D ones.

For example, scaling:

!

" x

" y

" z

1

#

$

% % % %

&

'

( ( ( (

=

sx 0 0 0

0 sy 0 0

0 0 sz 0

0 0 0 1

#

$

% % % %

&

'

( ( ( (

x

y

z

1

#

$

% % % %

&

'

( ( ( (

Page 27: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 27

Translation in 3D

!

" x

" y

" z

1

#

$

% % % %

&

'

( ( ( (

=

1 0 0 tx

0 1 0 ty

0 0 1 tz

0 0 0 1

#

$

% % % %

&

'

( ( ( (

x

y

z

1

#

$

% % % %

&

'

( ( ( (

Page 28: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 28

Rotation in 3DRotation now has more possibilities in 3D:

xR

yR

zR

Use right hand rule

!

Rx (") =

1 0 0 0

0 cos(") #sin(") 0

0 sin(") cos(") 0

0 0 0 1

$

%

& & & &

'

(

) ) ) )

Ry (") =

cos(") 0 sin(") 0

0 1 0 0

#sin(") 0 cos(") 0

0 0 0 1

$

%

& & & &

'

(

) ) ) )

Rz(") =

cos(") #sin(") 0 0

sin(") cos(") 0 0

0 0 1 0

0 0 0 1

$

%

& & & &

'

(

) ) ) )

Page 29: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 29

Shearing in 3D

Shearing is also more complicated. Here is oneexample:

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

!

" x

" y

" z

1

#

$

% % % %

&

'

( ( ( (

=

1 b 0 0

0 1 0 0

0 0 1 0

0 0 0 1

#

$

% % % %

&

'

( ( ( (

x

y

z

1

#

$

% % % %

&

'

( ( ( (

Page 30: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 30

Preservation of affine combinationsA transformation F is an affine transformation if it preserves affine

combinations:

where the pi are points, and:

Clearly, the matrix form of F has this property.One special example is a matrix that drops a dimension. For example:

This transformation, known as an orthographic projection, is an affinetransformation.

We’ll use this fact later…

1

1n

i

i

!=

="

!

" x

" y

1

#

$

% % %

&

'

( ( (

=

1 0 0 0

0 1 0 0

0 0 0 1

#

$

% % %

&

'

( ( (

x

y

z

1

#

$

% % % %

&

'

( ( ( (

!

F("1p1 +K+"

npn ) ="

1F(p1 ) +K+"

nF(pn )

Page 31: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 31

Properties of affine transformations

Here are some useful properties of affinetransformations:

Lines map to linesParallel lines remain parallelMidpoints map to midpoints (in fact, ratios arealways preserved)

!

ratio =pq

qr=

s

t=

" p " q

" q " r

Page 32: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 32

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 matrixdo and how these generalize to 3 x 3 transformations.What homogeneous coordinates are and how they workfor affine transformations.How to concatenate transformations.The rules for combining points and vectorsThe mathematical properties of affine transformations.

Page 33: Affine Transformations - University of Texas at Austin

University of Texas at Austin CS384G - Computer Graphics Fall 2010 Don Fussell 33

Next class: Shading

Topics we’ll cover:

- How does light interact with surfaces?

- What approximations do we use to model this interaction in computer graphics?Read:

Watt, sections 6.2 – 6.3

Optional Reading:Watt, chapter 7.


Recommended