Homework 3: Transformation Matrices
Due: Wednesday, Oct. 7, 11:59pm on Moodle
The goal of this homework is to practice using transformation matrices, both "on paper" and through code.
Part I: Working with Transformations (10 pts)
Answer the following Yes/No questions. If Yes, provide a brief justification (doesn't need to be a proof, but some kind of picture, matrix calculation, or explanation). If No, provide a counterexample. You can multiply the matrtrices by hand or using software like Matlab or Mathematica.
Credit: Joe O'Rourke
Part II: Implementing Transformations (10 pts)
For this part, you will build on Homework 2 and implement the transformations rotate, translate, and scale for your RegularPolygon class. First copy your Homework 2 into a new file and name it hw3.py.
def matrix_multiply(m1, m2):where m1 and m2 are 2D arrays. For example:
matrix_multiply([[2,4,3],[1,-5,0]], [[3,2],[-1,2],[4,3]])should return
[[14, 21], [8, -8]].
First, in the RegularPolygon constructor, add the line
self.vertices = []and then append each of the vertices to this list (you've probably already defined them in a for loop).
The second method "create_matrix" will create a 2D array (matrix) of the vertices of the polygon, so they can be easily passed in to your "matrix_multiply" method. The third method "update_vertices" will take in a 2D array (matrix) and update (overwrite) the polyons vertices.
def scale(self, ax, ay):where "ax" is the scaling for the x-coordinate and "ay" is the scaling for the y-coordinate. For each of these transformation matrices, first define the matrix in a 2D array. Second, create a matrix of the polygon vertices ("create_matrix"). Third, mutliply the transformation matrix and the matrix of vertices. Finally, use "update_vertices" with the resulting matrix.
def rotate(self, theta):where "theta" is the angle of rotation (counterclockwise).
def translate(self, tx, ty):where the x-coordinate is translated by "tx" and the y-coordinate is translated by "ty".
For this assignment, you are welcome to work together, but everyone should turn in their own math/code that they have written and understood. Please cite anyone you worked with at the top of your assignment.
EXTRA CREDIT OPTIONS: