• 검색 결과가 없습니다.

3D Transformation 3D Transformation

N/A
N/A
Protected

Academic year: 2022

Share "3D Transformation 3D Transformation"

Copied!
39
0
0

로드 중.... (전체 텍스트 보기)

전체 글

(1)

3D Geometric

T f i

Transformations

Chapter 5 Chapter 5

Intro. to Computer Graphics Spring 2008, Y. G. Shin

(2)

3D Transformation 3D Transformation

Right-handed coordinate system

⎥ ⎤

⎢ ⎡

⎥ ⎤

⎢ ⎡

⎥ ⎤

⎢ ⎡ ' x x

1

x

2

x

3

t

x

x

y

⎥ ⎥

⎢ ⎢

⎥ ⎥

⎢ ⎢

= ⎢

⎥ ⎥

⎢ ⎢

⎢ '

'

3 2

1

3 2

1

z y t

z z

z

t y

y y

z

y

y

⎥ ⎥

⎢ ⎦

⎥ ⎣

⎢ ⎦

⎥ ⎣

⎢ ⎦

⎣ 0 0 0 1 1

3 2

1

z z t z

z h

z

z

z

x

z

(3)

3D Transformation 3D Transformation

⎡ 1 0 0

ƒ Translation

ƒ Scaling

⎥ ⎥

⎢ ⎢

0 1

0

0 0

1

x

t t

⎥ ⎥

⎢ ⎢

0 0

0

0 0

x

0

s s

⎥ ⎥

⎢ ⎢

1 0

0

0 1

0

z y

t t

⎥ ⎥

⎢ ⎢

0 0

0

0 0

0

z y

s s

⎥ ⎦

⎢ ⎣ 0 0 0 1

z

⎢ ⎦

⎣ 0 0 0 1

z

(4)

3D Rotation 3D Rotation

0 0 cos

sin

0 0 sin

cos

θ θ

θ θ

⎥⎤

⎢⎡

0 i

0

0 0

0 1

θ θ

=

1 0 0

0

0 1 0

0

0 0 cos

) sin

( θ θ

z θ R

⎥⎥

⎥⎥

⎢⎢

⎢⎢ −

= 0 sin cos 0

0 sin

cos ) 0

( θ θ

θ θ θ

Rx

0 0 0 1

⎢ ⎦

⎣0 0 0 1

3D rotations do NOT commute!

3D rotations do NOT commute!

(5)

Rotation About Arbitrary Axis

Rotation About Arbitrary Axis

(6)

Rotation about an arbitrary axis Rotation about an arbitrary axis

1 Translation : rotation axis passes 1 0 0 x 1. Translation : rotation axis passes

through the origin

=

1 0 0 0

1 0 0

0 1 0

0 0 1

1 1 1

z y x T

2. Make the rotation axis on the z-axis

) ( )

(α R β

R

0 0 0 1

) ( )

(α y β

x R

R

3. Do rotation

) (θ

Rz(θ) (x1,y1,z1) R

4. Rotation & translation

) ( )

( 1

1 1 β α

R R

T Ry (β)Rx (α) T

Rotation about an arbitrary axis

T R

R R

R R

T

R(θ) = 1x1(α)⋅ y1(β)⋅ z(θ)⋅ y(β)⋅ x(α)⋅

(7)

Rotation About Arbitrary Axis Rotation About Arbitrary Axis

R t t t th i

„ Rotate u onto the z-axis

(8)

Rotation About Arbitrary Axis Rotation About Arbitrary Axis

„ Rotate a unit vector u onto the z axis

„ Rotate a unit vector u onto the z-axis

„ u’ : Project u onto the yz-plane to compute angle α

„ u’’ : Rotate u about the x-axis by angleu : Rotate u about the x axis by angle αα

„ Rotate u’’ onto the z-asis

(9)

Rotation About Arbitrary Axis Rotation About Arbitrary Axis

„ Rotate u’ about the x-axis onto the z-axis

„ Let u=(a,b,c) and thus u’=(0,b,c)

„ Let uz=(0,0,1)

⋅′u c u

y u’ u

2

cos 2

c b

c

z z

= +

= ′

u u

u α u

α x

z sin

x

z u u u

u

u′× = ′ α z uz = (0,0,1)

xb

= u

sin α = b = b

2

sin

2

c b

z

= +

= ′

u

α u

(10)

Rotation About Arbitrary Axis Rotation About Arbitrary Axis

R t t ’ b t th i t th i

„ Rotate u’ about the x-axis onto the z-axis

„ Since we know both cos α and sin α, the rotation matrix can be obtained

can be obtained

0 0

0 0

0

1 c b

y u’

+

= +

0 0

0 0

) (

2 2

2 2

2 2

2 2

b c b

b c b c

b

x α

R

α x u u

β

+ +

1 0

0 0

2 2

2

2 c b c

b x

z α

u’’

„ Rotate u’’ onto the z-asis

„ With the similar way, we can compute the angle β

u

(11)

Rotation about an arbitrary axis

i th l t i

using orthogonal matrix

„ Unit row vector of R rotates into the principle axes x, y, and z.

r

1x

r

2x

r

3x

y

P3 y

⎥ ⎥

⎢ ⎢

=

y y y

x x

x

r r

r

R

1 2 3

3 2

1

P1

P2 3

P3

⎥⎦

⎢⎣ r

1z

r

2z

r

3z

x z

x z P2 1

P

z z

Initial position Final position

(12)

Rotation about an arbitrary axis

i th l t i

is the unit vector along P P that

R

using orthogonal matrix

is the unit vector along P1P2 that will rotate into the positive z axis

P P R

z

[ ]

2 1

2 1 3

2

1

P P

P r P

r r

R

z

=

z z z

=

Rx

y

P3

Ry

is perpendicular to the plane P P and P that will rotate into

R

x

Rz

P3 P1

P2 3

P1, P2 and P3 that will rotate into the positive x axis

P P P

P

x z 2

P P1

[ ]

2 1 3

1

2 1 3

1 3

2

1

P P P P

P P P

r P r

r

R

x x x x

×

= ×

z

=

(13)

Rotation about an arbitrary axis

i th l t i

using orthogonal matrix

Finally

y R Finally,

[

y y y

]

z x

y

r r r R R

R =

1 2 3

= ×

Rx

P R

P3

Ry

Rz

P x P3 P1

P2

P1

⎥ ⎤

⎢ ⎡ R

x

z 2 P

⎥ ⎥

⎢ ⎢

= ⎢

=

x y y

R R R

R

R ( β ) ( α )

⎥⎦

⎢⎣ R

z

(14)

Reflection Reflection

„

Reflection about xy plane

⎥ ⎤

⎢ ⎡ 1 0 0 0

y

⎥ ⎥

⎢ ⎢

= ⎢

0 1

0 0

0 0

1 0

RF

z x

⎥ ⎥

⎢ ⎦

1 0

0 0

0 1

0 0

z z

(15)

fl b b l

Reflection about an arbitrary plane

1. Translate a known point P, that lies in the reflection plane, to the origin of the coordinate system

of the coordinate system

2. Rotate the normal vector to the reflection plane at the origin until reflection plane at the origin until the plane lies on z=0 plane.

3. After also applying the above

P

3. After also applying the above

transformations to the object, reflect the object through z=0 coordinate plane.

4. Perform the inverse transformations.

(16)

Shear Shear

„

Shear in x-direction

⎡ + +

⎡1 a b 0 x x ay bz

⎥⎥

⎥⎤

⎢⎢

⎢⎡ + +

⎥ =

⎥⎥

⎢⎢

⎢⎡

⎥⎥

⎥⎤

⎢⎢

⎢⎡

= 0 0 1 0

0 0

1 0

0 1

z y

bz ay

x

z y x b

a SHx

⎥⎥

⎢ ⎦

⎥ ⎣

⎢ ⎦

⎥⎣

⎢ ⎦

⎣0 0 0 1 1 1

0 1

0

0 z z

0

When b 0 =

When b =

(17)

Shearing along xy plane Shearing along xy-plane

Direction vector

y

⎥⎥

⎢⎢

⎡1 0 0

c a

(a, b, c)

⎥⎥

⎢⎢

= ⎢0 1 0

c bc SHxy

⎥ z

⎥⎥

⎢ ⎦

⎢⎢

⎣0 0 0 1 0 1

0 0

a b

(0, 0, 1) is moved to

⎜ ⎞

⎛ , , 1

c b c

a

(18)

How we represent Rotations?

How we represent Rotations?

ƒ Rotation (direction cosine) matrix

ƒ Euler angles u e a g es

ƒ Angular Displacement

ƒ Unit quaternions

ƒ Unit quaternions

(19)

Euler Angles (Euler’s Theorem) Euler Angles (Euler’s Theorem)

Arbitrary rotation can be represented by three rotation along x,y,z axis.

=

0 C

S S

S C C

C

) ( ) ( )

( )

, , (

β β

β

γ β

α α

β γ

S S C

S C R

R R

RXYZ z y x

⎥⎥

⎥⎤

⎢⎢

⎢⎡

− +

+

= 0

0 C

S - S S C C

C

β β

β

γ α γ

β α γ

α γ

β α β

α

γ α γ

β α γ

α γ

β α β

α

S C C

S S C

C S

S S C

S

S S C

S C

⎥⎥

⎢ ⎦

1 0

0 0

γ 0 β γ

β

β C S C C

S

↔ rotation matrix

) , , ( :

angle

Euler angle : R

XYZ

( γ , β , α )

rotation matrix

Euler R

XYZ

γ β α

Not easy

(20)

Gimble

Gimble

(21)

Gimble Lock Gimble Lock

„

Rotation about three orthogonal axes

12 bi ti

„ 12 combinations

„ XYZ, XYX, XZY, XZX

„ YZX, YZY, YXZ, YXY

„ YZX, YZY, YXZ, YXY

„ ZXY, ZXZ, ZYX, ZYZ

„

Gimble lock

„ Coincidence of inner

t d t t

most and outmost gimbles’ rotation axes

„ Loss of degree of

„ Loss of degree of freedom

(22)

Gimble Lock Gimble Lock

bl l k b f

„ Gimble lock gives ambiguous representation of a rotation angle.

„ Two different Euler angles can represent the same

„ Two different Euler angles can represent the same orientation

π π

) 0 2 ,

1

,

π

) ,r ,r (r

R =

x y z

= , )

, 2

2

= ( 0 π θ R

and

„ This ambiguity brings unexpected results of animation where frames are generated by interpolation

interpolation.

(23)

Gimble Lock Gimble Lock

Y축 Z축

Y축 Z축

X축 Y축

Z축

X축

Y축 Z축

Y축 Z축

X축 X축 X축 X축X축 X축

) 0 0 0 ) (

0 0 0

R((0,0,0) R(50,0,0) R(50 π 0) R(π π 0)

R ,0)

, 2 50

( π

R R(50,π,0) R(π,π,0)

Y축 Z축

Y축 Z축

Y축 Z축

Y축 Z축

Y축 Z축

X축 X축 X축 X축 X축

) 0 , 0 , 0

R( ,0)

, 2 0 ( π

R , 50)

, 2 0

( π

R , )

, 2 0

( π π

R R(π,π,0)

(24)

Gimble Lock Gimble Lock

π

⎡ 0 0 − 01

y.

arbitraril and

set and

2 ,

Set θ

y

= π θ

x

θ

z

⎥⎥

⎥⎤

⎢⎢

⎢⎡

− +

+

= −

= 0 0

0 0

0 1 0

0

z x z

x z

x z

x z

y

x c c s s c s s c

c c s

s s

c c

) s , , (

R θ θ θ

⎥⎥

⎢ ⎦

+

1 0

0 0

0

z 0

x z

x z

x z

xc s s c s s c

c

⎡ 0 0 1 0

⎥⎥

⎥⎤

⎢⎢

⎢⎡

= cos( ) sin( ) 0 0

0 0

) cos(

) sin(

0 1 0

0

z x

z x

θ θ

θ θ

θ θ

θ θ

f l d d h d ff

⎥⎥

⎢ ⎦

1 0

0 0

0 0

) sin(

)

cos(θx θz θx θz Transformation only depends on the difference

We lost one DOF.

(25)

Angular Displacement Angular Displacement

Arbitrary rotation can be represented by one rotation

„ Arbitrary rotation can be represented by one rotation (by a scalar angle) around an axis(unit vector)

„ No Gimble lock but NOT smooth interpolation for

„ No Gimble lock but NOT smooth interpolation for animation

„ Supported by OpenGL

θ angle an

by

r unit vecto a

about

Rotating v r u r

θ vr

ur v r = ( u r ⋅ v r ) u r + cos θ ( v r − ( u r ⋅ v r ) u r )

θ u

) (

sin

) ) (

( cos )

(

v u

u v u v

u v u v

rot

r× r +

− +

=

θ

θ

)

(

(26)

Angular Displacement Angular Displacement

) (

sin )

) (

( cos )

( u v u v u v u u v

v r

rot

= r ⋅ r r + θ r − r ⋅ r r + θ r × r sin

cos v v

v r

1

+ cos θ v r

2

+ sin θ v r

3

v + θ + θ

=

vr

2

v

θ

vr

3

θ

3

(27)

Quaternions Quaternions

M lti li ti f t l b Ù

„

Multiplication of two complex numbers Ù Rotation in 2D space

imaginary

2 2

1 1

2

1

p = ( a + b i )( a + b i )

1

p

θ real

2

1 θ

θ +

) ( 1 2

2

1 θ θ θ

θ

=

+

= e

i

e

i

e

i

θ θ

θ i ei bi

a+ = cos + sin =

„

Quaternions are 4D analogs of complex number

„

Multiplication of two quaternions Ù

„

Multiplication of two quaternions Ù

Rotation in 3D space

(28)

Quaternions Quaternions

„ Quaternions are defined using one real part and three imaginary quantities, i, j and k

k v j

v i

v s

v s

q = r ( , ) = +

1

+

2

+

3

j ik

ki i

kj jk

k ji

ij

k j

i

=

=

=

=

=

=

=

=

=

2 2

1 ,

2

j ik

ki i

kj jk

k ji

ij = − = , = − = , = − =

2 2

2

v

2

v v

s

q = s + v

1

+ v

2

+ v

3

q = + + +

(29)

Quaternions

θ

Pr

Quaternions

ur

A t ti f t i t

P ( x y z )

b t th

„ A rotation of a vector point about the unit vector by an angle can be computed using the quaternion

u θ P = ( x , y , z )

the quaternion

2 ) sin 2 ,

(cos )

, (

), ,

0

( = =

= p q s v u

P θ θ

2 2

1

= q q

rotated

P

P where q

1

= ( s , − v )

) ,

(

and

2 1

1 2 2

1 2 1

2 1 2

1

2 2 2

1 1 1

v v

v s v

s v

v s

s q

q

) v , (s q

) v , (s

q r r r r r r

r r

× +

+

=

=

=

When

) ,

(

1 2 1 2 1 2 2 1 1 2

2

1

q s s v v s v s v v v

q + + ×

) ,

0

rotated

( p

rotated

P =

) (

) (

2 )

2

(

p v

v p

v v

p v p

p

rotated

= s + ⋅ + s × + × ×

(30)

Quaternions Quaternions

θ

Quaternions for Rotation: θ )

sin 2 2 ,

(cos )

, (

), , 0

( θ θ

u v

p

P = q = s =

) (

) (

2 )

2

(

) (

) (

2 )

2

(

p v

v p

v v

p v p

p

rotated

= s + ⋅ + s × + × ×

(

0 0 1

)

sin

cosθ θ

=

= v

s

[Example] Rotation about z-axis

( )

sin 2 1 , 0 , 0

2 ,

cos =

= v

s

pprotated

o p

z ur

(31)

Q t i R t ti i M t i F

Quaternion Rotation in a Matrix Form

Assuming that a unit quaternion has been created in the form:

Then the quaternion can then be converted into

( s , a , b , c )

Then the quaternion can then be converted into

a 4x4 rotation matrix using the following expression

⎥⎥

⎢⎢

− +

+

= 2 2

2 2

2 2

2 2

1 2

2

2 2

2 2

2 2

1 )

( ab sc a c bc sa

sb ac

sc ab

c b

MR θ

⎥⎥

⎢ ⎦

⎣ 2ac − 2sb 2bc + 2sa 1− 2a2 − 2b2

I i f h i i i

It is often necessary to have a quaternion rotation in a matrix form, e.g., to load onto graphics hardware for hardware vertex transformations

hardware vertex transformations.

(32)

Quaternions Quaternions

„ Useful for animations

ƒ Independent definition of an axis of rotation and an angle

ƒ Smooth interpolation

ƒ No Gimble lock

Far more complicated to read and conceptualize than

„ Far more complicated to read and conceptualize than Eular angle

„ Interpolation can be expensive in practice

„ Interpolation can be expensive in practice

(33)

Modeling Transformation

Modeling Transformation

(34)

Modeling Transformation Modeling Transformation

?

?

(35)

Modeling Transformation Modeling Transformation

Modeling Transformation

y '

y y

y

A

r p B

x ' x

y ( , ) ( , )

'

'

Scale x y T x y M

x y xv

= ⋅

y

p A B

r

xx

(36)

Modeling Transformation Modeling Transformation

y y

Translate by -r, bringing t th i i

p A B

x

pAB r

r to the origin.

pA

x

p A B

r

x

y y

)

Rotate ( A translate ( A )

p B

x x

p B

x x

(37)

Modeling Transformation Modeling Transformation

translate both A and B by –p, bringing p to the origin.

y y

g g p g

p B p B

x

p B

x

p

y y

Rotate A&B Translate

y y

Rotate A&B

x

Translate

x

(38)

Modeling Transformation

Modeling Transformation

(39)

Wh t t!

What next!

참조

관련 문서

In each subfigure, the value of p

웹 표준을 지원하는 플랫폼에서 큰 수정없이 실행 가능함 패키징을 통해 다양한 기기를 위한 앱을 작성할 수 있음 네이티브 앱과

_____ culture appears to be attractive (도시의) to the

The index is calculated with the latest 5-year auction data of 400 selected Classic, Modern, and Contemporary Chinese painting artists from major auction houses..

The language of the journey is used as indicative of the reality that transformation and achievement of equality and justice are actually a process not necessarily a once

The “Asset Allocation” portfolio assumes the following weights: 25% in the S&P 500, 10% in the Russell 2000, 15% in the MSCI EAFE, 5% in the MSCI EME, 25% in the

1 John Owen, Justification by Faith Alone, in The Works of John Owen, ed. John Bolt, trans. Scott Clark, "Do This and Live: Christ's Active Obedience as the

A virtual displacement of a generalized coordinate in physical space ~ A combination of virtual displacements subjected to the constraints of... Generally, the