Affine Transformation

Jan 24, 2016

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 - PowerPoint PPT Presentation

Welcome message from author

This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript

Affine Transformation

Affine Transformations

In this lecture, we will continue with the discussion of the remaining affine transformations and composite transformationmatrix

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 negativescale factor)

Reflection (cont.)

For 2-D reflection, the transformation matrix F has the Following form

100

010

001

100

010

001

F(x) = F(y) =

About x-axis about y-axis

Reflection (cont.)

For 3-D reflection, the transformation matrix F has the following form

1000

0100

0010

0001

F(z) =

Reflection about z-axis

Reflection (cont.)

Reflection can be generalized by concatenating rotation andreflection matrices.

Example: If reflection at y=x axis (45 degree), the transformationsinvolved are:

1. Clockwise rotation of 45 degree2. Reflection about x axis3. 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 hasThe following form

X direction y direction

100

010

01 xsh

100

01

001

ysh

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 canSubstitute any zero term in identity matrix with a value likeExample below:

1000

010

01

0001

b

ca

Example (3-D shearing)

Let us consider a unit cube whose lower left corner coincidesWith the origin

Example (3-D shearing)

Based on the diagram, we want to shear the cube at aboutthe z axis. In this case the face of the cube that lies onthe xy-coordinate plane does not move. The face that lies on the plane z=1 is translated by a vector (shx,shy). This iscalled xy-shear. Under the xy-shear, the origin and x- andy-unit vectors are unchanged. The transformation matrixfor this transformation is:

1000

0100

010

001

y

x

sh

sh

Composition matrix

As can be seen in the previous example, we can actually compose or concatenate many affine transformation matricesto produce a single (resultant) affine transformation matrix

For example, to get a composition matrix for rotation andtranslation, we perform matrix multiplication.

We can build a composite transformation for a general-casetransformation 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), 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, M5All of these transformation can be represented by a single matrix, M

M = M5M4M3M2M1

Example (cont.)Composition matrix for affine transformations can only be produced if we use homogenous coordinates (for translationcase).

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 theCurrent transformation matrix. In other way, the CT matrix isAn example of composite matrix.

Typically, in OpenGL, we will have the following fragment ofcode in our program before we start performing transformations.

glMatrixMode(GL_MODELVIEW);glLoadIdentity();

OpenGL

By having this code in our program, we set our matrixMode to be GL_MODELVIEW and initialize the CT matrix to be identity

CT I

Once we have set this, we can perform transformationWhich means we modify the CT by post-multiplication by amatrix

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 pointof 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 aboutthe line through the origin and the point (1,2,3) with a fixedpoint of (4,5,6).) the following code fragment shows us how toperform 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 casesthe provided transformation matrices are not enough. Forexample, if we want to form a transformation matrix forshearing 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 elementarranged 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];

Related Documents