Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Questionnaire | Schedule | Submit

Saint Louis University

Computer Science 146
Object-Oriented Practicum

Michael Goldwasser

Spring 2012

Dept. of Math & Computer Science

Assignment 02

Affine Transformations

Overview

Topic: Affine Transformations
Due: 11:59pm Tuesday, 1 February 2012

Please make sure you adhere to the policies on academic integrity.


The underlying goal for this assignment is to write code that uses our initial matrix class. Please make sure to refer to the documentation for our initial matrix class. You may also with to look at demo.cpp for a basic example of a program that makes use of our matrix class.

For your assignment, we will make use of the matrix class to explore the topic of affine transformations (e.g., rotations, translations, scaling). These are a mainstay in computer graphics (see for example this wikipedia article). For the sake of simplicity, we will focus on two-dimensional geometry. Assume that we represent the geometry of a point (x,y) as the column vector

\begin{displaymath}
\left[
\begin{array}{c}
x\\
y\\
\end{array}\right]
\end{displaymath}

A basic translation, say by (dx,dy), can be viewed as a matrix addition

\begin{displaymath}
\left[
\begin{array}{c}
x\\
y\\
\end{array}\right]
+
\left...
...\left[
\begin{array}{c}
x + dx\\
y + dy\\
\end{array}\right]
\end{displaymath}

Scaling about the origin can be implemented simply as a scalar multiplication.

\begin{displaymath}
c \cdot
\left[
\begin{array}{c}
x\\
y\\
\end{array}\right]...
...
\begin{array}{c}
c \cdot x\\
c \cdot y\\
\end{array}\right]
\end{displaymath}

Rotation about the origin involves a bit of trigonometry, but can be expressed by the following matrix multiplication:

\begin{displaymath}
\left[
\begin{array}{cc}
\cos \theta & \sin \theta\\
-\sin ...
...ight]
=
\left[
\begin{array}{c}
x'\\
y'\\
\end{array}\right]
\end{displaymath}

Unfortunately, such a system is not convenient when it comes to composing several transformations together (e.g., a combination of rotation, scaling, and translation), because the algebra relies upon different types of matrix operations. For example, there is not a simple way of expression a rotation around a non-origin fixed point using this style of linear algebra.


Homogeneous Coordinates

The treatment of the various transformations types can be unified by considering an embedding of the two-dimensional geometry into three-dimensions (more particularly, the z=1 plane of three dimensional space). We will model an (x,y) point as a column vector with three entries
\begin{displaymath}
\left[
\begin{array}{c}
x\\
y\\
1\\
\end{array}\right]
\end{displaymath}

Now we can show that all three types of transformations above can be expressed directly as multiplications with 3x3 matrices.

Furthermore, we can easily compute composite transformations as follows. Assume that we have an initial point represented by vector p wanted to perform a translation represented by matrix T, followed by a rotation described with matrix R. If performing that as two separate operations, we would begin by computing the translated point as T * p. We could then compute the rotation as R * (T * p). However, since matrix multiplications are associative, we could instead compute this as (R * T) * p. Notice that the composite result (R * T) is itself a 3x3 matrix that represents a single affine transformation that is the result of the translation followed by rotation. Notice that by precomputing that composite matrix, we can apply it not just to point p, but to any other point q.


Your task

You will put this theory into action by looking at two commonly desired transformations:

You are to write a program that offers the user an opportunity to perform one of these two operations, querying him or her for the location of the fixed point, and the relevant angle of rotation or scaling factor. You should compute the composite matrix that represents the complete affine transformation. Finally, you should offer the user an opportunity to apply that transformation to a series of chosen points.

Please make your program adhere to the format and user interface demonstrated in these three sample runs.


Computing environment

For this project, you will need to write code that uses the matrix class designed for CSCI 146. As such, you will need to combine your source code with several other files that we are providing. The easiest way to get started is to open up a terminal window in your turing account, change directories into a desired subdirectory of your home folder if desired, and to execute the following command verbatim

cp -R /Public/goldwasser/146/asgn02 .
This will cause a new folder named asgn02 to appear in your working directory including all files that you need for this assignment. Alternatively, these files can be downloaded individual from this website. There are four files in the distribution:

Submitting your project

Your assignment should be submitted electronically (details on the submission process). The only file that I need from you is the source code affine.cpp.


Michael Goldwasser
CSCI 146, Spring 2012
Last modified: Sunday, 29 January 2012
Course Home | Assignments | Computing Resources | Lab Hours/Tutoring | Questionnaire | Schedule | Submit