lecture 6: normal transformations, 3d transformations

60
Lecture 6: Normal Transformations, 3D Transformations, Euler Angles COMPSCI/MATH 290-04 Chris Tralie, Duke University 2/2/2016 COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler An

Upload: others

Post on 23-Jan-2022

8 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 6: Normal Transformations, 3D Transformations

Lecture 6: Normal Transformations, 3DTransformations, Euler Angles

COMPSCI/MATH 290-04

Chris Tralie, Duke University

2/2/2016

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 2: Lecture 6: Normal Transformations, 3D Transformations

Announcements

I Mini Assignment 2 Out, Due Next Monday 11:55 PMI Online notes coming soon... (for now slides)

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 3: Lecture 6: Normal Transformations, 3D Transformations

Table of Contents

I Linear Functions Continued

B Normal TransformationsB Linear EquationsB 3D Transformations / Euler Angles

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 4: Lecture 6: Normal Transformations, 3D Transformations

Column Vector Walking Interpretation

| |... |

... |~v1 ~v2 . . . ~vk . . . ~vN

| |... |

... |

00...

ak...0

= ak ~vk

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 5: Lecture 6: Normal Transformations, 3D Transformations

Column Vector Walking Interpretation

| |... |

~v1 ~v2 . . . ~vN

| |... |

a1a2...

aN

=N∑

i=1

ai ~vi

Linear combination of column vectors!

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 6: Lecture 6: Normal Transformations, 3D Transformations

Column Vector Walking Interpretation

[−1 10 1

] [uv

]=

[−10

]u +

[11

]v

X

Y

v(1, 1)

u(-1, 0)

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 7: Lecture 6: Normal Transformations, 3D Transformations

Linear Function To Matrix Proof

B Define a linear function L : x ∈ RN → y ∈ RM

B Let Lj = L({

1 k = j0 otherwise

}, k = 1 to N

) | |

... |L1 L2 . . . LN

| |... |

a1a2...

aN

=N∑

i=1

aiLi

B Recall that for a linear function: L(ax +by) = aL(x)+bL(y)

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 8: Lecture 6: Normal Transformations, 3D Transformations

Linear Function To Matrix Proof

B Define a linear function L : x ∈ RN → y ∈ RM

B Let Lj = L({

1 k = j0 otherwise

}, k = 1 to N

)

| |... |

L1 L2 . . . LN

| |... |

a1a2...

aN

=N∑

i=1

aiLi

B Recall that for a linear function: L(ax +by) = aL(x)+bL(y)

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 9: Lecture 6: Normal Transformations, 3D Transformations

Linear Function To Matrix Proof

B Define a linear function L : x ∈ RN → y ∈ RM

B Let Lj = L({

1 k = j0 otherwise

}, k = 1 to N

) | |

... |L1 L2 . . . LN

| |... |

a1a2...

aN

=N∑

i=1

aiLi

B Recall that for a linear function: L(ax +by) = aL(x)+bL(y)

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 10: Lecture 6: Normal Transformations, 3D Transformations

Linear Function To Matrix Proof

B Define a linear function L : x ∈ RN → y ∈ RM

B Let Lj = L({

1 k = j0 otherwise

}, k = 1 to N

) | |

... |L1 L2 . . . LN

| |... |

a1a2...

aN

=N∑

i=1

aiLi

B Recall that for a linear function: L(ax +by) = aL(x)+bL(y)

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 11: Lecture 6: Normal Transformations, 3D Transformations

Linear Function To Matrix Example

f (x , y , z) = (x + y + 2z,3x − 2y)

f (1,0,0) =

f (0,1,0) =

f (0,0,1) =

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 12: Lecture 6: Normal Transformations, 3D Transformations

Square Matrix Inverse

A−1A = I

AA−1 = I

Example:

A =

[2 00 1

],A−1 =

[0.5 00 1

]

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 13: Lecture 6: Normal Transformations, 3D Transformations

Square Matrix Inverse

A−1A = I

AA−1 = I

Example:

A =

[2 00 1

],A−1 =

[0.5 00 1

]

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 14: Lecture 6: Normal Transformations, 3D Transformations

Square Matrix Inverse

A−1A = I

AA−1 = I

Example:

A =

[−1 00 1

],A−1 =

[−1 00 1

]

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 15: Lecture 6: Normal Transformations, 3D Transformations

Square Matrix Product Inverse

(AB)−1 = B−1A−1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 16: Lecture 6: Normal Transformations, 3D Transformations

Matrix Transpose

ATij = Aji

A : M × N ⇐⇒ AT : N ×M

A =

| |... |

... |~v1 ~v2 . . . ~vk . . . ~vN

| |... |

... |

AT =

− ~v1 −− ~v2 −... . . .

...− ~vN −

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 17: Lecture 6: Normal Transformations, 3D Transformations

Matrix Transpose

ATij = Aji

A : M × N ⇐⇒ AT : N ×M

A =

| |... |

... |~v1 ~v2 . . . ~vk . . . ~vN

| |... |

... |

AT =

− ~v1 −− ~v2 −... . . .

...− ~vN −

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 18: Lecture 6: Normal Transformations, 3D Transformations

Matrix Transpose

ATij = Aji

A : M × N ⇐⇒ AT : N ×M

A =

| |... |

... |~v1 ~v2 . . . ~vk . . . ~vN

| |... |

... |

AT =

− ~v1 −− ~v2 −... . . .

...− ~vN −

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 19: Lecture 6: Normal Transformations, 3D Transformations

Matrix Transpose Example

A =

1 2 −2 30 4 5 −16 −4 3 2

AT =

1 0 62 4 −4−2 5 33 −1 2

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 20: Lecture 6: Normal Transformations, 3D Transformations

Transpose of Product Matrix

(AB)T = BT AT

Check dimensions!

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 21: Lecture 6: Normal Transformations, 3D Transformations

Rotation Matrices Inverse

Rθ =

[cos(θ) − sin(θ)sin(θ) cos(θ)

]

R−1θ = R−θ =

[cos(θ) sin(θ)− sin(θ) cos(θ)

]

R−1θ = RT

θ

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 22: Lecture 6: Normal Transformations, 3D Transformations

Rotation Matrices Inverse

Rθ =

[cos(θ) − sin(θ)sin(θ) cos(θ)

]

R−1θ = R−θ =

[cos(θ) sin(θ)− sin(θ) cos(θ)

]

R−1θ = RT

θ

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 23: Lecture 6: Normal Transformations, 3D Transformations

Rotation Matrices Inverse

Rθ =

[cos(θ) − sin(θ)sin(θ) cos(θ)

]

R−1θ = R−θ =

[cos(θ) sin(θ)− sin(θ) cos(θ)

]

R−1θ = RT

θ

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 24: Lecture 6: Normal Transformations, 3D Transformations

Table of Contents

B Linear Functions Continued

I Normal Transformations

B Linear EquationsB 3D Transformations / Euler Angles

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 25: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformations

[cos(θ) − sin(θ)sin(θ) cos(θ)

] [xy

]=

[x cos(θ)− y sin(θ)x sin(θ) + y cos(θ)

]

Before After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 26: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformations

Uh oh....

[2 00 1

] [xy

]=

[2xy

]

Before After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 27: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformations

Uh oh.... [2 00 1

] [xy

]=

[2xy

]

Before After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 28: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

P2

P1

Tangent Vector:~T = ~P2 − ~P1

Normal Vector:~N

Treating as column vectors: T T N = 0COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 29: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

Given Transformation matrix A, transformed tangent vector is

AP2 − AP1 = A(P2 − P1) = AT

Want to find a matrix G s.t. transformed normal GN isorthogonal to AT

(AT )T (GN) = 0

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 30: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

Given Transformation matrix A, transformed tangent vector is

AP2 − AP1 = A(P2 − P1) = AT

Want to find a matrix G s.t. transformed normal GN isorthogonal to AT

(AT )T (GN) = 0

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 31: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

(AT )T (GN) = 0

T T AT GN = 0

T T (AT G)N = 0

We know T T N = 0, so AT G = ITherefore, G = (AT )−1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 32: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

(AT )T (GN) = 0

T T AT GN = 0

T T (AT G)N = 0

We know T T N = 0, so AT G = ITherefore, G = (AT )−1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 33: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

(AT )T (GN) = 0

T T AT GN = 0

T T (AT G)N = 0

We know T T N = 0, so AT G = ITherefore, G = (AT )−1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 34: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

(AT )T (GN) = 0

T T AT GN = 0

T T (AT G)N = 0

We know T T N = 0, so AT G = ITherefore, G = (AT )−1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 35: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformation Corrected

A =

[2 00 1

],G = (AT )−1 = A−1 =

[0.5 00 1

]

Before After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 36: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformations Corrected

A =

[cos(θ) − sin(θ)sin(θ) cos(θ)

],G = (AT )−1 = (A−1)−1 = A

Before After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 37: Lecture 6: Normal Transformations, 3D Transformations

Normal Transformations Corrected

A =

[ 32 10 1

],G = (AT )−1 =

[ 23 0−2

3 1

]

Before After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 38: Lecture 6: Normal Transformations, 3D Transformations

Table of Contents

B Linear Functions ContinuedB Normal Transformations

I Linear Equations

B 3D Transformations / Euler Angles

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 39: Lecture 6: Normal Transformations, 3D Transformations

Linear Equations Geometric Interpretation

Ax = b

[~v1 ~v2

] [ st

]= ~b

X

Y

v1

v2

b

s*v1

t*v2

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 40: Lecture 6: Normal Transformations, 3D Transformations

Linear Equations Geometric Interpretation

Ax = b

What if A has more rows than columns?

X

Y

v1

v2

b

Z

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 41: Lecture 6: Normal Transformations, 3D Transformations

Linear Equations Geometric Interpretation

Ax = b

What if A has more rows than columns?

(AT A)x = (AT b)

X

Y

v1

v2

b

Z

Least Squares solution / PseudoinverseCOMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 42: Lecture 6: Normal Transformations, 3D Transformations

Table of Contents

B Linear Functions ContinuedB Normal TransformationsB Linear Equations

I 3D Transformations / Euler Angles

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 43: Lecture 6: Normal Transformations, 3D Transformations

3D Scale X

2 0 00 1 00 0 1

xyz

=

2xyz

2

1

X

0

-1-1

0

1

Y

2

1

0

-1

2

Z

Before

2

1

X

0

-1-1

-0.5

0

0.5

1

Y

1.5

2

1.5

1

0.5

0

-0.5

-1

2

Z

AfterCOMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 44: Lecture 6: Normal Transformations, 3D Transformations

3D Flip XZ

−1 0 00 1 00 0 −1

xyz

=

−xy−z

2

1

X

0

-1-1

0

1

Y

2

1

0

-1

2

Z

Before

2

1

X

0

-1-1

-0.5

0

0.5

1

Y

1.5

2

1.5

1

0.5

0

-0.5

-1

2

Z

After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 45: Lecture 6: Normal Transformations, 3D Transformations

X Shear Along Y

1 1 00 1 00 0 1

xyz

=

x + yyz

2

1

X

0

-1-1

0

1

Y

2

1

0

-1

2

Z

Before

2

1

X

0

-1-1

-0.5

0

0.5

1

Y

1.5

2

1.5

1

0.5

0

-0.5

-1

2

Z

AfterCOMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 46: Lecture 6: Normal Transformations, 3D Transformations

X Shear Along Y and Z

1 1 10 1 00 0 1

xyz

=

x + y + zyz

2

1

X

0

-1-1

0

1

Y

2

1

0

-1

2

Z

Before

3

2.5

2

1.5

X

1

0.5

00

0.5

1

1.5

Y

2

1.5

1

0.5

0

2

Z

After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 47: Lecture 6: Normal Transformations, 3D Transformations

X Shear Along Y, Y Shear Along Z

1 1 00 1 10 0 1

xyz

=

x + yy + z

z

2

1

X

0

-1-1

0

1

Y

2

1

0

-1

2

Z

Before

2

1

X

0

-1-1

-0.5

0

0.5

1

Y

1.5

2

1.5

1

0.5

0

-0.5

-1

2Z

After

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 48: Lecture 6: Normal Transformations, 3D Transformations

X Shear Along Y, Y Shear Along Z

1 1 00 1 10 0 1

xyz

=

x + yy + z

z

Interactive Demo

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 49: Lecture 6: Normal Transformations, 3D Transformations

3D Homogenous Coordinates

A =

A11 A12 A13 TxA21 A22 A23 TyA31 A32 A33 Tz0 0 0 1

A[

x1

]=

A3×3x +

TxTyTz

1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 50: Lecture 6: Normal Transformations, 3D Transformations

3D Homogenous Coordinates

A =

A11 A12 A13 TxA21 A22 A23 TyA31 A32 A33 Tz0 0 0 1

A[

x1

]=

A3×3x +

TxTyTz

1

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 51: Lecture 6: Normal Transformations, 3D Transformations

2D Rotation Matrix Design: Review

X

Y

cos(θ)

sin(θ)

θ

cos(θ)

θ

-sin(θ)

[cos(θ) − sin(θ)sin(θ) cos(θ)

]

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 52: Lecture 6: Normal Transformations, 3D Transformations

Rotation About X

RX (γ) =

1 0 00 cos(γ) − sin(γ)0 sin(γ) cos(γ)

X,X'

YZ

Y' Z'γ

γ

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 53: Lecture 6: Normal Transformations, 3D Transformations

Rotation About Y

RY (β) =

cos(β) 0 sin(β)0 1 0

− sin(β) 0 cos(β)

X

Y,Y'Z

X'

Z'

β

β

This one hurts the brain a little

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 54: Lecture 6: Normal Transformations, 3D Transformations

Rotation About Z

RZ (α) =

cos(α) − sin(α) 0sin(α) cos(α) 0

0 0 1

X

YZ,Z'

αα

X'Y'

Just like the normal 2D XY rotation

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 55: Lecture 6: Normal Transformations, 3D Transformations

Euler Angles

Can chain these matrices together in any order, such as

RZYX = RX (γ)RY (β)RZ (α)

RXYZ = RZ (α)RY (β)RX (γ)

Resulting matrix is always orthogonal

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 56: Lecture 6: Normal Transformations, 3D Transformations

Euler Angles: Raffle Point Question

How many degrees of freedom to reach any 3D orientation?Give me a reason

B Each column of the matrix is a unit vector

B Every pair of columns is orthogonal.In matrix language, AT A = I

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 57: Lecture 6: Normal Transformations, 3D Transformations

Euler Angles: Raffle Point Question

How many degrees of freedom to reach any 3D orientation?Give me a reason

B Each column of the matrix is a unit vector

B Every pair of columns is orthogonal.In matrix language, AT A = I

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 58: Lecture 6: Normal Transformations, 3D Transformations

Euler Angles: Raffle Point Question

How many degrees of freedom to reach any 3D orientation?Give me a reason

B Each column of the matrix is a unit vector

B Every pair of columns is orthogonal.In matrix language, AT A = I

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 59: Lecture 6: Normal Transformations, 3D Transformations

Euler Angles: Raffle Point Question

How many degrees of freedom to reach any 3D orientation?Give me a reason

B Each column of the matrix is a unit vector

B Every pair of columns is orthogonal.In matrix language, AT A = I

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles

Page 60: Lecture 6: Normal Transformations, 3D Transformations

Euler Angles

Euler Angles Demo

COMPSCI/MATH 290-04 Lecture 6: Normal Transformations, 3D Transformations, Euler Angles