32
Graphics Graphics Lab @ Korea University 3D Geometric Transformation 고고고고고 고고고 고고고고 고고고

transformation 3d

Embed Size (px)

DESCRIPTION

Computer Graphics topic:: Transformation in 3d

Citation preview

Page 1: transformation 3d

Graphics

Graphics Lab @ Korea University

3D Geometric Transformation

고려대학교 컴퓨터 그래픽스 연구실

Page 2: transformation 3d

CGVR

Graphics Lab @ Korea University

Contents

Translation

Scaling

Rotation

Rotations with Quaternions

Other Transformations

Coordinate Transformations

Page 3: transformation 3d

CGVR

Graphics Lab @ Korea University

Transformation in 3D

Transformation Matrix

1131

1333

000 S

LIFC

KHEB

JGDA

33 : Scaling, Reflection, Shearing, Rotation33 : Scaling, Reflection, Shearing, Rotation

31 : Translation31 : Translation

13 : Homogeneous representation13 : Homogeneous representation

11 : Uniform global Scaling11 : Uniform global Scaling

Page 4: transformation 3d

CGVR

Graphics Lab @ Korea University

3D Translation

Translation of a Point

zyx tzztyytxx ',',' zyx tzztyytxx ',','

11000

100

010

001

1

'

'

'

z

y

x

t

t

t

z

y

x

z

y

x

xz

y

Page 5: transformation 3d

CGVR

Graphics Lab @ Korea University

3D Scaling

Uniform Scaling

zyx szzsyysxx ',',' zyx szzsyysxx ',','

11000

000

000

000

1

'

'

'

z

y

x

s

s

s

z

y

x

z

y

x

xz

y

Page 6: transformation 3d

CGVR

Graphics Lab @ Korea University

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

Page 7: transformation 3d

CGVR

Graphics Lab @ Korea University

3D Rotation

Coordinate-Axes Rotations X-axis rotation Y-axis rotation Z-axis rotation

General 3D Rotations Rotation about an axis that is parallel to one of the

coordinate axes Rotation about an arbitrary axis

Page 8: transformation 3d

CGVR

Graphics Lab @ Korea University

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

Page 9: transformation 3d

CGVR

Graphics Lab @ Korea University

Order of Rotations

Order of Rotation Affects Final Position X-axis Z-axis

Z-axis X-axis

Page 10: transformation 3d

CGVR

Graphics Lab @ Korea University

General 3D Rotations

Rotation about an Axis that is Parallel to One of the Coordinate Axes Translate the object so that the rotation axis

coincides with the parallel coordinate axis Perform the specified rotation about that axis Translate the object so that the rotation axis is

moved back to its original position

Page 11: transformation 3d

CGVR

Graphics Lab @ Korea University

General 3D Rotations

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

Page 12: transformation 3d

CGVR

Graphics Lab @ Korea University

General 3D Rotations

Step 1. Translation

1000

100

010

001

1

1

1

z

y

x

T

(x2,y2,z2)

(x1,y1,z1)

x

z

y

Page 13: transformation 3d

CGVR

Graphics Lab @ Korea University

General 3D Rotations

Step 2. Establish [ TR ]x x axis

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 14: transformation 3d

CGVR

Graphics Lab @ Korea University

Arbitrary Axis Rotation

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

Page 15: transformation 3d

CGVR

Graphics Lab @ Korea University

Arbitrary Axis Rotation

Step 4. Rotate about z axis by the desired angle

l

1000

0100

00cossin

00sincos

zR

y

x

z

Page 16: transformation 3d

CGVR

Graphics Lab @ Korea University

Arbitrary Axis Rotation

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

Page 17: transformation 3d

CGVR

Graphics Lab @ Korea University

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).

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

Example

Page 18: transformation 3d

CGVR

Graphics Lab @ Korea University

Example

Step1. Translate point A to the origin

A’(0,0,0)x

z

y

B’(1,2,1)

1000

0100

1010

2001

T

Page 19: transformation 3d

CGVR

Graphics Lab @ Korea University

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

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

Page 20: transformation 3d

CGVR

Graphics Lab @ Korea University

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

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

Page 21: transformation 3d

CGVR

Graphics Lab @ Korea University

Example

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 22: transformation 3d

CGVR

Graphics Lab @ Korea University

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

Page 23: transformation 3d

CGVR

Graphics Lab @ Korea University

PRP

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

Example

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

Page 24: transformation 3d

CGVR

Graphics Lab @ Korea University

Rotations with Quaternions

Quaternion Scalar part s + vector part v = (a, b, c) Real part + complex part (imaginary numbers i, j, k)

Rotation about any axis Set 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 ,

Page 25: transformation 3d

CGVR

Graphics Lab @ Korea University

Rotations with Quaternions

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 26: transformation 3d

CGVR

Graphics Lab @ Korea University

Example

Rotation about z axis Set 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

Page 27: transformation 3d

CGVR

Graphics Lab @ Korea University

Other Transformations

Reflection Relative to the xy Plane

Z-axis Shear

xz

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 28: transformation 3d

CGVR

Graphics Lab @ Korea University

Coordinate Transformations

Multiple Coordinate System Local (modeling) coordinate system World coordinate scene

Local Coordinate System

Page 29: transformation 3d

CGVR

Graphics Lab @ Korea University

Coordinate Transformations

Multiple Coordinate System Local (modeling) coordinate system World coordinate scene

Word Coordinate System

Page 30: transformation 3d

CGVR

Graphics Lab @ Korea University

Coordinate Transformations

Example – Simulation of Tractor movement As tractor moves, tractor coordinate system and

front-wheel coordinate system move in world coordinate system

Front wheels rotate in wheel coordinate system

Page 31: transformation 3d

CGVR

Graphics Lab @ Korea University

Coordinate Transformations

Transformation of an Object Description from One Coordinate System to Another

Transformation Matrix Bring 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

Page 32: transformation 3d

CGVR

Graphics Lab @ Korea University

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