3d geometric transformations -...

14
Sun-Jeong Kim 3D Geometric Transformations 10 th Week, 2008 Computer Graphics 2 Transformation in 3D Transformation matrix × × × × 1 1 3 1 1 3 3 3 0 0 0 S L I F C K H E B J G D A 3×3 : Scaling, Reflection, Shearing, Rotation 3×3 : Scaling, Reflection, Shearing, Rotation 3×1 : Translation 3×1 : Translation 1×3 : Homogeneous representation 1×3 : Homogeneous representation 1×1 : Uniform global Scaling 1×1 : Uniform global Scaling

Upload: dangcong

Post on 23-Mar-2018

222 views

Category:

Documents


6 download

TRANSCRIPT

Page 1: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Sun-Jeong Kim

3D Geometric Transformations

10th Week, 2008

Computer Graphics2

Transformation in 3D

Transformation matrix

⎥⎥⎥⎥

⎢⎢⎢⎢

××

××⇒

⎥⎥⎥⎥

⎢⎢⎢⎢

1131

1333

000 S

LIFC

KHEB

JGDA

3×3 : Scaling, Reflection, Shearing, Rotation3×3 : Scaling, Reflection, Shearing, Rotation

3×1 : Translation3×1 : Translation

1×3 : Homogeneous representation1×3 : Homogeneous representation

1×1 : Uniform global Scaling1×1 : Uniform global Scaling

Page 2: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics3

3D Translation

Translation of a point

zyx tzztyytxx +=+=+= ',','

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

11000

100

010

001

1

'

'

'

z

y

x

t

t

t

z

y

x

z

y

x

xz

y

Computer Graphics4

3D Scaling

Scaling relative to the origin

zyx szzsyysxx ⋅=⋅=⋅= ',','

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

11000

000

000

000

1

'

'

'

z

y

x

s

s

s

z

y

x

z

y

x

xz

y

Page 3: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics5

Relative Scaling

Scaling with a selected fixed position

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

=−−−⋅⋅

11000

100

010

001

1000

000

000

000

1000

100

010

001

1

'

'

'

),,(),,(),,(z

y

x

z

y

x

s

s

s

z

y

x

z

y

x

zyxTsssSzyxTf

f

f

z

y

x

f

f

f

fffzyxfff

x x x xzzzz

y y y y

Original position Translate Scaling Inverse Translate

Computer Graphics6

3D Rotation

Coordinate-axes rotationsx-axis rotation

y-axis rotation

z-axis rotation

General 3D rotationsRotation about an axis that is parallel to one of the coordinate axes

Rotation about an arbitrary axis

Page 4: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics7

Coordinate-Axes Rotations

z-axis rotation x-axis rotation y-axis rotation

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

=

⎥⎥⎥⎥

⎢⎢⎢⎢

11000

0100

00cossin

00sincos

1

'

'

'

z

y

x

z

y

x

θθθθ

z

y

x

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

=

⎥⎥⎥⎥

⎢⎢⎢⎢

11000

0cossin0

0sincos0

0001

1

'

'

'

z

y

x

z

y

x

θθθθ

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−=

⎥⎥⎥⎥

⎢⎢⎢⎢

11000

0cos0sin

0010

0sin0cos

1

'

'

'

z

y

x

z

y

x

θθ

θθ

z

y

xz

y

x

Computer Graphics8

Order of Rotations

Order of rotation affects final positionx-axis z-axis

z-axis x-axis

Page 5: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics9

General 3D Rotations (1)

Rotation about an axis that is parallel to one of the coordinate axes

Translate : the rotation axis coincides with the parallel coordinate axis

Rotation about that axis

Translate : the rotation axis is moved back to its original position

Computer Graphics10

General 3D Rotations (2)

Rotation about an arbitrary axis

Basic Idea

1. Translate (x1, y1, z1) to the origin

2. Rotate (x’2, y’2, z’2) on to the z axis

3. Rotate the object around the z-axis

4. Rotate the axis to the original

orientation

5. Translate the rotation axis to the

original position

Basic Idea

1. Translate (x1, y1, z1) to the origin

2. Rotate (x’2, y’2, z’2) on to the z axis

3. Rotate the object around the z-axis

4. Rotate the axis to the original

orientation

5. Translate the rotation axis to the

original position

(x2,y2,z2)

(x1,y1,z1)

x

z

y

R-1R-1

T-1T-1

RR

TT

( ) ( ) ( ) ( ) ( ) ( )TRRRRRTR αβθβαθ xyzyx111 −−−=

RR

Page 6: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics11

Arbitrary Axis Rotation (1)

Step 1. Translation

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−

=

1000

100

010

001

1

1

1

z

y

x

T

(x2,y2,z2)

(x1,y1,z1)

x

z

y

Computer Graphics12

Arbitrary Axis Rotation (2)

Step 2. Rotate about x axis by α

( )⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−

=

1000

0//0

0//0

0001

1000

0cossin0

0sincos0

0001

dcdb

dbdcx αα

αααR

(a,b,c)(0,b,c)

Projected Point α α

Rotated Point

d

c

cb

c

d

b

cb

b

=+

=+

22

22

cos

sin

x

y

z

Page 7: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics13

Arbitrary Axis Rotation (3)

Step 3. Rotate about y axis by β

(a,b,c)

(a,0,d)β

l

d

22

222222

cos,sin

cbd

dacbal

l

d

l

a

+=

+=++=

== ββ

( )⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

=

1000

0/0/

0010

0/0/

1000

0cos0sin

0010

0sin0cos

ldla

lald

y ββ

ββ

βRx

y

Projected Point

zRotated

Point

Computer Graphics14

Arbitrary Axis Rotation (4)

Step 4. Rotate about z axis by the desired angle θ

θ

l

( )⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

=

1000

0100

00cossin

00sincos

θθθθ

θzR

y

x

z

Page 8: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics15

Arbitrary Axis Rotation (5)

Step 5. Apply the reverse transformation to place the axis back in its initial position

x

y

l

l

z

( ) ( )

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−⎥⎥⎥⎥

⎢⎢⎢⎢

−−−

=−−−

1000

0cos0sin

0010

0sin0cos

1000

0cossin0

0sincos0

0001

1000

100

010

001

1

1

1

111

ββ

ββ

αααα

βαz

y

x

yx RRT

( ) ( ) ( ) ( ) ( ) ( )TRRRRRTR αβθβαθ xyzyx111 −−−=

Computer Graphics16

Example (1)

Find the new coordinates of a unit cube 90º-rotated about an axis defined by its endpoints A(2,1,0) and B(3,3,1)

A Unit Cube

Page 9: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics17

Example (2)

Step1. Translate point A to the origin

A’(0,0,0)x

z

y

B’(1,2,1)

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−−

=

1000

0100

1010

2001

T

Computer Graphics18

x

z

y

l

( )

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

−=

1000

05

5

5

520

05

52

5

50

0001

αxR

6121

5

5

5

1cos

5

52

5

2

12

2sin

222

22

=++=

==α

==+

lB’(1,2,1)

α

Projected point (0,2,1)

B”(1,0,√5)

Example (3)

Step 2. Rotate axis A’B’ about the x axis by and angle α, until it lies on the xz plane.

Page 10: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics19

x

z

y

l

( )

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

⎡−

=

1000

06

300

6

60010

06

60

6

30

βyR

6

30

6

5cos

6

6

6

1sin

==

==

β

β

β

B”(1,0, √ 5)(0,0,√6)

Example (4)

Step 3. Rotate axis A’B’’ about the y axis by and angle φ, until it coincides with the z axis.

Computer Graphics20

Example (5)

Step 4. Rotate the cube 90° about the z axis

Finally, the concatenated rotation matrix about the arbitrary axis AB becomes,

( ) ( ) ( ) ( ) ( ) ( )TRRRRRTR αββαθ xyzyx °= −−− 90111

( )⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

1000

0100

0001

0010

90zR

Page 11: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics21

( )

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡−−

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

⎡−

⎥⎥⎥⎥

⎢⎢⎢⎢

⎡ −

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

−⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

−⎥⎥⎥⎥

⎢⎢⎢⎢

=

1000

560.0167.0741.0650.0

151.1075.0667.0742.0

742.1983.0075.0166.0

1000

0100

1010

2001

1000

05

5

5

520

05

52

5

50

0001

1000

06

300

6

60010

06

60

6

30

1000

0100

0001

0010

1000

06

300

6

60010

06

60

6

30

1000

05

5

5

520

05

52

5

50

0001

1000

0100

1010

2001

θR

Example (6)

Computer Graphics22

Example (7)

Multiplying R(θ) by the point matrix of the original cube

[ ]

⎥⎥⎥⎥

⎢⎢⎢⎢

−−−−−−−

=

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−−

=′

11111111

076.0091.0560.0726.0817.0650.0301.1467.1

483.0409.0151.1225.1184.0258.0484.0558.0

891.2909.1742.1725.2816.2834.1667.1650.2

11111111

10011001

00001111

11001100

1000

560.0167.0741.0650.0

151.1075.0667.0742.0

742.1983.0075.0166.0

P

[ ] ( )[ ]PRP θ=′

Page 12: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics23

Rotations with Quaternions (1)

QuaternionScalar part s + vector part v = (a, b, c)

Real part + complex part (imaginary numbers i, j, k)

Rotation about any axisSet up a unit quaternion (u: unit vector)

Represent any point position P in quaternion notation (p = (x, y, z))

2sin ,

2cos

θθuv ==s

( )pP ,0=

( ) ckbjaissq +++== v ,

Computer Graphics24

Rotations with Quaternions (2)

Carry out with the quaternion operation (q-1=(s, –v))

Produce the new quaternion

Obtain the rotation matrix by quaternion multiplication

Include the translations:

1−=′ qqPP

( )pP ′=′ ,0

( ) ( ) ( )pvvpvvpvpp ××+×+⋅+=′ ss 22

( ) ( ) ( ) ( ) ( ) ( )

⎥⎥⎥

⎢⎢⎢

−−+−−−−++−−−

=

= −−

22

22

22

11

2212222

2222122

2222221

basabcsbac

sabccascab

sbacscabcb

xyzyxR αβθβαθ RRRRRM

( ) ( )TMTR θθ R1−=

Page 13: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics25

Example

Rotation about z axisSet the unit quaternion:

Substitute a=b=0, c=sin(θ/2) into the matrix:

( )2

sin1 ,0 ,0 ,2

cosθθ

== vs

( )

⎥⎥⎥

⎢⎢⎢

⎡ −=

⎥⎥⎥⎥⎥⎥

⎢⎢⎢⎢⎢⎢

−−

=

100

0cossin

0sincos

100

02

sin212

sin2

cos2

02

sin2

cos22

sin21

2

2

θθθθ

θθθ

θθθ

θRM

θθθ

θθ

sin2

sin2

cos2

cos2

sin21 2

=

=−

Computer Graphics26

Other Transformations

Reflection relative to the xy plane

z-axis shearxz

y

x

z

y

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

−=

⎥⎥⎥⎥

⎢⎢⎢⎢

′′′

11000

0100

0010

0001

1

z

y

x

z

y

x

⎥⎥⎥⎥

⎢⎢⎢⎢

⎥⎥⎥⎥

⎢⎢⎢⎢

=

⎥⎥⎥⎥

⎢⎢⎢⎢

11000

0100

010

001

1

'

'

'

z

y

x

b

a

z

y

x

Page 14: 3D Geometric Transformations - hallym.ac.krgraphics.hallym.ac.kr/teach/2008/cg/src/12transform3d.pdf3D Geometric Transformations ... Find the new coordinates of a unit cube 90º-rotated

Computer Graphics27

Coordinate Transformations

Transformation of an object description from one coordinate system to another

Transformation matrixBring the two coordinates systems into alignment

[1] Translation

x

y

z (0,0,0)

y’

z’

x’u'y

u'z

u'x(x0,y0,z0)x

y

z (0,0,0)

u'y

u'z

u'x

( )000 , , zyx −−−T

Computer Graphics28

Coordinate Transformations

[2] Rotation & Scaling

x

y

z (0,0,0)

y’

z’

x’u'y

u'z

u'x x

y

z (0,0,0)

u'y

u'z

u'x x

y

z (0,0,0)

u'y

u'z

u'x

⎥⎥⎥⎥

⎢⎢⎢⎢

′′′′′′′′′

=

1000

0

0

0

321

321

321

zzz

yyy

xxx

uuu

uuu

uuu

R