28
Transformation Matrices CPSC 453 – Winter 2018 Sonny Chan

Transformation Matrices - University of Calgarypages.cpsc.ucalgary.ca/.../slides/CPSC453-L13-Transformations.pdf · Things to Remember • Operations on vectors can be encoded as

Embed Size (px)

Citation preview

Transformation Matrices

CPSC 453 – Winter 2018Sonny Chan

Today’s Outline

• Transformations in matrix form

- scalar multiplication

- rotation / change of basis

- translation / displacement

- other types of transformations

Matrix Forms of vector operations

Scalar Multiplication

• in geometric form:

• in matrix form:

• what is S?~v

~w

~w = s~v, s 2 R

[~w] = S [~v] , S 2 R2⇥2

S =

s 00 s

Our Example Clock

(as borrowed from your textbook)

Uniform Scaling

Rotation (Change of Basis)

ax

ay

bx

by

~v [~v]A = ARB [~v]B ,

ARB =

cos ✓ � sin ✓sin ✓ cos ✓

Rotation by 45°

R45�

"1p21p2

#=

"0

1

#, R45�

"0

1

#=

"�1p21p2

#

Rotation by -30°

R�30�

"p3212

#=

"1

0

#, R�30�

"0

1

#=

"12p32

#

General Transforms

What happens if we put in generic values for the matrix M?

[~w] = M [~v] ,

M =

a bc d

What does this matrix do? M =

0.5 00 1.5

Non-Uniform Scaling

What does this matrix do? M =

1 10 1

Shearing

"1 1

0 1

#"1

1

#=

"2

1

#,

"1 1

0 1

#"1

0

#=

"1

0

#,

"1 1

0 1

#"x

y

#=

"x+ y

y

#

Shearing

What does this matrix do? M =

�1 00 1

Flipping

"�1 0

0 1

#"x

y

#=

"�x

y

#

Flipping

Composing Transformations

SyR45� =

Sy =

R45� =

When composing transformations,

does order matter?

Order Matters!

SyR45� 6= R45�Sy

What about displacements or

translations?

x0 = ax+ by

y0 = cx+ dy

Affine Transforms

• Matrix multiplication gives as a linear transform:

• For translation, we need an affine transform:

x0 = x+ u

y0 = y + v

for M =

a bc d

for

uv

�2 R2

Homogeneous Coordinates

• A brilliantly convenient “trick” is to add an extra coordinate to our vectors and matrices:

• The result multiplication gives us an affine transform:

2

4x0

y0

1

3

5 =

2

4a b uc d v0 0 1

3

5

2

4xy1

3

5

x0 = ax+ by + u

y0 = cx+ dy + v

Hold on a second!

ax

ay

bx

by

~v ~v = v1ax + v2ay =

2

4v1v2vh

3

5

If we want [~v]B ) [~v]A ,

then what is vh?

versus

free vectors

bound vectors

Reference Frame Transformations

• Our final homogeneous transformation matrix to go between references frames A and B looks like this:

• Where free vectors and bound (position) vectors are encoded differently:

ATB =

ARB ~rB/A

0 1

h~rP/B

i=

2

4r1r21

3

5[~v] =

2

4v1v20

3

5

Things to Remember

• Operations on vectors can be encoded as matrices

• Transforms can be composed by matrix multiplication

- order matters!

• Homogeneous coordinates allow translations to be encoded in matrix form as well

• Free vectors and bound (position) vectors must be encoded differently