09transformation3d

Page 1

Graphics

3D Geometric Transformation ????? ??? ???? ???

Graphics Lab @ Korea University


Contents 

Translation

Scaling

Rotation

Rotations with Quaternions

Other Transformations

Coordinate Transformations

CGVR

Graphics Lab @ Korea University


Transformation in 3D 

CGVR

Transformation Matrix A B  C  0

D E F 0

G H I 0

J K  L  S

     

 3 ×1   1×1

3×3 1× 3

3×3 : Scaling, Reflection, Shearing, Rotation 3×1 : Translation 1×1 : Uniform global Scaling 1×3 : Homogeneous representation Graphics Lab @ Korea University


3D Translation 

CGVR

Translation of a Point x' = x + t x ,

y' = y + t y , z' = z + t z y

x z

 x' 1  y ' 0  =  z '  0     1  0

0 1

0 0

0 0

1 0

t x  x     t y  y  t z  z    1  1 

Graphics Lab @ Korea University


3D Scaling 

CGVR

Uniform Scaling x' = x ⋅ s x ,

y' = y ⋅ s y , z' = z ⋅ sz y

x

 x' s x  y '  0  =  z'  0    1   0

0

0

sy 0

0 sz

0

0

0  x  0 y  0  z    1  1 

z

Graphics Lab @ Korea University


Relative Scaling 

CGVR

Scaling with a Selected Fixed Position y

z

y

x

Original position

y

x

z

x

z

Translate

 x'  1  y '  0 T ( x f , y f , z f ) ⋅ S ( s x , s y , s z ) ⋅ T ( − x f ,− y f ,− z f ) =   =   z'  0     1  0

y

Scaling 0 1 0 0

x

z

Inverse Translate

0 x f   sx 0 0 0 y f   0 s y 0 1 z f   0 0 sz  0 1  0 0 0

0  1 0  0 0  0  1  0

0 1 0 0

0 − x f   x 0 − y f   y  1 − zf  z   0 1   1

Graphics Lab @ Korea University


3D Rotation 

Coordinate-Axes Rotations   

CGVR

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

Graphics Lab @ Korea University


Coordinate-Axes Rotations 

Z-Axis Rotation

 x' cosθ  y '  sin θ  =  z'  0    1  0

− sin θ cosθ 0 0

0 0  x  0 0  y  1 0  z    0 1  1 

X-Axis Rotation 0  x '  1  y ' 0 cosθ  =  z '  0 sin θ    0  1  0

0 − sin θ cos θ 0

0  x  0  y  0  z    1  1 

Y-Axis Rotation  x'  cosθ  y '  0  =  z '  − sin θ    1  0

y

y

z

0 sin θ 1 0 0 cosθ 0 0

0  x  0  y  0  z    1  1 

y

x

x z

CGVR

x z

Graphics Lab @ Korea University


Order of Rotations 

CGVR

Order of Rotation Affects Final Position 

X-axis  Z-axis

Z-axis  X-axis

Graphics Lab @ Korea University


General 3D Rotations 

CGVR

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

Graphics Lab @ Korea University


General 3D Rotations 

CGVR

Rotation about an Arbitrary Axis Basic BasicIdea Idea

y

TT

(x2,y2,z2)

RR (x1,y1,z1) x z

RR-1-1 TT-1-1

1.1. Translate Translate(x1, (x1,y1, y1,z1) z1)totothe theorigin origin 2.2. Rotate Rotate(x’2, (x’2,y’2, y’2,z’2) z’2)on ontotothe thezz axis axis 3.3. Rotate Rotatethe theobject objectaround aroundthe thez-axis z-axis 4.4. Rotate Rotatethe theaxis axistotothe theoriginal original orientation orientation 5.5. Translate Translatethe therotation rotationaxis axistotothe the original originalposition position

R (θ ) = T −1R −x 1 ( α ) R −y1 ( β ) R z (θ ) R y ( β ) R x ( α ) T Graphics Lab @ Korea University


General 3D Rotations 

CGVR

Step 1. Translation y (x2,y2,z2)

(x1,y1,z1) x

1 0 T= 0  0

0 1 0 0

0 − x1  0 − y1  1 − z1   0 1 

z

Graphics Lab @ Korea University


General 3D Rotations 

CGVR

Step 2. Establish [ TR ]αx x axis y

(0,b,c) Projected Point

sin α = cos α =

(a,b,c) α

α x

z Rotated Point

0 1 0 cos α R x (α ) =  0 sin α  0 0

b b2 + c2 c b2 + c2 0 − sin α cos α 0

=

b d

=

c d

0  1 0 0 0 c / d =  0 0 b / d   1  0 0

0 −b/d c/d 0

0 0 0  1

Graphics Lab @ Korea University


Arbitrary Axis Rotation 

Step 3. Rotate about y axis by φ a d , cos β = l l l 2 = a2 + b2 + c2 = a2 + d 2

y

sin β = (a,b,c)

Projected Point

d = b2 + c2

l d

x

β (a,0,d)

z

CGVR

Rotated Point

cos β  0 Ry(β ) =   sin β   0

0 − sin β 1 0

0 cos β

0

0

0  d / l 0  0 = 0  a / l   1  0

0 − a / l 0 1 0 0 0 d / l 0  0 0 1

Graphics Lab @ Korea University


Arbitrary Axis Rotation 

CGVR

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

l θ

x

cos θ  sin θ R z (θ ) =   0   0

− sin θ cos θ 0 0

0 0 1 0

0 0 0  1

z

Graphics Lab @ Korea University


Arbitrary Axis Rotation 

CGVR

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

l

l

z

1 0 −1 −1 −1 T R x (α ) R y ( β ) =  0  0 x

0 0 − x1  1 0 1 0 − y1  0 cos α 0 1 − z1  0 − sin α  0 0 1  0 0

 cos β  0  − sin β   0

0 sin β 1 0 0 cos β 0 0

0 sin α cos α 0

0 0 0  1

0 0 0  1

R (θ ) = T −1R −x 1 ( α ) R −y1 ( β ) R z (θ ) R y ( β ) R x ( α ) T Graphics Lab @ Korea University


Example

CGVR

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

A Unit Cube Graphics Lab @ Korea University


Example 

CGVR

Step1. Translate point A to the origin

y B’(1,2,1)

A’(0,0,0)

z

x

1 0 T= 0  0

0 0 − 2 1 0 − 1  0 1 0  0 0 1

Graphics Lab @ Korea University


Example 

CGVR

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

y Projected point (0,2,1)

α z

B’(1,2,1)

l x B”(1,0,√5)

2 2 2 + 12

=

2 2 5 = 5 5

1 5 = 5 5

l = 12 + 2 2 + 12 = 6

1  0 R x (α ) =  0  0

0 5 5 2 5 5 0

0 2 5 − 5 5 5 0

0  0  0  1

Graphics Lab @ Korea University


Example 

CGVR

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

y

cos β =

(0,0,√6)

β

l

x B”(1,0, √ 5)

z

1 6 = 6 6 5 30 = 6 6

   Ry(β) =    

30 6 0 6 6 0

0 1 0 0

6 − 6 0 30 6 0

 0  0 0  1

Graphics Lab @ Korea University


Example 

CGVR

Step 4. Rotate the cube 90° about the z axis 0 − 1 1 0 R z ( 90°) =  0 0  0 0 

0 0 1 0

0 0 0  1

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

R (θ ) = T −1R −x 1 ( α ) R −y1 ( β ) R z ( 90°) R y ( β ) R x ( α ) T

Graphics Lab @ Korea University


Example 1 0 R (θ ) =  0  0       

0 1 0 0 2  5 0  1 0 1  5  2 5 0 1 0  0 −  5 0 0 1  0 0  1 30 6 0 − 0  6 6  0 0 1 0 0  6 30 0 0  0  6 6 0 0 0 1 0

CGVR 2 5 5 5 5 0

0  30  0  6  0 6 0 −  6 1  0

0 5 5 2 5 5 0

0 2 5 − 5 5 5 0

0

0 1 0 0 0  1 0  0  0 0   0  1

6 6 0 30 6 0 0 1 0 0

 0  0 − 1  0 1 0 0 0 0   0 0  1

0 0 0 0 1 0  0 1

0 − 2 0 − 1 1 0  0 1

 0.166 − 0.075 0.983 1.742   0.742  0 . 667 0 . 075 − 1 . 151  = − 0.650 0.741 0.167 0.560    0 0 1   0

Graphics Lab @ Korea University


Example 

CGVR

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

[ P′ ] = R ( θ ) ⋅ [ P ]  0.166  0.742 [ P′] =  − 0.650   0  2.650 − 0.558 =  1.467   1

− 0.075 0.983

1.742  0 0.075 − 1.151 1 0.167 0.560  1  0 1  1

0 1 1 0 0 1 1 0.667 1 1 1 0 0 0 0 0.741 0 0 1 1 0 0 1  0 1 1 1 1 1 1 1 1.667 1.834 2.816 2.725 1.742 1.909 2.891  − 0.484 0.258 0.184 − 1.225 − 1.151 − 0.409 − 0.483 1.301 0.650 0.817 0.726 0.560 − 0.091 0.076   1 1 1 1 1 1 1  Graphics Lab @ Korea University


Rotations with Quaternions 

CGVR

Quaternion  

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

q = ( s, v ) = s + ai + bj + ck

Rotation about any axis 

Set up a unit quaternion (u: unit vector) θ θ s = cos , v = u sin 2 2

Represent any point position P in quaternion notation (p = (x, y, z)) P = ( 0, p ) Graphics Lab @ Korea University


Rotations with Quaternions

CGVR

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

Produce the new quaternion P′ = ( 0, p′) p′ = s 2 p + v ( p ⋅ v ) + 2 s ( v × p ) + v × ( v × p )

Obtain the rotation matrix by quaternion multiplication M R (θ ) = R −x 1 ( α ) R −y1 ( β ) R z (θ ) R y ( β ) R x ( α )

1 − 2b 2 − 2c 2 2ab − 2 sc 2ac + 2 sb    =  2ab + 2 sc 1 − 2a 2 − 2c 2 2bc − 2 sa  2 2  2ac − 2 sb 2 bc + 2 sa 1 − 2 a − 2 b    Include the translations: R (θ ) = T −1M (θ ) T R

Graphics Lab @ Korea University


Example 

CGVR

Rotation about z axis  

θ θ Set the unit quaternion: s = cos , v = ( 0, 0, 1) sin 2 2 Substitute a=b=0, c=sin(θ/2) into the matrix: θ θ   2θ 1 − 2 sin − 2 cos sin 0  2 2 2    θ θ θ M R (θ ) =  2 cos sin 1 − 2 sin 2 0 2 2 2    2θ 0 0 1 1 − 2 sin = cos θ   2 θ θ 2 cos sin = sin θ cos θ − sin θ 0 2 2   =  sin θ cos θ 0  0 0 1 Graphics Lab @ Korea University


Other Transformations 

Reflection Relative to the xy Plane y

y z

z

CGVR

x

x

 x' 1  y' 0  =  z'  0     1  0

0 1 0 0

0  x  0 0 y  −1 0 z    0 1  1  0

Z-axis Shear  x' 1  y ' 0  =  z '  0     1  0

0 1

a b

0 0

1 0

0  x  0 y  0  z    1  1 

Graphics Lab @ Korea University


Coordinate Transformations 

CGVR

Multiple Coordinate System  

Local (modeling) coordinate system World coordinate scene

Local Coordinate System Graphics Lab @ Korea University


Coordinate Transformations 

CGVR

Multiple Coordinate System  

Local (modeling) coordinate system World coordinate scene

Word Coordinate System Graphics Lab @ Korea University


Coordinate Transformations 

CGVR

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

Graphics Lab @ Korea University


Coordinate Transformations  

CGVR

Transformation of an Object Description from One Coordinate System to Another Transformation Matrix Bring the two coordinates systems into alignment 1. Translation y’ y x’ u'y u'y y u'x (x0,y0,z0) u'x (0,0,0) x u 'z z u'z z’ (0,0,0) x 

z

T( − x0 , − y0 , − z0 )

Graphics Lab @ Korea University


Coordinate Transformations

CGVR

2. Rotation & Scaling y’ y u'y

u'x x z (0,0,0) z’ u'z

y u' y

y u'

x’

y

z

u ′x1 u ′ R =  y1 u ′z1  0

(0,0,0)u'x u' z

x

u ′x2 u ′y2 u ′z2

u ′x3 u ′y3 u ′z3

0

0

z

u' x (0,0,0) x u' z

0 0 0  1 Graphics Lab @ Korea University


Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.