Your grade: Doing Part 1 tolerably will get you a 'C'. Doing it particularly nicely can get you a B. Doing the more difficult part (Part 2) and doing it well can earn you up to an 'A'.

This assignment is due electronically by the __midnight__ on
Thursday, July 12th (by the end of that day).
Remember, turn in __whatever__ you have done by that time.

This will be our introduction to geometric transformations, which lie behind much of computer graphics, especially animation. The basic part of this assignment will involve simple translation of a line, using the appropriate transformation matrices and a timing loop (thread). No grid or fat pixels are used in this assignment.

**Demo: ** Here's a simple demo of how a timing loop could be used
to move a line, but done without the matrix transformations you'll
need to do. Here's the
demo applet and the
demo source code.

**Assignment 3, Part 1:** You are to create a Matrix2D class and a CGLine2D
class such that the matrix can move the line in 2D and allows the line to be drawn.
The specifics follow:

- Create a class Matrix2D which will implement the transformations described in Section 5-2 of the textbook. Internally it holds its coordinates in a array of type double[3][3].
- It should have two constructors, Matrix2D(double angle) which creates a rotation matrix with elements shown in (5-19), pg. 190 and Matrix2D(double tx, double ty) which creates an array of the form (5-17) for translation.
- Write a method transformPoint(Point) for Matrix which returns a new Point equal to the argument Point transformed (multiplied) by the matrix. (Inside the method you may want to create a 3D array to make the matrix-vector computation more straightforward.) These computations are described early in Chapter 5.
- Create a CGLine2D class that uses two Point values internally to represent its two endpoints. Create an additional method transformCGLine2D(CGLine2D) of Matrix2D returns a new CGLine2D such that its two endpoints have both been transformed (multiplied) by the matrix using transformPoint() twice, each time with the same matrix.
- Create a method of CGLine2D(Graphics) that draws the line on the screen.
- Borrowing from my MoveLine.java code, set up a loop that translates the line by deltaX = 2 and deltaY = 1 and redraws it for 100 steps, 50 msec each.

**Assignment 3, Part 2 (Pretty Hard):** Create a static method mult(Matrix2D, Matrix2D)
of Matrix2D that multiplies two matrices together and returns the result as a new
matrix. Use this to write a static method rotateAroundPoint(double x, Point p)
that composes three matrices to first translate to the origin from p, then rotate
by theta and then translate back, effectively rotating around the point specified.
The method returns a new matrix that
is the appropriate product of the three specified.
Use this to "spin" a line around its center.
Do this in parallel for three different
lines of three different colors, each spinning around their own centers at different
rates. It'll be hard but it will look nice!
Hint: In doing these multiplications, you'll find it useful to create a matrix
of all zeroes, which you can do with zero arguments constructor. You'll need this
because matrix multiplication involves *adding* a set of products to get the final
value of each element.

See the page on electronic handins for the correct way to set up your directories and files for your electronic handins.

Return to Prof. Futrelle's home page