Three Dimensional
Modeling
Transformations
Outline
Three-Dimensional transformation
Three-Dimensional Translation
Three-Dimensional Rotation
Three-Dimensional Scaling
Composite Three-Dimensional Transformations
Other Three-Dimensional Transformations
Transformations between Three-Dimensional Coordinate
Systems
Affine Transformations
OpenGL Geometric-Transformation Functions
OpenGL Three-Dimensional Geometric- Transformation
Programming Examples
Three Dimensional Modeling
Transformations
Methods for object modeling
transformation in three dimensions
are extended from two dimensional
methods by including consideration
for the z coordinate.
Three Dimensional Modeling
Transformations
Generalize from 2D by including z coordinate
Straightforward for translation and scale, rotation more
difficult
Homogeneous coordinates: 4 components
Transformation matrices: 4×4 elements
3D Point
We will consider points as column vectors.
Thus, a typical point with coordinates (x, y, z)
is represented as:
x
y
z
3D Point Homogenous Coordinate
A 3D point P is represented in
homogeneous coordinates by a 4-dim. Vect:
x
y
P
z
1
3D Point Homogenous Coordinate
We don't lose anything
x
The main advantage: it is easier to y
compose translation and rotation
Everything is matrix multiplication
z
1
3D Coordinate Systems
Right Hand coordinate system: Left Hand coordinate system:
3D Transformation
In homogeneous coordinates, 3D
transformations are represented by 4×4
matrixes:
a b c t
x
d e f t
y
g h i t
z
0 0 0 1
3D Translation
3D Translation
P is translated to P' by:
P T P
x 1 0 0 t x x
y 0 1 0 t y y
z 0 0 1 tz z
1 0 0 0 1 1
3D Translation
An object is translated in 3D dimensional by
transforming each of the defining points of the
objects .
3D Translation
An Object represented as a
set of polygon surfaces, is
translated by translate each
vertex of each surface and x ' , y ' , z '
redraw the polygon facets T t x , t y , t z
in the new position. x, y , z
Inverse Translation:
T (t , t , t ) T (t ,t ,t )
1
x y z x y z
3D Rotation
3D Rotation
In general, rotations are specified by a
rotation axis and an angle. In
two-dimensions there is only one
choice of a rotation axis that leaves
points in the plane.
3D Rotation
The easiest rotation axes are those that parallel to
the coordinate axis.
Positive rotation angles produce counterclockwise
rotations about a coordinate axis, if we are looking
along the positive half of the axis toward the
coordinate origin.
Coordinate Axis
Rotations
Coordinate Axis Rotations
Z-axis rotation:
For z axis same as
2D rotation:
P R z (θ) P
x' cos sin 0 0 x
y ' sin cos 0 0 y
z' 0 0 1 0 z
1 0 0 0 1 1
Coordinate Axis Rotations
Obtain rotations around other axes through
cyclic permutation of coordinate parameters:
x yzx
Coordinate Axis Rotations
X-axis rotation:
P R () P
x
x' 1 0 0 0 x
y ' 0 cos sin 0 y
z ' 0 sin cos 0 z
1 0 0 0 1 1
Coordinate Axis Rotations
Y-axis rotation:
P R () P
y
x' cos 0 sin 0 x
y ' 0 1 0 0 y
z ' sin 0 cos 0 z
1 0 0 0 1 1
General Three Dimensional
Rotations
General Three Dimensional Rotations
Rotation axis
parallel with
coordinate axis
(Example x axis):
1
P T R x (θ) T P
General Three
Dimensional
Rotations
An arbitrary axis
(with the rotation
axis projected onto
the Z axis):
R (θ) T 1 R x 1 (α) R y1 (β) R z (θ) R y (β) R x (α) T
General Three Dimensional Rotations
1 1 1
R (θ) T R (α) R (β) R z (θ) R y (β) R x (α) T
x y
A composite transformation combining translations and the
coordinate-axes rotations produces general three dimensional
rotation.
1. Translate the object so that the rotation axis passes through
the coordinate origin.
2. Rotate the object so that the axis rotation coincides with
one of the coordinate axes.
3. Perform the specified rotation about that coordinate axis.
4. Apply inverse rotation axis back to its original orientation.
5. Apply the inverse translation to bring the rotation axis back
to its original position.
Other way to look at
rotation
Roll, Pitch, Yaw
Roll, Pitch, Yaw
Imagine three lines running through an
airplane and intersecting at right
angles at the airplane's center of
gravity.
Roll
Roll: rotation around the front-to-back axis.
PITCH
Rotation around the side-to-side axis
YAW
Rotation around the vertical axis.
3D Scaling
3D Scaling
About origin: Changes the size of the object and
repositions the object relative to the coordinate origin.
P S P
x s x 0 0 0 x
y 0 sy 0 0 y
z 0 0 sz 0 z
1 0 0 0 1 1
3D Scaling
About any fixed point:
s x 0 0 (1 s x ) x f
0 sy 0 (1 s y ) y f
T ( x f , y f , z f ) S ( s x , s y , s z ) T( x f , y f , z f )
0 0 sz (1 s z ) z f
0 0 0 1
Composite
3D Transformations
Composite 3D Transformations
Same way as in two dimensions:
Multiply matrices
Rightmost term in matrix product is the first
transformation to be applied
Other 3D
Transformations
3D Reflections
About an axis: equivalent to 180˚rotation about that axis
About a plane:
1. A reflection through the xy plane: x 1 0 0 0 x
y 0 1 0 0 y
z 0 0 1 0 z
1 0 0 0 1 1
A reflections through the xz and the yz planes are
defined similarly.
3D Shearing
Modify object shapes
Useful for perspective projections:
E.g. draw a cube (3D) on a screen (2D)
Alter the values for x and y by an amount
proportional to the distance from z ref
1 0 shzx shzx z ref
0 1 shzy shzy z ref
M zshear
0 0 1 0
0 0 0 1
Transformations
Between
Coordinate Systems
Transformations Between Coordinate systems
y
Translate such y'
that the origins
overlap uy '
Rotate such
that the axes ( x0 , y0 , z0 ) ux ' x'
(0,0,0) x
overlap uz '
z z'
u ' x1 u ' x 2 u'x3 0
u ' u' y 2 u' y3 0
R T y1
T x0 , y0 , z0
u ' z1 u ' z 2 u'z3 0
0 0 0 1
Affine Transformations
A coordinate transformation of the form
x = axxx + axyy + axzz + bx
y = ayxx + ayyy + ayzz + by
z = azxx + azyy + azzz + bz is called an affine transformation.
Each of the transformed coordinates x, y, and z is a linear function of the
original coordinates x, y, and z, and parameters ai j and bk are constants
determined by the transformation type.
Affine transformations (in two dimensions, three dimensions, or higher
dimensions) have the general properties that parallel lines are transformed
into parallel lines, and finite points map to finite points.
Translation, rotation, scaling, reflection, and shear are examples of affine
transformations.
We can always express any affine transformation as some composition of
these five transformations
OpenGL Geometric-Transformation
Functions
OpenGL Three-Dimensional Geometric-
Transformation Programming
Examples:
1. Translation
glMatrixMode (GL_MODELVIEW);
glColor3f (0.0, 0.0, 1.0); // Set current color to blue.
glRecti (50, 100, 200, 150); // Display blue rectangle.
glPushMatrix ( ); // Make copy of identity (top) matrix.
glColor3f (1.0, 0.0, 0.0); // Set current color to red.
glTranslatef (-200.0, -50.0, 0.0); // Set translation parameters.
glRecti (50, 100, 200, 150); // Display red, translated rectangle.
glPopMatrix ( ); // Throw away the translation matrix.
glPushMatrix ( ); // Make copy of identity (top) matrix.
glRotatef (90.0, 0.0, 0.0, 1.0); // Set 90-deg. rotation about z
axis.
glRecti (50, 100, 200, 150); // Display red, rotated rectangle.
glPopMatrix ( ); // Throw away the rotation matrix.
glScalef (-0.5, 1.0, 1.0); // Set scale-reflection parameters.
glRecti (50, 100, 200, 150); // Display red, transformed rectangle.
OpenGL Three-Dimensional Geometric-
Transformation Programming
Examples:
2. Composite Transformation
class wcPt3D { public: GLfloat x, y, z; };
/* Procedure for generating a matrix for rotation about
/* an axis defined with points p1 and p2. */
void rotate3D (wcPt3D p1, wcPt3D p2, GLfloat thetaDegrees)
{
/* Set up components for rotation-axis vector. */
float vx = (p2.x - p1.x);
float vy = (p2.y - p1.y);
float vz = (p2.z - p1.z);
/* Specify translate-rotate-translate sequence in reverse order: */
glTranslatef (p1.x, p1.y, p1.z); // Move p1 back to original
position.
glRotatef (thetaDegrees, vx, vy, vz); // Rotate about axis through
origin
glTranslatef (-p1.x, -p1.y, -p1.z); // Translate p1 to origin.
}
OpenGL Three-Dimensional Geometric-
Transformation Programming
Examples:
2. Composite Transformation
Procedure for generating a matrix for a scaling
/* transformation with respect to an arbitrary fixed point. */
void scale3D (GLfloat sx, GLfloat sy, GLfloat sz, wcPt3D fixedPt)
{
/* Specify translate-scale-translate sequence in reverse order: */
/* (3) Translate fixed point back to original position: */
glTranslatef (fixedPt.x, fixedPt.y, fixedPt.z);
glScalef (sx, sy, sz); // (2) Scale with respect to origin.
/* (1) Translate fixed point to coordinate origin: */
glTranslatef (-fixedPt.x, -fixedPt.y, -fixedPt.z);
}
OpenGL Three-Dimensional Geometric-
Transformation Programming
Examples:
2. Composite
void displayFcn (void)Transformation
{
/* Input object description. */ /* Set up 3D viewing-transformation
routines. */
/* Display object. */
glMatrixMode (GL_MODELVIEW);
/* Input translation parameters tx, ty, tz. */
/* Input the defining points, p1 and p2, for the rotation axis. */
/* Input rotation angle in degrees. */
/* Input scaling parameters: sx, sy, sz, and fixedPt. */
/* Invoke geometric transformations in reverse order: */
glTranslatef (tx, ty, tz); // Final transformation: Translate.
scale3D (sx, sy, sz, fixedPt); // Second transformation: Scale.
rotate3D (p1, p2, thetaDegrees); // First transformation: Rotate.
/* Call routines for displaying transformed objects. */
}