Saint Louis University |
Computer Science 146
|
Dept. of Math & Computer Science |
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
A basic translation, say by (dx,dy), can be viewed as a matrix addition
Scaling about the origin can be implemented simply as a scalar multiplication.
Rotation about the origin involves a bit of trigonometry, but can be expressed by the following matrix multiplication:
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.
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.
You will put this theory into action by looking at two commonly desired transformations:
While the basic rotation matrix works for rotating about the origin, a rotation about some other fixed point can be composed by performing three successive transformations. For the sake of example, assume that the fixed point is (a,b).
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.
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:
Please note that this particular file was specifically compiled for use on turing or any of the Linux Lab machines. I expect you to do your work for this assignment on those machines, but if that is not an option, please speak with me to make other arrangements.
makefrom the terminal window, assuming your working directory is the one containing all of these files. If your program has any compilation errors, those will be reported and the build will fail. If your program does not produce compilation errors then the make command will produce a new executable as a file named affine (without any suffix). You can run that program by typing the following in the same working directory
./affinePlease note that if you ever change the source code in affine.cpp, you will need to rebuild the project by typing make again before executing the revised code.
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.