3D Modelling Transformations
1
3D Modelling
Transformations
2
Intended Learning Outcomes
Understand the use of homogeneous coordinates
Learn different types of 3D transforms and the concept
of composite transform
Able to use coordinate transform to switch between one
coordinate frame to another
Able to use OpenGL to implement coordinate transform
3
Homogeneous coordinates
Represent a n-dimensional entity as a (n+1)-
dimensional entity
Allow all linear transforms to be expressed as
matrix multiplications; eliminate matrix
addition/subtraction
4
Linear Transform
P2 = M1P1 + M2
P1 n-dimensional points (n x 1 column vector)
P2 Transformed n-dimensional points
(n x 1 column vector)
M1 n x n square transform matrix
M2 n x 1 column transform vector
Homogeneous coordinates allow us to express the
multiplicative term M1 and the addition term M2 in a
common 4 x 4 matrix. This is achieved by adding one
dimension w.
5
3D Point
A 3D point (n = 3) can be expressed as
(X, Y, Z) Euclidean coordinates
(XW, YW, ZW, W) Homogeneous coordinates
W can be any non-zero value.
W
Z
Z
W
Y
Y
W
X
X WWW ===
6
3D Translation
Euclidean
P2 = P1 + T(tX, tY, tZ)
Homogeneous
P2 = T(tX, tY, tZ)P1
Note : W2 = W1=1
+
=
Z
Y
X
t
t
t
Z
Y
X
Z
Y
X
1
1
1
2
2
2
100
010
001
=
1
1
1
1
2
2
2
2
1000
100
010
001
W
Z
Y
X
t
t
t
W
Z
Y
X
Z
Y
X
7
3D Rotations
Rotation about an axis
CCW ⇒ POSITIVE rotation
Right Hand Rule
8
2D Rotations about the origin
About a common coordinate system X-Y
X
Y
(X1, Y1)
(X2, Y2)
−
=
1
1
2
2
cossin
sincos
Y
X
Y
X
θθ
θθ
(0, 0)
Equivalent to rotation about Z
axis, which is pointing out of
paper
9
Rotation about Z
Euclidean
P2=RZ(θ)P1
Homogeneous
P2=RZ(θ)P1
−
=
1
1
1
2
2
2
100
0cossin
0sincos
Z
Y
X
Z
Y
X
θθ
θθ
−
=
1
1
1
1
2
2
2
2
1000
0100
00cossin
00sincos
W
Z
Y
X
W
Z
Y
X
θθ
θθ
10
Rotation about X
Euclidean
P2=RX(θ)P1
Homogeneous
P2=RX(θ)P1
−=
1
1
1
2
2
2
cossin0
sincos0
001
Z
Y
X
Z
Y
X
θθ
θθ
−
=
1
1
1
1
2
2
2
2
1000
0cossin0
0sincos0
0001
W
Z
Y
X
W
Z
Y
X
θθ
θθ
11
Rotation about Y
Euclidean
P2=RY(θ)P1
Homogeneous
P2=RY(θ)P1
−
=
1
1
1
2
2
2
cos0sin
010
sin0cos
Z
Y
X
Z
Y
X
θθ
θθ
−
=
1
1
1
1
2
2
2
2
1000
0cos0sin
0010
0sin0cos
W
Z
Y
X
W
Z
Y
X
θθ
θθ
12
Scaling about the origin
Euclidean
P2=S(sX, sY, sZ)P1
Homogeneous
P2=S(sX, sY, sZ)P1
=
1
1
1
2
2
2
00
00
00
Z
Y
X
s
s
s
Z
Y
X
Z
Y
X
=
1
1
1
1
2
2
2
2
1000
000
000
000
W
Z
Y
X
s
s
s
W
Z
Y
X
Z
Y
X
13
Reflection about the X-Y plane
Euclidean
P2=RFZP1
Homogeneous
P2=RFZP1
−
=
1
1
1
2
2
2
100
010
001
Z
Y
X
Z
Y
X
−
=
1
1
1
1
2
2
2
2
1000
0100
0010
0001
W
Z
Y
X
W
Z
Y
X
14
Shearing about the Z axis
Euclidean
P2=Shz(a,b)P1
Homogeneous
P2=ShZ(a,b)P1
=
1
1
1
2
2
2
100
10
01
Z
Y
X
b
a
Z
Y
X
=
1
1
1
1
2
2
2
2
1000
0100
010
001
W
Z
Y
X
b
a
W
Z
Y
X
15
Affine Transform
aij and bi are constants.
a linear transformation
// lines are transformed to // lines
Translation, rotation, scaling, reflection, shearing are
special cases
Any affine transform can be expressed as composition of
the above 5 transforms
+
=
3
2
1
1
1
1
333231
232221
131211
2
2
2
b
b
b
z
y
x
aaa
aaa
aaa
z
y
x
16
Composite Transformation
A number of (relative) transformations applied in
sequence
Models the complex movement of an object in the world
coordinate system
The transformation is pre-computed where possible.
In practice, ONLY the final 4 x 4 composite
transformation needs to be stored.
17
E.g. 1 Rotation about an axis // to X axis.
Let (Xf, Yf, Zf) be a point on the axis. The
composite rotation is
P2 = T-1Rx(θ)T P1
T = T(-Xf, -Yf, -Zf)
18
For the composite transformation
Only the product
is stored
−
−
−
−
1000
100
010
001
1000
0cossin0
0sincos0
0001
1000
100
010
001
f
f
f
f
f
f
Z
Y
X
Z
Y
X
θθ
θθ
+−−
++−−
1000
cossincossin0
sincossincos0
0001
fff
fff
ZZY
YZY
θθθθ
θθθθ
19
E.g. 2 Scaling about (Xf, Yf, Zf)
P2 = T-1S(sX, sY, sZ)T P1
T = T(-Xf, -Yf, -Zf)
Similarly, only the final 4 x 4 composite transformation is
stored
20
Concept
A composite transformation may have two
physical meaning:
Either
It represents a physical action
Or
It represents a change of coordinate system
21
3 Kinds of Coordinate System in CG
Each object defined in their own natural
coordinate system – Modelling coordinate
system (MC)
All objects being placed in a common world
coordinate system (WC)
For correct viewing by a camera, objects
need to be expressed in a common viewer or
camera coordinate system (VC, CC)
MC → WC → VC/CC
22
A point in two different coordinate sy.
The SAME point has DIFFERENT coordinates in
DIFFERENT coordinate systems
)1()2( )( PRP θ−=
X1
Y1
X2
Y2
(X2, Y2) ~ (X1, Y1)
θ
−−
−−−
=
1
1
2
2
)cos()sin(
)sin()cos(
Y
X
Y
X
θθ
θθ
23
P(i) A point in coordinate system i
Mj←i 4 x 4 transformation that transforms
a point in coordinate system i to
coordinate system j
P(j) = Mj←i P(i)
24
Rule 1 for computing Mj←i :
Mj←i is the inverse of the transformation
that takes the ith coordinate system
frame as if it is an object to the jth
coordinate system frame position, all the
time using the ith coordinate system as
the reference coordinate system
As Mj←i = Mi←j-1, we have the alternative rule:
25
Alternative rule (rule 2) for computing Mj←i :
Mj←i is the transformation that takes the jth
coordinate system frame as if it is an
object to the ith coordinate system frame
position, all the time using the jth
coordinate system as the reference
coordinate system
which rule to use depends on which
coordinate system is easier to get on hand
26
Mj←i is the INVERSE of the transformation that takes the ith coordinate system frame as if it is an object to the jth coordinate system frame
Proof
Suppose we have two coordinate systems xi-yi-zi and xj-yj-zj. Treat xi-yi-zi and xj-yj-zj as two objects that consist of two sets of points, both
defined in the xi-yi-zi coordinate system. Let
xi = (1, 0, 0)
T → xj = (a11, a21, a31)
T + (tx, ty, tz)
T
yi = (0, 1, 0)
T → yj = (a12, a22, a32)
T + (tx, ty, tz)
T
zi = (0, 0, 1)
T → zj = (a13, a23, a33)
T + (tx, ty, tz)
T
where all the coordinates are defined in the xi-yi-zi coordinate system. → means “corresponds to”.
The transformation T that transforms the three points xi, yi, zi to xj, yj, zj in the xi-yi-zi coordinate system is thus
=
1000
333231
232221
131211
z
y
x
taaa
taaa
taaa
T
However, it can also be interpreted as changing from coordinate system j to coordinate system i. Thus
P(j) = (1, 0, 0)T → P(i) = (a11, a21, a31)
T + (tx, ty, tz)
T
P(j) = (0, 1, 0)T → P(i) = (a12, a22, a32)
T + (tx, ty, tz)
T
P(j) = (0, 0, 1)T → P(i) = (a13, a23, a33)
T + (tx, ty, tz)
T
Since any arbitrary P(j) can be written as T3T2T1 )1,0,0()0,1,0()0,0,1( λλλ ++ , where 321 ,, λλλ are constants, it follows that
TM =← ji
Since 1−←← = jiij MM ,
1−
← = TM ij
This gives the rule
Mj←i is the INVERSE of the transformation that takes the ith coordinate system frame as if it is an object to the jth coordinate system frame
27
OpenGL Geometric Transformations
4 x 4 translation matrix
glTranslatef (tx, ty, tz);
4 x 4 rotation matrix
glRotatef (theta, vx, vy, vz);
4 x 4 scaling matrix
glScalef (sx, sy, sz);
4 x 4 reflection matrix
glScalef (1, 1, -1); // reflection about Z axis
4 x 4 shearing matrix
glMultMatrixf (matrix); // matrix is a 16 element
// matrix in column-major order
28
OpenGL Matrix Operations
Calls the current matrix, responsible for geometrical
transformation
glMatrixMode (GL_MODELVIEW);
(do not confuse with glMatrixMode (GL_PROJECTION),
which is responsible for projection transformation)
Assign identity matrix to current matrix
glLoadIdentity ( );
29
Current matrix is modified by (relative) transformations
E.g. glTranslatef, glScalef, glRotatef …
The meaning of the relative transformations may either be
physical action or coordinate transformations
Current matrix are postmultiplied. Last operation
specified is first operation performed, like a LIFO stack
30
Let C be the composite matrix
Example 1
glMatrixMode (GL_MODELVIEW)
glLoadIdentity ( ); // C = identity matrix
glTranslatef (-25, 50, 25); // C = T(-25,50,25)
glRotatef (45, 0, 0, 1); // C = T (-25,50,25)RZ(45o)
glScalef (1, 2, 1); // C = T (-25,50,25)RZ(45o) S(1,2,1)
31
Example 2
glMatrixmode (GL_MODELVIEW)
glLoadIdentity ( );
glScalef (1, 2, 1);
glRotatef (45, 0, 0, 1);
glTranslatef (-25, 50, 25); // C = S(1,2,1)RZ(45o)T(-25,50,25)
Note: the order of the transformation is important
32
OpenGL Matrix Stacks
OpenGL has a stack for storing the relative
transformations
Stack is a LIFO data structure
Stores intermediate results
Push the current matrix into the stack
glPushMatrix ( );
Pop the current matrix from the stack
glPopMatrix ( );
Note: Very useful for modelling hierarchical structures
33
Example
glMatrixMode (GL_MODELVIEW)
glLoadIdentity ( ); // MV = identity matrix
glTranslatef (-25, 50, 25); // MV = T(-25,50,25)
glRotatef (45, 0, 0, 1); // MV = T (-25,50,25)RZ(45o)
glPushMatrix ( ); // MV is pushed to the stack
glScalef (1, 2, 1); // MV = T (-25,50,25)RZ(45o) S(1,2,1)
glTranslatef (0, 0, 10); // MV = T RZ(45o)S(1,2,1) T(0, 0, 10)
glPopMatrix ( );
// MV = T (-25,50,25)RZ(45o)
34
References
Text: Sec 7.2 -7.3, 9.1 – 9.7 (except quaternion method),
9.8. The text uses a different exposition of the
coordinate transformation method.
Our discussion of coordinate transformation follows:
Foley et. al., Computer Graphics, 2nd Ed., 222-226
The two methods of coordinate transformation are
conceptually the same.
3D Modelling Transformations
Intended Learning Outcomes
Homogeneous coordinates
Linear Transform
3D Point
3D Translation
3D Rotations
2D Rotations about the origin
Rotation about Z
Rotation about X
Rotation about Y
Scaling about the origin
Reflection about the X-Y plane
Shearing about the Z axis
Affine Transform
Composite Transformation
E.g. 1 Rotation about an axis // to X axis. � ��
Slide Number 18
E.g. 2 Scaling about (Xf, Yf, Zf)
Concept
3 Kinds of Coordinate System in CG
A point in two different coordinate sy.
Slide Number 23
Slide Number 24
Slide Number 25
Slide Number 26
OpenGL Geometric Transformations
OpenGL Matrix Operations
Slide Number 29
Slide Number 30
Slide Number 31
OpenGL Matrix Stacks
Slide Number 33
References
®
T
ú
ú
ú
ú
û
ù
ê
ê
ê
ê
ë
é
=
1
0
0
0
33
32
31
23
22
21
13
12
11
z
y
x
t
a
a
a
t
a
a
a
t
a
a
a
T
T
3
T
2
T
1
)
1
,
0
,
0
(
)
0
,
1
,
0
(
)
0
,
0
,
1
(
l
l
l
+
+
3
2
1
,
,
l
l
l
T
M
=
¬
j
i
1
–
¬
¬
=
j
i
i
j
M
M
1
–
¬
=
T
M
i
j
The inverse of the transformation that transforms a set of points from the ith object to the jth object within the ith coordinate system is the transformation Mij
Mj(i is the INVERSE of the transformation that takes the ith coordinate system frame as if it is an object to the jth coordinate system frame
Proof
Suppose we have two coordinate systems xi-yi-zi and xj-yj-zj. Treat xi-yi-zi and xj-yj-zj as two objects that consist of two sets of points, both defined in the xi-yi-zi coordinate system. Let
xi = (1, 0, 0)T ( xj = (a11, a21, a31)T + (tx, ty, tz)T
yi = (0, 1, 0)T ( yj = (a12, a22, a32)T + (tx, ty, tz)T
zi = (0, 0, 1)T ( zj = (a13, a23, a33)T + (tx, ty, tz)T
where all the coordinates are defined in the xi-yi-zi coordinate system.
means “corresponds to”.
The transformation
that transforms the three points xi, yi, zi to xj, yj, zj in the xi-yi-zi coordinate system is thus
However, it can also be interpreted as changing from coordinate system j to coordinate system i. Thus
P(j) = (1, 0, 0)T ( P(i) = (a11, a21, a31)T + (tx, ty, tz)T
P(j) = (0, 1, 0)T ( P(i) = (a12, a22, a32)T + (tx, ty, tz)T
P(j) = (0, 0, 1)T ( P(i) = (a13, a23, a33)T + (tx, ty, tz)T
Since any arbitrary P(j) can be written as
, where
are constants, it follows that
Since
,
This gives the rule
Mj(i is the INVERSE of the transformation that takes the ith coordinate system frame as if it is an object to the jth coordinate system frame
(
_1220869945.unknown
_1377341704.unknown
_1377341717.unknown
_1377341727.unknown
_1377341657.unknown
_1220869515.unknown
_1220869890.unknown
_1220868992.unknown