Download - transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

Transcript
Page 1: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

1

mjb – August 23, 2019

1

Computer Graphics

Transformations

transformations.pptx

Mike Bailey

[email protected]

This work is licensed under a Creative Commons Attribution-NonCommercial-NoDerivatives 4.0 International License

mjb – August 23, 2019

2

Computer Graphics

Geometry vs. Topology

Where things are (e.g., coordinates)

Geometry:

How things are connected

Topology:

1

2

3

4

1

2

3

4

1

2

3

4

Geometry = changedTopology = same (1-2-3-4-1)

Geometry = sameTopology = changed (1-2-4-3-1)

Original Object

Page 2: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

2

mjb – August 23, 2019

3

Computer Graphics

3D Coordinate Systems

Right-Handed

X

Y

Z

X

Y

Z

Left-Handed

mjb – August 23, 2019

4

Computer Graphics

Transformations

X

YSuppose you have a point P and you want to move it over by 2 units in X.

How would you change P’s coordinates?

P P’

( , ) ( 2., )x y x yP P P P P

This is known as a coordinate transformation

Page 3: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

3

mjb – August 23, 2019

5

Computer Graphics

Transform the geometry – leave the topology as is

General Form of 3D Linear Transformations

It’s called a “Linear Transformation” because all of the coordinates are raised to the 1st power, that is, there are no x2, x3, etc. terms.

x Ax By Cz D y Ex Fy Gz H z Ix Jy Kz L

mjb – August 23, 2019

6

Computer Graphics

Translation Equations

xx x T

yy y T

zz z T

xT

yT

Page 4: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

4

mjb – August 23, 2019

7

Computer Graphics

Scaling About the Origin

x’ = xꞏSx

y’ = yꞏSy

z’ = zꞏSz

mjb – August 23, 2019

8

Computer Graphics

2D Rotation About the Origin

cos sinx x y

sin cosy x y

Page 5: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

5

mjb – August 23, 2019

9

Computer Graphics

Linear Equations in Matrix Form

x Ax By Cz D y Ex Fy Gz H z Ix Jy Kz L

1 0 0 0 1 1

x A B C D x

y E F G H y

z I J K L z

x consuming column

x’ producing row

y consuming column

z consuming column

constant column

y’ producing row

z’ producing row

mjb – August 23, 2019

10

Computer Graphics

Identity Matrix ( [ I ] )

[ I ] signifies that “Nothing has changed”

1 0 0 0

0 1 0 0

0 0 1 0

1 0 0 0 1 1

x x

y y

z z

x x y y z z

Page 6: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

6

mjb – August 23, 2019

11

Computer Graphics

Matrix Inverse

[M]•[M]-1 = [I]

[M]•[M]-1 = “Nothing has changed”

“Whatever [M] does, [M]-1 undoes”

mjb – August 23, 2019

12

Computer Graphics

Translation Matrix

1 0 0

0 1 0

0 0 1

1 0 0 0 1 1

x

y

z

x T x

y T y

z T z

Quick! What is the inverse of this matrix?

Page 7: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

7

mjb – August 23, 2019

13

Computer Graphics

Scaling Matrix

0 0 0

0 0 0

0 0 0

1 0 0 0 1 1

x

y

z

x S x

y S y

z S z

Quick! What is the inverse of this matrix?

mjb – August 23, 2019

14

Computer Graphics

3D Rotation Matrix About Z

cos sin 0 0

sin cos 0 0

0 0 1 0

1 0 0 0 1 1

x x

y y

z z

Right-handed positive rotation rule

Right-handed coordinates

+90º rotation gives: y’ = x

X

Y

Z

Page 8: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

8

mjb – August 23, 2019

15

Computer Graphics

3D Rotation Matrix About Y

X

Y

Z cos 0 sin 0

0 1 0 0

sin 0 cos 0

1 0 0 0 1 1

x x

y y

z z

+90º rotation gives: x’ = z

mjb – August 23, 2019

16

Computer Graphics

3D Rotation Matrix About X

X

Y

Z 1 0 0 0

0 cos sin 0

0 sin cos 0

1 0 0 0 1 1

x x

y y

z z

+90º rotation gives: z’ = y

Page 9: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

9

mjb – August 23, 2019

17

Computer Graphics

http://xkcd.com

How it Really Works :-)

mjb – August 23, 2019

18

Computer Graphics

Compound Transformations

A

B

Write it

Say it

X

Y

, ,

1 1

A B A B

x x

y yT R T

z z

Q: Our rotation matrices only work around the origin. What if we want to rotate about an arbitrary point (A,B)?

A: Use more than one matrix.

123

Page 10: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

10

mjb – August 23, 2019

19

Computer Graphics

Matrix Multiplication is not Commutative

X

YRotate, then translate

Translate, then rotate

X

Y

X

Y

mjb – August 23, 2019

20

Computer Graphics

Matrix Multiplication is Associative

, ,

1 1

A B A B

x x

y yT R T

z z

, ,

1 1

A B A B

x x

y yT R T

z z

One matrix –the Current Transformation Matrix, or CTM

Page 11: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

11

mjb – August 23, 2019

21

Computer Graphics

Can Multiply All Geometry by One Matrix !

Graphics hardware can do this very quickly!

A

B

X

Y

1 1

[ ]x x

y y

z zM

mjb – August 23, 2019

22

Computer Graphics

OpenGL Will Do the Transformation Compounding for You !

glTranslatef( A, B, C );

glRotatef( (GLfloat)Yrot, 0., 1., 0. );glRotatef( (GLfloat)Xrot, 1., 0., 0. );

glScalef( (GLfloat)Scale, (GLfloat)Scale, (GLfloat)Scale );

glCallList( BoxList );

glT

rans

late

f( A

, B,

C )

;

glR

otat

ef(

(G

Lflo

at)Y

rot,

0., 1

., 0

. );

glR

otat

ef(

(G

Lflo

at)X

rot,

1., 0

., 0

. );

glS

cale

f( (

GLf

loat

)Sca

le, (

GLf

loat

)Sca

le, (

GLf

loat

)Sca

le )

;

glC

allL

ist(

Box

List

);

Typically objects are modeled around their own local origin, so theglTranslate( -A, -B, -C )

step is unnecessary.

Page 12: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

12

mjb – August 23, 2019

23

Computer Graphics

OpenGL Will Do the Transformation Compounding for You !

for( ; ; ){

<< Turn mouse position into Xrot and Yrot >>

glLoadIdentity( );

glTranslatef( A, B, C );

glRotatef( (GLfloat)Yrot, 0., 1., 0. );glRotatef( (GLfloat)Xrot, 1., 0., 0. );

glScalef( (GLfloat)Scale, (GLfloat)Scale, (GLfloat)Scale );

glCallList( BoxList );}

mjb – August 23, 2019

24

Computer Graphics

The Funky Rotation Matrix for an Arbitrary Axis and Angle

A

P

P’

ˆ ˆ( )P A A P

ˆ ˆ( )P P P P A A P

ˆ ˆ ˆ ˆ ˆ ˆ0Q A P A P A P A P A P P A P

Q

P

P

Page 13: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

13

mjb – August 23, 2019

25

Computer Graphics

' ' 'P P P

'P P ' cos sinP P Q

ˆ ˆ ˆ ˆ ˆ' ( ) cos ( ) sinP A A P P A A P A P

The Funky Rotation Matrix for an Arbitrary Axis and Angle

mjb – August 23, 2019

26

Computer Graphics

ˆ ˆ( )x x x y x z

y x y y y z

z x z y z z

A A A A A A

A A P A A A A A A P

A A A A A A

The Funky Rotation Matrix for an Arbitrary Axis and Angle

0

ˆ 0

0

z y

z x

y x

A A

A P A A P

A A

Page 14: transformations - College of Engineeringweb.engr.oregonstate.edu/~mjb/cs491/Handouts/... · 2 mjb –August 23, 2019 3 Computer Graphics 3D Coordinate Systems Right-Handed X Y Z X

14

mjb – August 23, 2019

27

Computer Graphics

The Funky Rotation Matrix for an Arbitrary Axis and Angle

ˆ ˆ ˆ ˆ ˆ' ( ) cos ( ) sinP A A P P A A P A P

0

' cos sin 0

0

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

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

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

A A A A A A A A A A A A A A

P A A A A A A I A A A A A A A A P

A A A A A A A A A A A A A A

1 0

cos 1 sin 0

1 0

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

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

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

A A A A A A A A A A A A A A

M A A A A A A A A A A A A A A

A A A A A A A A A A A A A A

mjb – August 23, 2019

28

Computer Graphics

The Funky Rotation Matrix for an Arbitrary Axis and Angle

cos 1 cos sin cos sin

cos sin cos 1 cos sin

cos sin cos sin cos 1

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

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

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

A A A A A A A A A A A A A A

M A A A A A A A A A A A A A A

A A A A A A A A A A A A A A

1 0

cos 1 sin 0

1 0

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

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

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

A A A A A A A A A A A A A A

M A A A A A A A A A A A A A A

A A A A A A A A A A A A A A

For this to be correct, A must be a unit vector