Jinxiang Chai CSCE441: Computer Graphics 3D Transformations 0

Preview:

Citation preview

Jinxiang Chai

CSCE441: Computer Graphics3D Transformations

1

Outline

2D Coordinate transformation

Composite transformation

3D transformation

Required readings: HB 7-8, 9-1 to 9-9

2

Image space

Coordinate Transform: 3D Geometry Pipeline

3

Normalized project

space

View spaceWorld spaceObject space

Aspect ratio &

resolution

Focal length

Rotate and translate the

camera

Coordinate Transformation: 3D Modeling/Design

Coordinate transformation from one reference frame to another

4

Coordinate Transformation: Animation/Robotics

How to model 2D movement of animated characters or robots?

5

Click here

Coordinate Transformation

Coordinate transformation from one reference frame to another

6

Coordinate Transformation

Coordinate transformation from one reference frame to another

7

Local reference frame

Coordinate Transformation

Coordinate transformation from one reference frame to another

8

Local reference frame

Global reference frame

Coordinate Transformation

Coordinate transformation from one reference frame to another

?

9

Local reference frame

Global reference frame

Review – Vector Operations

Dot Product

v w

10

Review – Vector Operations

Dot Product: measuring similarity between two vectors

v w

)cos(|||| wvwv

11

Review – Vector Operations

Dot Product: measuring similarity between two vectors

v w

)cos(|||| wvvw

12

Review – Vector Operations

Dot Product: measuring similarity between two vectors

v w

1vvUnit vector:

13

Review – Vector Operations

Dot Product: measuring similarity between two vectors

v w

)cos(|||| wvwv

14

Review – Vector Operations

Dot Product: measuring similarity between two vectors

v w

0wv

15

Review – Vector Operations

Cross Product: measuring the area determined by two vectors

16

v w

Review – Vector Operations

Cross Product: measuring the area determined by two vectors

sin 2*v w v w u area u

17

v w

u

2D Coordinates

2D Cartesian coordinate system:

P: (x,y)

i

j

o

18

2D Coordinate Transformation

2D Cartesian coordinate system:

P: (x,y)

i

j

o x

y1 ii

1 jj

0 ji

19

2D Coordinate Transformation

2D Cartesian coordinate system:

P: (x,y)

i

j

o x

y

1 ii

1 jj

0 ji

20

jyixop

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

21

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

22

Given the coordinates (x’,y’) in i’j’

- how to compute the coordinates (x,y) in ij?

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

23

Given the coordinates (x’,y’) in i’j’

- how to compute the coordinates (x,y) in ij?

0x

0y

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

),( 00 yx

24

Given the coordinates (x’,y’) in i’j’

- how to compute the coordinates (x,y) in ij?

1100

cossin

sincos

10

0

y

x

y

x

y

x

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

jyixop

ji ij

),( 00 yx

25

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

jyixop

jyixpo

ji ij

),( 00 yx

26

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

jyixop

jyixpo

jyixoo

00

ji ij

),( 00 yx

27

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

poooop

ji ij

),( 00 yx

28

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

poooop

jyixop

jyixpo

jyixoo

00

ji ij

),( 00 yx

29

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

poooop

ji ij

jyixjyixjyix

00

),( 00 yx

30

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

poooop

ji ij

jyixjyixjyix

00

jyixjyyixx

)()( 00

),( 00 yx

31

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

poooop

ji ij

jyixjyixjyix

00

jyixjyyixx

)()( 00

y

xji

yy

xxji

0

0),( 00 yx

32

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

yy

xxji

0

0

),( 00 yx

33

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

yy

xxji

0

0

y

xjiji

yy

xx 1

0

0

),( 00 yx

34

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

yy

xxji

0

0

y

xjiji

yy

xx 1

0

0

y

xji

j

i

yy

xxT

T

0

0

),( 00 yx

35

10

01

jjij

jiii

j

iji

T

T

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

36

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

),( 00 yx

37

110010

0

y

x

yjjij

xjiii

y

xTT

TT

2D Coordinate Transformation

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

38

What does this column vector mean?

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

39

What does this column vector mean? Vector i’ in the new reference system

ii T

ij T

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

40

What does this column vector mean?

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

41

What does this column vector mean? Vector j’ in the new reference system

ji T

jj T

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

42

What does this column vector mean?

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

y

xji

j

i

yy

xxT

T

0

0

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

43

What does this column vector mean? The old origin in the new reference system

2D Coordinate Transformation

2D translation

pj

i

i

j

o

o

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

44

2D Coordinate Transformation

2D translation

pj

i

i

j

o

o

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

?

? ?

?

45

2D Coordinate Transformation

2D translation

pj

i

i

j

o

o

110010

0

y

x

yjjij

xjiii

y

xTT

TT

1

0

0

1

),( 00 yx

46

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

?

47

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

1100

cos

10

0

y

x

yjjij

xji

y

xTT

T

),( 00 yx

?

48

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

1100

sin

cos

10

0

y

x

yjj

xji

y

xT

T

),( 00 yx

49

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

1100

sin

cos

10

0

y

x

yjj

xji

y

xT

T

),( 00 yx

?

50

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

1100

sin

sincos

10

0

y

x

yjj

x

y

xT

),( 00 yx

51

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

1100

sin

sincos

10

0

y

x

yjj

x

y

xT

),( 00 yx

?

52

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o

o

1100

cossin

sincos

10

0

y

x

y

x

y

x

),( 00 yx

53

2D Coordinate Transformation

An alternative way to look at the problem

i

j

o

P=[x,y]j

i

o ),( 00 yx

54

- set up a transformation that superimposes the x’y’ axes onto the xy axis

1

y

x

2D Coordinate Transformation

An alternative way to look at the problem

i

j

o

P=[x,y]j

i

o ),( 00 yx

55

- set up a transformation that superimposes the x’y’ axes onto the xy axis

1100

10

01

0

0

y

x

y

x

2D Coordinate Transformation

An alternative way to look at the problem

i

j

o

P=[x,y]

j

io ),( 00 yx

56

- set up a transformation that superimposes the x’y’ axes onto the xy axis

1100

10

01

100

0cossin

0sincos

0

0

y

x

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’)

i

j

o

p

j

io ),( 00 yx

57

1100

10

01

100

0cossin

0sincos

10

0

y

x

y

x

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’) How to transform the point from (x’,y’) to

(x,y)?

i

j

o

p

j

io ),( 00 yx

58

1100

10

01

100

0cossin

0sincos

10

0

y

x

y

x

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’) How to transform the point from (x’,y’) to

(x,y)? Invert the matrix!

i

j

o

p

j

io ),( 00 yx

59

1100

0cossin

0sincos

100

10

01

1

11

0

0

y

x

y

x

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’) How to transform the point from (x’,y’) to

(x,y)? Invert the matrix!

i

j

o

p

j

io ),( 00 yx

60

1100

0cossin

0sincos

100

10

01

1

11

0

0

y

x

y

x

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’) How to transform the point from (x’,y’) to

(x,y)? Invert the matrix!

i

j

o

p

j

io ),( 00 yx

61

1100

0cossin

0sincos

100

10

01

1

11

0

0

y

x

y

x

y

x

100

10

01

0

0

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’) How to transform the point from (x’,y’) to

(x,y)? Invert the matrix!

i

j

o

p

j

io ),( 00 yx

62

1100

0cossin

0sincos

100

10

01

1

11

0

0

y

x

y

x

y

x

100

10

01

0

0

y

x

2D Coordinate Transformation

An alternative way to look at the problem This transforms the point from (x,y) to (x’,y’) How to transform the point from (x’,y’) to

(x,y)? Invert the matrix!

i

j

o

p

j

io ),( 00 yx

63

1100

0cossin

0sincos

100

10

01

1

11

0

0

y

x

y

x

y

x

100

10

01

0

0

y

x

100

0cossin

0sincos

2D Coordinate Transformation

Same results!

pj

i

i

j

o

o

1100

cossin

sincos

10

0

y

x

y

x

y

x

),( 00 yx

64

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o o

1???

???

???

1

y

x

y

x

30

65

2D Coordinate Transformation

2D translation&rotation

pj

i

i

j

o o

1100

030cos30sin

030sin30cos

1

y

x

y

x

30

66

2D Coordinate Transformation

2D translation&rotation

p

j

i

i

j

oo

1???

???

???

1

y

x

y

x

45

67

2D Coordinate Transformation

2D translation&rotation

p

j

i

i

j

oo

1100

045cos45sin

045sin45cos

1

y

x

y

x

45

68

2D Coordinate Transformation

2D translation&rotation

p

j

i

i

j

o

)2,4( o

1???

???

???

1

y

x

y

x

45

69

2D Coordinate Transformation

2D translation&rotation

p

j

i

i

j

o

)2,4( o

1100

245cos45sin

445sin45cos

1

y

x

y

x

45

70

Composite 2D Transformation

How to model 2D movement of characters or robots?

71

Click here

Composite 2D Transformation

A 2D lamp character

1

2

3

),,( 0yx

3c

2c

1c

0c

A

72

0

Composite 2D Transformation

A 2D lamp character – skeleton size3l

A2l

1l

0l

73

Composite 2D Transformation

How can we draw the character given the pose ?

1

2

3

),,( 0yx

3c

2c

1c

0c

A

74

),,,,,( 3210 yx

),,( 0yx

3c2c

0c

A1c

Articulated Character

Local reference frames with a default pose (0,0,0,0,0,0)

Composite 2D Transformation

What’s the pose?

)1,5(

76

?)?,?,?,,1,5(

300

Composite 2D Transformation

What’s the pose?

)1,5(

77

)90,0,90,30,1,5(

300

Composite 2D Transformation

A 2D lamp character

1

2

3

3c

2c

1c

A

Given , , how to compute the global position of a point A?

),,,,,( 3210 yx

?

),,( 0yx0c

78

Composite 2D Transformation

What’s local coordinate ?

1

2

3

3c

2c

1c

A

?

A

),,( 0yx0c

79

Composite 2D Transformation

What’s local coordinate ?

1

2

3

3c

2c

1c

A

?

A

1

03

0

l

p

),,( 0yx0c

03221100 )()0,()()0,()()0,()(),( pRlTRlTRlTRyxTp 80

Composite 2D Transformation

What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

?

),,( 0yx0c

1

00

l

p

03221100 )()0,()()0,()()0,()(),( pRlTRlTRlTRyxTp

100

010

01

)0,(2

2

l

lT

81

100

0cossin

0sincos

)( 33

33

3

R

Composite 2D Transformation

What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

?

),,( 0yx0c

1

00

l

p

03221100 )()0,()()0,()()0,()(),( pRlTRlTRlTRyxTp

100

010

01

)0,(1

1

l

lT

82

100

0cossin

0sincos

)( 22

22

2

R

Composite 2D Transformation

What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

?

),,( 0yx0c

1

00

l

p

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

100

10

001

),0( 00 llT

83

100

0cossin

0sincos

)( 11

11

1

R

Composite 2D Transformation

What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

?

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

1

00

l

p

100

cossin

sincos

)(),( 00

00

0 y

x

RyxT

84

Composite 2D Transformation

What’s the current coordinate A ?

1

2

3

3c

2c

1c

A

03221100 )()0,()()0,()(),0()(),( pRlTRlTRlTRyxTp

),,( 0yx0c

85

How to Animate the Character?

A 2D lamp character

1

2

3

),,( 0yx

3c

2c

1c

0c

A

86

How to Animate the Character?

Keyframe animation

- Manually pose the character by choosing appropriate values for

- Linearly interpolate the inbetween poses.

- Works for any types of articulated characters!

87

),,,,,( 3210 yx

3D Transformation

A 3D point (x,y,z) – x,y, and z coordinates We will still use column vectors to represent

points Homogeneous coordinates of a 3D point

(x,y,z,1) Transformation will be performed using 4x4

matrix

x

y

z

88

Right-handed Coordinate System

x

y

z

;zyx ;xzy yxz

Left hand coordinate system

Not used in this class and

Not in OpenGL 89/94

3D Transformation

Very similar to 2D transformation

Translation transformation

11000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

Homogenous coordinates

90

3D Transformation

Very similar to 2D transformation

Scaling transformation

11000

000

000

000

1

z

y

x

s

s

s

z

y

x

z

y

x

Homogenous coordinates

91

3D Transformation

3D rotation is done around a rotation axis Fundamental rotations – rotate about x, y, or

z axes Counter-clockwise rotation is referred to as

positive rotation (when you look down negative axis)

x

y

z

+

92

3D Transformation

Rotation about z – similar to 2D rotation

x

y

z

+

11000

0100

00cossin

00sincos

1

z

y

x

z

y

x

zz

yxy

yxx

'

cossin'

sincos'

93

3D Transformation

Rotation about y: z -> y, y -> x, x->z

11000

0cos0sin

0010

0sin0cos

1

z

y

x

z

y

x

yy

xzx

xzz

'

cossin'

sincos'

y

z

x

x

y

z

94

3D Transformation

Rotation about x (z -> x, y -> z, x->y)

x

y

z

11000

0cossin0

0sincos0

0001

1

z

y

x

z

y

x

xx

zyz

zyy

'

cossin'

sincos'

z

x

y

95

Inverse of 3D Transformations

Invert the transformation In general, X= AX’->x’=A-1X

11000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

1

'

'

'

1000

100

010

001

1

z

y

x

t

t

t

z

y

x

x

y

x

11000

0100

00cossin

00sincos

1

z

y

x

z

y

x

1

'

'

'

1000

0100

00cossin

00sincos

1

z

y

x

z

y

x

)(zR)( zR

T(tx,ty,tz)T(-tx,-ty,-tz)

3D Rotation about Arbitrary Axes

Rotate p about the by the angle

x

y

zr

),,( zyxp

r

97

3-D Rotation General rotations in 3-D require rotating

about an arbitrary axis of rotation

Deriving the rotation matrix for such a rotation directly is a good exercise in linear algebra

The general rotation matrix is a combination of coordinate-axis rotations and translations!

98

3D Rotation about Arbitrary Axes

Rotate p about the by the angle

x

y

zr

),,( zyxp

r

99

3-D Rotation General rotations in 3-D require rotating about

an arbitrary axis of rotation

Deriving the rotation matrix for such a rotation directly is a good exercise in linear algebra

Standard approach: express general rotation as composition of canonical rotations Rotations about x, y, z

100

Composing Canonical Rotations Goal: rotate about arbitrary vector r by θ

Idea: we know how to rotate about x,y,zSet up a transformation that superimposes

rotation axis onto one coordinate axisRotate about the coordinate axisTranslate and rotate object back via inverse of

the transformation matrix

101

Composing Canonical Rotations Goal: rotate about arbitrary vector r by θ

Idea: we know how to rotate about x,y,zSo, rotate about z by - until r lies in the xz

planeThen rotate about y by -β until r coincides

with +zThen rotate about z by θThen reverse the rotation about y (by β )Then reverse the rotation about z (by )

102

3D Rotation about Arbitrary Axes

Rotate p about the by the angle

x

y

zr

),,( zyxp

r

103

3D Rotation about Arbitrary Axes

Translate so that rotation axis passes through the origin

x

y

zr

TRRRRRT zyzyz )()()()()(1

104

3D Rotation about Arbitrary Axes

Rotation by about z-axis

x

y

z

r

TRRRRRT zyzyy )()()()()(1

105

3D Rotation about Arbitrary Axes

Rotation by about y-axis

x

y

z

r

xTRRRRRT zyzyy )()()()()(1

106

3D Rotation about Arbitrary Axes

Rotation by about z-axis

x

y

z

r

xTRRRRRT zyzyy )()()()()(1

107

3D Rotation about Arbitrary Axes

Rotation by about y-axis

x

y

z

r

xTRRRRRT zyzyy )()()()()(1

108

3D Rotation about Arbitrary Axes

Rotation by about z-axis

x

y

z

r

TRRRRRT zyzyz )()()()()(1

109

3D Rotation about Arbitrary Axes

Translate the object back to original point

x

y

z

r

TRRRRRT zyzyz )()()()()(1

110

3D Rotation about Arbitrary Axes

Final transformation matrix for rotating about an arbitrary axis

x

y

z

r

TRRRRRT zyzyz )()()()()(1

111

3D Rotation about Arbitrary Axes

Final transformation matrix for rotating about an arbitrary axis

x

y

z

r

TRRRRRT zyzyz )()()()()(1

112

3D Rotation about Arbitrary Axes

Final transformation matrix for rotating about an arbitrary axis

TRRRRRT zyzyz )()()()()(1

1000

0

0

0

333231

232221

131211

rrr

rrr

rrr

3D Rotation about Arbitrary Axes

Final transformation matrix for rotating about an arbitrary axis

TRRRRRT zyzyz )()()()()(1

A 3 by 3 Rotation matrix—orthogonal matrix

1000

0

0

0

333231

232221

131211

rrr

rrr

rrr

Rotation Matrices

Orthonormal matrix: orthogonal (columns/rows linearly

independent)normalized (columns/rows length of 1)

115

Rotation Matrices

Orthonormal matrix: orthogonal (columns/rows linearly

independent)normalized (columns/rows length of 1)

The inverse of an orthogonal matrix is just its transpose:

116

T

rrr

rrr

rrr

rrr

rrr

rrr

333231

232221

131211

1

333231

232221

131211

Rotation Matrices

Orthonormal matrix: orthogonal (columns/rows linearly

independent)normalized (columns/rows length of 1)

The inverse of an orthogonal matrix is just its transpose:

117

T

rrr

rrr

rrr

rrr

rrr

rrr

333231

232221

131211

1

333231

232221

131211

Rotation Matrices

Orthonormal matrix: orthogonal (columns/rows linearly

independent)normalized (columns/rows length of 1)

The inverse of an orthogonal matrix is just its transpose: e.g.,

T

xx

Tyy

Tzz

RR

RR

RR

)()(

)()(

)()(

1

1

1

123

3D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

),,( 000 zyx

k

'k

124

2D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

110010

0

y

x

yjjij

xjiii

y

xTT

TT

),( 00 yx

poooop

125

3D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

1

'

'

'

1000

'

'

'

10

0

0

z

y

x

zkkjkik

ykjjjij

xkijiii

z

y

x

TTT

TTT

TTT

),,( 000 zyx

k

'k

poooop

126

3D Coordinate Transformation

Transform object description from to

pj

i

i

j

o

o

ji ij

1

'

'

'

1000

'

'

'

10

0

0

z

y

x

zkkjkik

ykjjjij

xkijiii

z

y

x

TTT

TTT

TTT

),,( 000 zyx

k

'k

poooop

127

3D Coordinate Transformation

Transform object description from to

i

i

j

o

ji ij

1

'

'

'

1000

'

'

'

10

0

0

z

y

x

zkkjkik

ykjjjij

xkijiii

z

y

x

TTT

TTT

TTT

k

128

p'i

'j

3D Coordinate Transformation

Transform object description from toji ij

129

'i

11000

0cos0sin

0010

0sin0cos

1

z

y

x

z

y

x

x

y

z

Composite 3D Transformation

Similarly, we can easily extend composite transformation from 2D to 3D

1

2

3

),,( 0yx

3c

2c

1c

0c

A

130

Composite 3D Transformation

xRRhTRhTRRRhTRRRzyxTp )()()0,,0()()0,,0()()()()0,,0()()()(),,( 332211110000000

131