3D Geometric
T f i
Transformations
Chapter 5 Chapter 5
Intro. to Computer Graphics Spring 2008, Y. G. Shin
3D Transformation 3D Transformation
Right-handed coordinate system
⎥ ⎤
⎢ ⎡
⎥ ⎤
⎢ ⎡
⎥ ⎤
⎢ ⎡ ' x x
1x
2x
3t
xx
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
zz
x
z
3D Transformation 3D Transformation
⎤
⎡ 1 0 0
Translation
⎤
⎡
Scaling
⎥ ⎥
⎤
⎢ ⎢
⎡
0 1
0
0 0
1
xt 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
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!
Rotation About Arbitrary Axis
Rotation About Arbitrary Axis
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(θ) = −1 ⋅ x−1(α)⋅ y−1(β)⋅ z(θ)⋅ y(β)⋅ x(α)⋅
Rotation About Arbitrary Axis Rotation About Arbitrary Axis
R t t t th i
Rotate u onto the z-axis
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
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
2c b
z
= +
= ′
u
α u
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
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
1xr
2xr
3xy
P3 y
⎥ ⎥
⎥
⎦
⎤
⎢ ⎢
⎢
⎣
⎡
=
y y yx x
x
r r
r
R
1 2 33 2
1
P1
P2 3
P3
⎥⎦
⎢⎣ r
1zr
2zr
3zx z
x z P2 1
P
z z
Initial position Final position
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
xRz
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
=
Rotation about an arbitrary axis
i th l t i
using orthogonal matrix
Finally
y R Finally,
[
y y y]
z xy
r r r R R
R =
1 2 3= ×
Rx
P R
P3
Ry
Rz
P x P3 P1
P2
P1
⎥ ⎤
⎢ ⎡ R
xz 2 P
⎥ ⎥
⎥
⎢ ⎢
= ⎢
⋅
=
x y yR R R
R
R ( β ) ( α )
⎥⎦
⎢⎣ R
zReflection 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
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.
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 =
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
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
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 matrixEuler R
XYZγ β α
Not easy
Gimble
Gimble
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
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.
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)
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.
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
rotr× r +
⋅
− +
⋅
=
θ
θ
)
(
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
3v + θ + θ
=
vr
2v
θ
vr
3θ
3
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
ie
ie
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
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+
3j ik
ki i
kj jk
k ji
ij
k j
i
=
=
=
=
=
=
−
=
=
=
2 21 ,
2
j ik
ki i
kj jk
k ji
ij = − = , = − = , = − =
2 2
2
v
2v v
s
q = s + v
1+ v
2+ v
3q = + + +
Quaternions
θPr
Quaternions
urA 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 22
1
q s s v v s v s v v v
q + + ×
) ,
0
rotated
( p
rotatedP =
) (
) (
2 )
2
(
p v
v p
v v
p v p
p
rotated= s + ⋅ + s × + × ×
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)
sincosθ θ
=
= v
s
[Example] Rotation about z-axis
( )
sin 2 1 , 0 , 0
2 ,
cos =
= v
s
•pprotated
•
o p
z ur
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.
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
Modeling Transformation
Modeling Transformation
Modeling Transformation Modeling Transformation
?
?
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
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 Bx x
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
py y
Rotate A&B Translate
y y
Rotate A&B