0% found this document useful (0 votes)
42 views5 pages

Part 3 - Transformation - Notes

Uploaded by

Mark Mamdouh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views5 pages

Part 3 - Transformation - Notes

Uploaded by

Mark Mamdouh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Geometric Transformations

These notes contain some guidance for all students regarding transformations. This part is covered
in chapter 3 in your textbook. You can use the material here as a summary.

This is about geometric transformation which is used to describe moving objects in space. First we
must introduce the concept of frames. A frame in 3D space is composed of 3 vectors (usually
orthogonal) and a point (origin). Any object in space has a frame associated with it. You can move
objects between different frames. Moving objects also have their own frames. Objects are formed
by a set of points in space (sometimes called control points; so each object has its own control
points).

To start, I first present 2D frames and the types of motion objects in 2Dmay encounter.

2D Translation
A point P(x,y,1) in 2D is translated to P`(x+a, y+b,1) using the matrix Ta,b = 1 0 0
010
ab1
P` = P . Ta,b
= [x y 1] * 1 0 0
010
ab1
= [x+a y+b 1] (which is what you expect)
Note that this presentation of point P = [x y 1] is called row major. It can also be represented by a
column major as P =[x y 1]T . In this case P` = Ta,b . P while Ta,b this time is: 1 0 a
0 1 b
0 0 1
P` = Ta,b . P
= 1 0 a x
0 1 b . y
0 0 1 1
= x+a
y+b
1 (again, this is what you expect)

2D Scaling:
Scaling in 2D takes places around a point. The standard scaling matrix is derived with respect to
scaling around the origin point (0,0,1). Scaling about the origin basically will scale the coordinates
of a point. So a point P=[x y 1] (row major) will become P`=[ax by 1]. Using the matrix
Sa,b = a 0 0
0 b 0
0 0 1
P` = P . Sa,b (do the multiplication and you will get the P` that you expect).
Also do it in the column-major format: P` = STa,b . P (P is in column-major)

Now what will you do if you need to scale about a different point than the origin? Simply translate
the point to the origin, do the scaling then translate back to the original coordinate of the point. This
means that three 3x3 matrices are going to be multiplied together to produce the overall matrix
which explains the whole process. Let's say the point you would like to scale about is at [p q 1],
then the overall transformation matrix is:

1
T = T-p,-q . Sa,b . Tp,q (you can choose between row or column major format)

2D Rotation
Rotation in 2D takes place around a point. The standard rotation matrix is derived with respect to
scaling around the origin point O(0,0,1) with angle t. It is quite simple to come up with the
coordinates of point P` which is the result of rotating point P about the origin; just use high school
geometry.

RO, t = cos t sin t 0


-sin t cos t 0
0 0 1

Similar to scaling around an arbitrary point, you can rotate about and arbitrary point by translating it
to the origin, rotate, then translate back to the original point.

You can deduce similar matrices on 2D shear.

Now talking about 3D transformation, we have to upgrade the matrix to a 4x4 matrices

Translation in 3D
Ta,b,c = 1 0 0 a
0 1 0 b
0 0 1 c
0 0 0 1
(this matrix is used with column-major format) (Can you write down the one used with row-major
format?) (Hint: transpose this one)

Scaling in 3D
Sa,b,c = Sx 0 0 0
0 Sy 0 0
0 0 Sz 0
0 0 0 1

Rotation in 3D
Rotation in 3D takes place around an axis (defined by a direction and a point). So we may define a
standard rotation matrix around a known axis, so we choose the ones we know; x, y or z axis. I give
here the standard matrix of rotation about the x-axis with angle t. (keep in mind that rotation about
the x-axis will not change the x coordinates of the rotated point)

Rx,t = 1 0 0 0
0 cos t -sin t 0
0 sin t cos t 0
0 0 0 1

We can derive similar matrices for rotation around the y axis, the z axis, or any arbitrary axis.

In opengl, we use:
glRrotatef() for which you have to specify the angle of rotation in degrees. And also specify the x, y,
and z coordinates of a vector (which the rotation is defined about).

2
glTranslatef() for which you have to specify the x, y, and z coordinates of a translation vector.

glScalef() for which you have to specify scale factors along the x, y, and z axes.

Camera/Viewing Transformations

This part is covered in chapter 4 in your textbook. You can use the material here as a summary.

This is the standard way in graphics of having a camera set in 3D space and manipulationg the 3D
space into an image. Everything you see in films, animated characters.. etc are made by placing the
camera using what we describe here as camera transformation.

The camera model we use is called pinhole camera where objects project obliquely vs parallel
projection where objects project orthographically. This has to be treated mathematically so that the
pyramid projection is looked at as a projection on cube. This means that camera transformation is
basically a mathematical implementation of perspective projection.

In pinhole camera model, a camera is defined using 5 parameters:


1) Camera position in 3D coordinates.
2) Pointing direction: This is the direction the camera is looking at
3) Up direction: this is the direction the camera is rotated at deviated from the up (see fig 4.18)

3
4) Viewing angle (this is the angle of the pyramid) generated by the size of the file (image surface
which is a rectangel)
5) Near and far clipping planes

Now with the above parameters, we can setup the camera to be pointing anywhere or even fly the
camera around in 3D space.

In opengl, we use:
gluLookAT() for which you have to specify:
- The position of the camera
- The position of the reference point (which can be used to determine the pointing direction of the
camera).
- The up direction of the camera.

gluPerspective() - which sets up the perspective projection matrix. For this you need to specify:
- The field of view angle, in degrees, in the y direction.
- The aspect ratio that determines the field of view in the x direction. The aspect ratio is the ratio of
x (width) to y (height) of the viewing plane.
- The distance from the viewer to the near clipping plane (always positive).
- The distance from the viewer to the far clipping plane (always positive).

cotan α1/2 0 0 0
V= 0 cotan α2/2 0 0
0 0 (f+n) / (f-n) -1
0 0 2f/(f-n) 0

α1 and α2 are the field of view angles in the x direction and the y direction, respectively. Note that
you will use one angle and an aspect ratio in the API gluPerspective() instead of using two angles.
To do all of these transformations you will need some kind of matrix operations. In particular you
need matrix stacks.
Matrix stack

... Vertex 2 Vertex 1 Transformation


* * Transformation * Transformation ... Transformed Transformed
matrix n matrix 2 matrix 1 Vertex 2 Vertex 1

Opengl will do the multiplication of all transformation matrices


pushed in the stack and have only one matrix in the stack in
which all verticies will be transformed with

So let's say you would like to process a translation followed by a rotation on a set of vertices, then
what you will do is construct a translation matrix that will do the job for you (using glTranslatef() ).
And same goes with the rotation matrix (using glRotatef() ). Then you will use the matrix mode:
glMatrixMode(GL_MODELVIEW) and push these two matrices in it:

Matrix stack (GL_MODELVIEW)

... Vertex 2 Vertex 1 Rotation Translation ... Transformed Transformed


* *
Matrix matrix Vertex 2 Vertex 1

Opengl will do the multiplication of the two matrices and have only
one matrix in the stack in which all verticies will be transformed with
4
As another example, let's say you would like to push a projection matrix into the stack (for example
you construct the projection matrix using gluPerspective() ):

Matrix stack (GL_PROJECTION)

... Vertex 2 Vertex 1 Projection ... Transformed Transformed


*
matrix Vertex 2 Vertex 1

Sometimes you need to process a set of vertices using a given set of transformation matrices and
another set of set of vertices using another set of transformation matrices. In that case you will need
to clear/reset the opengl matrix stack by loading the Identity matrix using glLoadIdentity().

You might also like