Top Banner
03/27/22 ©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte, 2006 All Rights Reserved Textbook: Chapter 5
32

6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

Dec 20, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 1

3D Coordinate Systemsand Transformations

Revision 1.1Copyright Zachary Wartell, University of North Carolina at Charlotte, 2006

All Rights Reserved

Textbook:Chapter 5

Page 2: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 2

3D Coordinate Systems

Z

X

YY

X

Z

Right-handed coordinate

system

Left-handedcoordinate

system

, Larry F. Hodges

Page 3: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 3

Points & Vectors

• 3D affine space: points (locations), vectors (alignment with signed magnitude)

• operations:

– Points: pi - pj = v, pi + v = pj (p + 0 = p)

– Vectors: vi ±vj = vk , vj = a ∙ vk (a R)

length(v), |v| =

dot product: vivj =

2 2 2x y z

cos

j

i i i j i j i j i j

j

i j

x

x y z y x x y y z z

z

v v

Page 4: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 4

• operations:– vectors:

• cross product: vi×vj = vk

.

Also

sin

i i i j j j i j j i j i i j i j j i

i j i j

x y z x y z y z y z x z x z x y x y

v v v v

Points & Vectors (cont.)

Page 5: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 5

Parametric Definition of a Line

Given two points p1 = (x1, y1, z1), p2 = ( x2, y2, z2)

x = x1 + t (x2 - x1)

y = y1 + t (y2 - y1)

z = z1 + t (z2 - z1)

Given a point p1 and a vector v = (xv, yv, zv)

x = x1 + t xv, y = y1 + t yv , z = z1 + t zv

COMPACT FORM: p = p1 + t [p2 - p1] or p = p1 + vt

p1

p2

t = 1

t = 0

t > 1

t < 0

, Larry F. Hodges

Page 6: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 6

Equation of a plane

Ax + By + Cz + D = 0

Alternate Form: A'x + B'y + C'z +D' = 0

where A' = A/d, B' = B/d, C' = C/d, D' = D/d

d =

Distance between a point and the plane is given by

A'x + B'y + C'z +D' (sign indicates which side)

Given Ax + By + Cz + D = 0 Then (A, B, C) is a normal vector

Pf: Given two points p1 and p2 in the plane, the vector (p2 - p1) is in the plane and (A,B,C) • (p2 - p1) = (Ax2 + By2 +Cz2) - (Ax1 + B y1 + Cz1) = ( - D ) - ( - D ) = 0

2 2 2A B C

, Larry F. Hodges

Page 7: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 7

Derivation of Plane Equation

P1

P2

P3

• To derive equation of the plane given three points: p1, p2 , p3

• (p3 - p1) x (p2 - p1) = n, orthogonal vector

• Given a general point p = (x,y,z)

• n • [p - p1] = 0 if p is in the plane.

Or given a point (x,y,z) in the plane and normal vector n then n • (x,y,z) = -D

p

, Larry F. Hodges

Page 8: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 8

Basic Transformations

•Translation

•Scale

•Rotation

•Shear

Page 9: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 9

Translation

1 0 0

0 1 0{1,0}

0 0 1

0 0 0 1

x x

y y

z z

x wt t x

y wt t yw

z wt t z

w w

Point or vector

Page 10: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 10

Scale (about origin)

0 0 0

0 0 0{1,0}

0 0 0

0 0 0 1

x x

y y

z z

x s s x

y s s yw

z s s z

w w

Page 11: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 11

Rotation (about coordinate axis)

• Positive Rotations are defined as follows

Axis of rotation is Direction of positive rotation is

x y to z

y z to x

z x to y

, Larry F. Hodges

Z

Y

X

Page 12: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 12

Rotations

cos sin 0 0

sin cos 0 0( ) :

0 0 1 0

0 0 0 1

1 0 0 0

0 cos sin 0( ) :

0 sin cos 0

0 0 0 1

cos 0 sin 0

0 1 0 0( ) :

sin 0 cos 0

0 0 0 1

z

x

y

R

R

R

Page 13: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 13

Shears

1 0 0

0 1 0{1,0}

0 0 1 0

0 0 0 1

xz xz

yz yz

x SH z SH x

y SH z SH yw

z z

w w

XY sheared on Z

Of course other combinations occur too, e.g. ZX sheared on Y, X sheared on Y,etc.

x

y

z

Page 14: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 14

Rotation About An Arbitrary Axis

Z

p1

p2

Y

X

u

θ

Page 15: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 15

Rotation About An Arbitrary Axis

Z

p1

p2

Y

X

Translate p1 to origin

u'

T(-p1)

u

Page 16: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 16

Rotation About An Arbitrary Axis

Z

Y

X

b

a

c

ux

uy

uz

ß

u'

Rotate u' to u'' in YZ plane (rotation about Y axis, Ry(-β))

2 2

2 2

2 2

cos /

sin /

x z

x y

y z

z

x

a u u

b u u

c u u

u a

u a

Ry(-β)) ∙ T(-p1)

, Larry F. Hodges

Page 17: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 17

Rotation About An Arbitrary Axis

Z

Y

X

b

a

c

ux

uy

uz

ß

u'

2 2

2 2

2 2

cos /

sin /

x z

x y

y z

z

x

a u u

b u u

c u u

u a

u a

u''

Rotate u' to u'' in YZ plane (rotation about Y axis, Ry(-β))

Ry(-β)) ∙ T(-p1)

, Larry F. Hodges

Page 18: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 18

Rotation About An Arbitrary Axis

Z

Y

X

a

c

ux

uy

uz

α

Next, Rotate u'' to Z axis (u''') (rotation about X axis, Rx(α))

cos /

sin /y

a

u

u

u

u''

After Ry(-ß), angle α and u'' lies in the y-z plane.

Rx(α) ∙ Ry(-β) ∙ T(-p1)

, Larry F. Hodges

Page 19: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 19

Rotation About An Arbitrary Axis

Z

Y

X

u''

After Rx(α), u'' lies in the Z axis as u'''.

Next, rotate about Z by θ (Rz(θ))

u'''

θ

Rz(θ) ∙ Rx(α) ∙ Ry(-β) ∙ T(-p1)

Page 20: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 20

R((p1,p2),θ) = T(p1) ∙ Ry(β) ∙ Rx(-α) ∙ Rz(θ) ∙ Rx(α) ∙ Ry(-β) ∙ T(-p1)

Rotation About An Arbitrary Axis

Y

X

Now we’ve rotated about U.

Next, apply the inverse transformations to place u''' back on u

p1

p2

uZ

θ

Page 21: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 21

Rotation About An Arbitrary Axis

Y

X

p1

p2

UZθ

Y

X

p1

p2

UZθ

2

2

2

More compactly:

(( , ), ) = 1

1 1 1

, 1 1 1

1 1 1

where cos , sin

x x y z x z y

y x z y y z x

z x y z y x z

u c c u u c u s u u c u s

u u c u s u c c u u c u s

u u c u s u u c u s u c c

c s

R 1 1 R

1 2

R

M p p MM p p

0

M u

Page 22: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 22

Rotation Representations So Far….

Euler angles-Rx Ry Rz - note order is arbitrary, 6 possible-3 real numbers-interpolation problems-gimbal lock-compose rotation matrix: 27 *’s and 18 +’s

Matrix-9 real numbers-no good way to interpolate rotations-compose rotation matrix: 27 *’s and 18 +’s

Axis-Angle-4 real numbers-again unclear how to interpolate rotations-no clear way to compose rotations (must convert to matrix)

Page 23: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 23

Euler Angles: Gimbal Lock

Occurs when two rotation axes are aligned by an intermediate rotation

Example: Assume Euler order Rz ∙ Ry ∙ Rx

If Ry = 90 degrees, then x-axis aligns with y-axis and

Rz = -Rx

X'

Z

Y

X

Page 24: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 24

Rotation Matrix: Interpolation

a b c a b c

d e f d e f

g h i g h i

?

Page 25: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 25

Axis-Angle: Composition

R(?,?) = R(uk,θk) ∙ R(uk-1,θk-1) ….. R(u1,θ1)

Page 26: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 26

Quaternions

Alternative rotation representation:

4 real numbersinterpolation between quaternions well defined

(“slerp”)no gimbal lockcomposition of quaternions: 16 *’s, 9+’s

(matrix 27 *’s and 18 +’s)

Page 27: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 27

Quaternions

• Rotation representation:

( , ) ( , ( , , ))

cos , sin2 2

x y zs s v v v

s

q v

v u

Relation to axis-angle representation (u,θ) is:

x

y

Z

u

θ

Page 28: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 28

Quaternion Rotation: Basic Idea

• To rotate point p:– represent p as quaternion:

– compute rotated quaternion point representation

– extract standard coordinate representation p' from qp'

(0, )pq p

1 p pq qq q

(0, ) pq p

x

y

Z

u

pp'

Page 29: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 29

Details of Rotation

• How do you multiply quaternions:

• How do you find inverse of quaternion:

• For rotations we assume unit quaternions, hence:

1 2 1 2 1 2 1 2 2 1 1 2( , )s s s s q q v v v v v v

2

12

magnitude:

1inverse: ,

s

s

q v v

q vq

1 , when 1s q v q

Page 30: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 30

Quaternion Rotation: Complete Equation

• To rotate point p:1 1

2

, where ( , )

.... after some algebra .....

( ) 2 ( ) ( )

Note, 26 *'s, 14 +'s versus 9 *'s, 6 +'s for 3x3 matrix-vector oper.

s

s s

p pq qq q q v

p p v p v v p v v p

x

y

Z

u

pp'

Page 31: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 31

1 2 1 2 1 2 1 2 2 1 1 2( , )s s s s q q v v v v v v

Quaternion Rotation Examples:

0

1

2

1

( ) :

(cos( / 2),sin( / 2)(1,0,0)) (0, (1,0,0))

( ) :

(cos( / 2),sin( / 2)(0,1,0)) 0, (0,1,0))

( ) :

(cos( / 2),sin( / 2)(0,0,1)) 0, (0,0,1))

( ) ( ) :

(0, (0,1,0) (0,0,1)) (0, (1,0,0)) ( )

y

x

y

z

z

2 x

R

q

R

q = (

R

q = (

R R

q q R

Recall:

We have examples:

Page 32: 6/19/2015©Zachary Wartell 1 3D Coordinate Systems and Transformations Revision 1.1 Copyright Zachary Wartell, University of North Carolina at Charlotte,

04/18/23©Zachary Wartell 32

How do quaternions help?

• Quaternion composition:

requires 16 *’s, 12+’s while 3x3 matrix composition needs 27*’s and 18+’s

• No gimbal lock• interpolation between two orientations using “spherical

linear interpolation” (slerp) of their quaternions:

-constant angular velocity-unique interpolation-interpolation that is same regardless of coordinatesystem used for computation

1 2 1 2 1 2 1 2 2 1 1 2( , )s s s s q q v v v v v v