Affine Transformation
Affine Transformations
In this lecture, we will continue with the discussion of the
remaining affine transformations and composite transformation
matrix
Reflection
Reflection produces a mirror image of an object
It is also a rigid body transformation
Reflection is relative the axis of the reflection. In 2

D,
the axis are either x and y whereas 3

D includes z axis.
Reflection is actually a special case of scaling (with the negative
scale factor)
Reflection (cont.)
For 2

D reflection, the transformation matrix
F
has the
Following form
1
0
0
0
1
0
0
0
1
1
0
0
0
1
0
0
0
1
F(x) =
F(y) =
About x

axis
about y

axis
Reflection (cont.)
For 3

D reflection, the transformation matrix
F
has the
following form
1
0
0
0
0
1
0
0
0
0
1
0
0
0
0
1
F
(z) =
Reflection about z

axis
Reflection (cont.)
Reflection can be generalized by concatenating rotation and
reflection matrices.
Example: If reflection at y=x axis (45 degree), the transformations
involved are:
1. Clockwise rotation of 45 degree
2. Reflection about x axis
3. Counter clockwise rotation of 45 degree
Shearing
Distort an object by moving one side relative to another
It neither rigid body nor orthogonal transformation. I.e.
changing a square into parallelogram in 2

D or cube into
parallelepiped in 3

D space
It is normally used to display italic text using regular ones
Shearing (cont.)
For 2

D shearing transformation the transformation matrix has
The following form
X direction
y direction
1
0
0
0
1
0
0
1
x
sh
1
0
0
0
1
0
0
1
y
sh
Shearing (cont.)
The values can be positive or negative numbers
Positive: moves points to the right
Negative: moves points to the left
Shearing (cont.)
For 3

D space shearing transformations the number of
Transformation matrix are many.
Basically, to get one transformation matrix for shearing, we can
Substitute any zero term in identity matrix with a value like
Example below:
1
0
0
0
0
1
0
0
1
0
0
0
1
b
c
a
Example (3

D shearing)
Let us consider a unit cube whose lower left corner coincides
With the origin
Example (3

D shearing)
Based on the diagram, we want to shear the cube at about
the z axis. In this case the face of the cube that lies on
the xy

coordinate plane does not move. The face that lies
on the plane z=1 is translated by a vector (shx,shy). This is
called xy

shear. Under the xy

shear, the origin and x

and
y

unit vectors are unchanged. The transformation matrix
for this transformation is:
1
0
0
0
0
1
0
0
0
1
0
0
0
1
y
x
sh
sh
Composition matrix
As can be seen in the previous example, we can actually
compose or concatenate many affine transformation matrices
to produce a single (resultant) affine transformation matrix
For example, to get a composition matrix for rotation and
translation, we perform matrix multiplication.
We can build a composite transformation for a general

case
transformation at any other points (besides origin)
Example
Let say we want to produce an object that goes through the
following transformation operations:
translate by (3,

4),
M
1
then rotate through 30 degree,
M
2
then scale by (2,

1),
M
3
then translate by (0, 1.5),
M
4
and finally, rotate through
–
30 degree,
M
5
All of these transformation can be represented by a single
matrix,
M
M = M
5
M
4
M
3
M
2
M
1
Example (cont.)
Composition matrix for affine transformations can only be
produced if we use homogenous coordinates (for translation
case).
Notice the multiplication is done in
reverse order
(FILO)
Exercise
: Build a transformation matrix that
a) rotates through 45 degrees
b) then scales in x by 1.5 and in y by
–
2,
c) and finally translates through (3,5)
Find the image under this transformation of the point
(1,2)
Affine transformation in OpenGL
Recall our lesson on OpenGL graphics pipeline.
CT = Current Transformation
OpenGL
All the transformations will be performed in CT by changing the
Current transformation matrix. In other way, the CT matrix is
An example of composite matrix.
Typically, in OpenGL, we will have the following fragment of
code in our program before we start performing transformations.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
OpenGL
By having this code in our program, we set our matrix
Mode to be GL_MODELVIEW and
initialize the CT matrix to be identity
CT I
Once we have set this, we can perform transformation
Which means we modify the CT by post

multiplication by a
matrix
OpenGL
CT
CT.T
(translation matrix)
CT
CT.S
(scaling matrix)
CT
CT.R
(rotation matrix)
CT
CT.M
(arbitrary matrix)
Once all of the transformation matrix multiplications have
been done, the vertices will be transformed based on
the final (composite) matrix
In OpenGL all matrices are in 4 x 4 matrix
OpenGL
The three transformation supported in most graphics system
(including OpenGL) are translation, rotation with a fixed point
of the origin and scaling with a fixed point of the origin.
The functions for these transformation in OpenGL are:
glTranslatef(dx, dy, dz);
glRotatef (angle, vx, vy, vz);
glScalef(sx, sy, sz);
OpenGL
If we want to perform rotation at any other point using the
provided functions in OpenGL, (I.e. 45 degree rotation about
the line through the origin and the point (1,2,3) with a fixed
point of (4,5,6).) the following code fragment shows us how to
perform this transformation.
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(4.0,5.0,6.0);
glRotatef(45.0,1.0,2.0,3.0);
glTranslatef(

4.0,

5.0,

6.0);
NB: Take note at the reverse order implementation
OpenGL
For most purposes, rotation, translation and scaling can be
used to form our desired object. However, in some cases
the provided transformation matrices are not enough. For
example, if we want to form a transformation matrix for
shearing and reflection.
For these transformations, it is easier if we set up the matrix
directly. We can load a 4 x 4 homogeneous

coordinate
matrix as the current matrix (CT)
OpenGL
To load the matrix we call this function:
glLoadMatrixf(myarray);
Or we can multiply our shearing matrix by calling this function
glMultMatrixf(myarray);
Where
myarray
is a one

dimensional array of 16 element
arranged by colomns.
OpenGL
To define a user

defined matrix (for shearing and reflection)
we can follow the same way as shown below:
Glfloat myarray[16];
for (i=0;i<3;i++)
for(j=0;j=3;j++)
myarray[4*j+i] = M[i][j];
Enter the password to open this PDF file:
File name:

File size:

Title:

Author:

Subject:

Keywords:

Creation Date:

Modification Date:

Creator:

PDF Producer:

PDF Version:

Page Count:

Preparing document for printing…
0%
Comments 0
Log in to post a comment