Title: Affine Transformation
1Affine Transformation
2Affine Transformations
In this lecture, we will continue with the
discussion of the remaining affine
transformations and composite transformation matri
x
3Reflection
- 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)
4Reflection (cont.)
For 2-D reflection, the transformation matrix F
has the Following form
F(y)
F(x)
About x-axis about y-axis
5Reflection (cont.)
For 3-D reflection, the transformation matrix F
has the following form
F(z)
Reflection about z-axis
6Reflection (cont.)
Reflection can be generalized by concatenating
rotation and reflection matrices. Example If
reflection at yx 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
7Shearing
- 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
8Shearing (cont.)
For 2-D shearing transformation the
transformation matrix has The following form
X direction y direction
9Shearing (cont.)
The values can be positive or negative
numbers Positive moves points to the
right Negative moves points to the left
10Shearing (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
11Example (3-D shearing)
Let us consider a unit cube whose lower left
corner coincides With the origin
12Example (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 z1 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
13Composition 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)
14Example
Let say we want to produce an object that goes
through the following transformation
operations translate by (3, -4), M1 then
rotate through 30 degree, M2 then scale by (2,
-1), M3 then translate by (0, 1.5), M4 and
finally, rotate through 30 degree, M5
All of these transformation can be represented by
a single matrix, M M M5M4M3M2M1
15Example (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)
16Affine transformation in OpenGL
Recall our lesson on OpenGL graphics pipeline.
CT Current Transformation
17OpenGL
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) gl
LoadIdentity()
18OpenGL
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
19OpenGL
CT CT.T (translation matrix) CT CT.S (scaling
matrix) CT CT.R (rotation matrix) CT CT.M (arbit
rary 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
20OpenGL
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)
21OpenGL
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) glTran
slatef(-4.0,-5.0,-6.0) NB Take note at the
reverse order implementation
22OpenGL
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)
23OpenGL
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.
24OpenGL
To define a user-defined matrix (for shearing and
reflection) we can follow the same way as shown
below Glfloat myarray16 for (i0ilt3i)
for(j0j3j) myarray4ji Mij