133
Transformations I CS5600Computer Graphics by Rich Riesenfeld 27 February 2002 Lecture Set 5

Transformations I CS5600Computer Graphics by Rich Riesenfeld 27 February 2002 Lecture Set 5

  • View
    216

  • Download
    0

Embed Size (px)

Citation preview

Transformations I

CS5600Computer Graphicsby

Rich Riesenfeld

27 February 2002Lect

ure

Set

5

CS5600 2

Transformations and Matrices

• Transformations are functions

• Matrices are functions representations

• Matrices represent linear transf’s

• s'TransfLinear 2Matrices22 Dx

CS5600 3

What is a 2D Linear Transf ?

Recall from Linear Algebra:

. and vectorsand ascalar for

,)()()(:

yx

yTxaTyxaTDefinition

CS5600 4

Example: Scale in x

),2(),2(),(2

:say 2,by in x, Scale

11001010 yxyxyyxx

CS5600 5

Example: Scale in x by 2

What is the graphical view?

CS5600 6

), 00( yx ), 002( yx

), 11( yx ), 112( yx

Scale in x by 2y

x

CS5600 7

x

y

), 002( yx

), 112( yx

yyxx 1010 ,22

yyxx 1010 ,22

CS5600 8

y

), 00( yx

), 11( yx

yyxx 1010 ),(2

yyxx 1010 ),(

yyxx 1010 ),(2

x

CS5600 9

y

yyxx 1010 ),(2

yyxx 1010 ),(

yyxx 1010 ),(2 y

x

CS5600 10

Summary on Scale

• “Scale then add,” is same as

• “Add then scale”

CS5600 11

Matrix Representation

y

x

y

x 2

10

02

Scale in x by 2:

CS5600 12

Matrix Representation

y

x

y

x

220

01

Scale in y by 2:

CS5600 13

Matrix Representation

y

x

y

x

y

x2

2

2

20

02

Overall Scale by 2:

CS5600 14

Matrix RepresentationShowing Same

)(

22

)(

)(2

10

02

10

10

10

10

10

10

yy

xx

yy

xx

yy

xx

CS5600 15

What about Rotation?

Is it linear?

CS5600 16

Rotate by

x

y

)0,1(

)1,0(

CS5600 17

sin

Rotate by : 1st Quadrant

x

y

)0,1(

)sin,(cos

cos

CS5600 18

Rotate by : 1st Quadrant

)sin,(cos)0,1(

CS5600 19

Rotate by : 2nd Quadrant

x

y

)1,0(

)0,1(

CS5600 20

Rotate by : 2nd Quadrant

x

y

cos

sin

)1,0(

CS5600 21

Rotate by : 2nd Quadrant

)cos,sin()1,0(

CS5600 22

Summary of Rotation by

)sin,(cos)0,1(

)cos,sin()1,0(

CS5600 23

Summary (Column Form)

cos

sin

1

0

sin

cos

0

1

CS5600 24

Using Matrix Notation

sin

cos

0

1

cossin

sin-cos

cos

sin-

1

0

cossin

sin-cos

(Note that unit vectors simply copy columns)

CS5600 25

General Rotation by Matrix

cossin

ysin-cos

cossin

sin-cos

yx

x

y

x

CS5600 26

Who had linear algebra?

Who understand matrices?

CS5600 27

What do the off diagonal elements do?

CS5600 28

Off Diagonal Elements

ybx

x

y

x

b 1

01

y

ayx

y

xa

10

1

CS5600 29

Example 1

y

yx

x

y

xyxT

4.0

14.0

01),(

)1,0(

)0,1(

)1,1(

)0,0(

S

x

CS5600 30

Example 1

x

y

yx

x

yxT

4.0

),(

S

)1,0(

)0,1(

)1,1(

)0,0(

CS5600 31

Example 1

y

)1,0(

)4.0,1(

)0,0(

T(S)

yx

x

yxT

4.0

),()4.1,1(

x

CS5600 32

Example 2

y

y

yx

y

xyxT

6.0

10

6.01),(

S

x

)1,0(

)0,1(

)1,1(

)0,0(

CS5600 33

Example 2

x

y

y

yx

yxT

6.0

),(

S

)1,0(

)0,1(

)1,1(

)0,0(

CS5600 34

Example 2

x

y

)1,0(

)0,1()0,0(

T(S)

)1,6.0(

y

yxyxT

6.0 ),(

)1,6.1(

CS5600 35

Summary

Shear in x:

Shear in y:

y

ayx

y

xaShx 10

1

ybx

x

y

x

bShy 1

01

CS5600 36

Double Shear

ab)(10

1

1

01

1

1

b

aa

b

1

1 ab)(

1

01

10

1

b

a

b

a

CS5600 37

Sample Points: unit inverses

0

11

1

01

bb

1

0

10

1

1

aa

CS5600 38

Geometric View of Shear in x

)0,1(

)1,( a )1,0(

)0,1(

)1,1(

Another Geometric View of Shear in x

x39x x

yy

Another Geometric View of Shear in x

40

x

y

CS5600 41

Geometric View of Shear in y

)1,0(

)0,0(

),1( b

)1,0(

)0,1()0,0(

)1,1(

Another Geometric View of Shear in y

h h42

x

y

x

y

Another Geometric View of Shear in y

43

x

y

CS5600 44

“Lazy 1”

100

010

01 0

11

y

x

y

x

CS5600 45

Translation in x

1

y

x

10 10

010

01

yxdx

xd

CS5600 46

Translation in x

1

y

x

10

0

10

10

01

ydy

x

d y

CS5600 47

Homogeneous Coordinates

100

010

01 0

11

y

x

y

x

CS5600 48

Homogeneous Coordinates

0for ,

y

xy

x

1

y

x

CS5600 49

Homogeneous Coordinates

Homogeneous term effects overall scaling

0,For

y

xy

x

y

x

y

x

1100

010

01

11

0

Homogeneous CoordinatesAn infinite number of points correspond to (x,y,1).

They constitute the whole line (tx,ty,t).

x

w

y

w = 1

(tx,ty,t)

(x,y,1)

CS5600 51

We’ve got Affine Transformations

Linear + Translation

CS5600 52

Compound Transformations

• Build up compound transformations by concatenating elementary ones

• Use for complicated motion

• Use for complicated modeling

CS5600 53

Elementary Transformations

• Scale

• Rotate

• Translate

• Shear

• (Reflect)

)(R)(),( dT ydT x

Rf yRf x,

)(),( dSh ydShx

)(),( S yS x

CS5600 54

Refection about y-axis

0

1

0

1

10

01

CS5600 55

Reflection about y-axis

x

y

),( yx),( yx

)0,1()0,1(

CS5600 56

Reflection about x-axis

1

0

1

0

1-0

01

CS5600 57

Reflection about x-axis

x

y

)1,0( ),( yx

),( yx )1,0(

Is Reflection “Elementary?”

• Can we effect reflection in an elementary way?

• (More elementary means scale, shear, rotation, translation.)

58

CS5600 59

Reflection is Scale (-1)

CS5600 60

Example:Move clock hands

x

),( ba

y

CS5600 61

Example:Move clock hands

),( ba

x

y

CS5600 62

Example:Move clock hands

),( ba

x

y

CS5600 63

Example:Move clock hands

y

),( ba

x

CS5600 64

Clock Transformations

• Translate to Origin

• Move hand with rotation

• Move hand back to clock

• Do other hand

CS5600 65

Clock Transformations

15

),(12),(

),()(),(

)(

twhere

baTtRbaTT

baTtRbaTT

b

s

CS5600 66

Clock Transformations

1

y

x

1

10

01

11

10

01

0000

0)cos()sin(

0)sin()cos(

00

b

a

tt

tt

b

a

CS5600 67

Map [a,b] [0,1]

0[ ]

x

a b

x

1

CS5600 68

Map [a,b] [0,1]

• Translate to Origin

• Map x to translated interval

axx

ababaaba ,0,,

CS5600 69

Map [a,b] [0,1]

• Normalize the interval

• Map x to normalized interval

abaxx

1,0,1

,0

abaaab

ab

CS5600 70

Map [a,b] [0,1])( aT x

abS x1

1100

010

01

y

xa

1

yab

ax

100

010

001

ab

CS5600 71

Just Look at

10

01

ab

1 RThis is a homogeneous form for 1D

)( aT x

abS x1

10

1 a

1

x

1

ab

ax

CS5600 72

Map [a,b] [-1,1]

0[ ]

-1 +1x

a bx

2

ba

CS5600 73

Map [a,b] [-1,1]

• Translate center of interval to origin

• Normalize interval to [-1,1]

2

baxx

22 2

1 bax

bax

ab

CS5600 74

Map [a,b] [-1,1]

• Substitute x =a (analogous for x =b) :

12

)(2

2

22

22

22

ab

ab

baa

ab

baa

ab

x

CS5600 75

Now Map [a,b] [c,d]

• First map [a,b] to [0,1]

– (We already did this)

• Then map [0,1] to [c,d]

CS5600 76

Now Map [a,b] [c,d]

• Scale [0,1] by (d-c)

• Then translate by c

• That is, in 1D homogeneous form:

1)(

110

0

10

1 cxcdxcdc

CS5600 77

All Together: [a,b] [c,d]

110

1

10

01

10

0

10

1 xaab

cdc

110

1

10

010

1 xaab

cdc

CS5600 78

Now Map Rectangles

),(minmin yx

),(maxmax vu

),(minmin vu

),(maxmax yx

CS5600 79

Transformation in x and y

yyvv

xxuu

yx

vu

xx

y

x

y

x

minmax

minmax

minmax

minmax

min

min

min

min

,where

1100

10

01

100

00

00

100

10

01

,

This is the Viewport Transformation

• Good for mapping objects from one

coordinate system to another

• This is what we do with windows and

viewports

80

CS5600 81

3D Transformations

• Scale

• Rotate

• Translate

• Shear

)(),(),( dT zdT ydT x

)(),(),( dShzdSh ydShx

)(),(),( S zS yS x

)(),(),( RzR yRx

CS5600 82

3D Scale in x

1000

0100

0010

000

)(

S x

CS5600 83

3D Scale in x

111000

0100

0010

000

z

y

x

z

y

x

S x

CS5600 84

3D Scale in y

111000

0100

000

0001

)(z

y

x

z

y

x

S y

CS5600 85

3D Scale in z

111000

000

0010

0001

)(z

y

x

z

y

x

S z

CS5600 86

Overall 3D Scale

11 1000

0100

0010

0001

)(z

y

x

z

y

x

S

CS5600 87

Overall 3D Scale

Same in x,y and z:

z

y

x

z

y

x

z

y

x

11

What is a Positive Rotation in 3D ?

• Sit at end of given axis

• Look at Origin

• CC Rotation is in Positive direction

88

3D Positive Rotations

x

z

y

CS5600 90

3D Rotation about z-axis by

We have already done this:

11000

0100

00cossin

00sincos

)(z

y

x

Rz

CS5600 91

3D Rotation about x-axis by

y

z

)0,1,0(

)1,0,0(

CS5600 92

3D Rotation about x-axis

11000

0cossin0

0sincos0

0001

)(z

y

x

Rx

3D Rotation about y-axis by

x

z

)0,0,1(

)1,0,0(

93

CS5600 94

3D Rotation about y-axis

11000

0cos0sin

0010

0sin0cos

)(z

y

x

R y

CS5600 95

Elementary Transformations

• Scale

• Rotate

• Translate

• Shear

• (Reflect)

)(),( R yRx)(),( dT ydT x

)(),( S yS x

Rf yRf x,

)(),( dSh ydShx

CS5600 96

Consider an arbitrary 3D rotation

• What is its inverse?

• What is its transpose?

• Can we constructively elucidate this

relationship?

Want to rotate by about arbitrary axis a

a

)(: Ra

x

z

y

97

CS5600 98

First rotate about by

)(: Rzz

a Now in the

(y-z)-plane

x

z

y

CS5600 99

Then rotate about by

x

z

y

)(: Rx x

Rotate in the

(y-z)-plane

a

Now perform rotation about -

x

z

y

)(: Raxisz za Now aligned

with z-axis

100

Now perform rotation about -

x

z

y

)(: Raxisz zaNow aligned

with z-axis

101

CS5600 102

Then rotate about by )(: Rx x

Rotate again in the (y-z)-plane

x

z

y

a

CS5600 103

Then rotate about by )(: Rz z

Now to original position of a

a

x

z

y

We effected a rotation by about arbitrary axis a

a

)(: Ra

x

z

y

104

We effected a rotation by about arbitrary axis a )(: Ra

105

)()()( RRR z xa)( Rz

)()( RRx z

CS5600 106

Rotation about an arbitrary axis

• Rotation about a-axis can be effected by a composition of 5 elementary rotations

• We show arbitrary rotation as succession of 5 rotations about principal axes

CS5600 107

)( Ra

1000

0)cos()sin(0

0)sin()cos(00001

10000100

00)cos()sin(

00)sin()cos(

)(

Ra

1000010000cossin00sincos

1000

0cossin0

0sincos00001

1000010000cossin00sincos

)( Rz

In matrix terms, )( Rz

)( Rx

)( Rx

)( Rz

CS5600 108

1000

0)cos()sin(0

0)sin()cos(00001

10000100

00)cos()sin(

00)sin()cos(

)(

Ra

,)()(1 RaRa

1000010000cossin00sincos

1000

0cossin0

0sincos00001

1000010000cossin00sincos

)( Rz

Similarly, so,

CS5600 109

Recall, tAtBtAB

RtMtRtA

tttt RRMt

RMR .

Consequently, for , RMtRA

because,

RMR tt

CS5600 110

RStMtStRt

RSMtStR

It follows directly that,

CS5600 111

)()(1 RtaRa

)( Rtz

1000

0)cos()sin(0

0)sin()cos(00001

10000100

00)cos()sin(

00)sin()cos(

)(

Ra

1000010000cossin00sincos

1000

0cossin0

0sincos00001

1000010000cossin00sincos

CS5600 112

)()( 1 RtaRa

Constructively, we have shown,

This will be useful later

CS5600 113

3D Translation in x

111000

0100

0010

001

)(z

yd xx

z

y

xd x

d xT x

CS5600 114

3D Translation in y

111000

0100

010

0001

)(zd yy

x

z

y

x

d yd yT y

CS5600 115

3D Translation in z

111000

100

0010

0001

)(d zz

y

x

z

y

x

d zd zT z

CS5600 116

3D Shear in x -direction

111000

0100

0010

001

)(z

y

ayx

z

y

xa

aShx

CS5600 117

3D Shear in x -direction

111000

0100

0010

001

)(z

y

bzx

z

y

xb

bShx

CS5600 118

3D Shears:clamp a principal plane, shear in other 2 DoFs

x

z

y

x

z

y

111000

0100

0010

001

)(z

y

ayx

z

y

xa

aShx

x

z

y

CS5600 120

3D Shear in y -direction

111000

0100

010

0001

)(z

czy

x

z

y

x

ccShy

CS5600 121

3D Shear in y -direction

111000

0100

001

0001

)(z

ydx

x

z

y

x

ddShy

x

z

y

x

z

y

111000

0100

001

0001

)(z

ydx

x

z

y

x

ddShy

CS5600 123

3D Shear in z -direction

111000

010

0010

0001

)(zex

y

x

z

y

x

eeShz

CS5600 124

3D Shear in z

111000

010

0010

0001

)(zex

y

x

z

y

x

eeShz

CS5600 125

3D Shear in z

111000

010

0010

0001

)(zfy

y

x

z

y

x

ffShz

CS5600 126

What is “Perspective?”

• A mechanism for portraying 3D in 2D

• “True Perspective” corresponds to

projection onto a plane

• “True Perspective” corresponds to an

ideal camera image

Many Kinds of Perspective Used

• Mechanical Engineering

• Cartography

• Art

CS5600 128

Perspective in Art

• Naïve (wrong)

• Egyptian

• Cubist (unrealistic)

• Esher

– Impossible (exploits local property)

– Hyperpolic (non-planar)

– etc

CS5600 129

“True” Perspective in 2D

y

x

(x,y)

p

h

CS5600 130

“True” Perspective in 2D

pxpyh

pxy

ph

CS5600 131

“True” Perspective in 2D

px

py

px

px

px

py

px

px

p

pxpx

y

x

y

x

11

This is right answer for screen projection

CS5600 132

“True” Perspective in 2D

11101

010

001

yp

x

y

x

p

End Transformations I

Lect

ure

Set

5

133