Question: Project 3 Pre-Lab: Background on Graphing and Transforming Images in Mathematica Name: __________________________ Date: _______________ < < sccc` ClearNames[] ShowMatrixForm[] Section 1.9 of the text
Project 3 Pre-Lab: Background on Graphing and Transforming Images in Mathematica Name: __________________________ Date: _______________
<< sccc` ClearNames[] ShowMatrixForm[]
Section 1.9 of the text explores 5 basic types of matrix transformations: rotations, reflections, contractions/expansions, shears and projections. Let's see how Mathematica can illustrate those transformations. We start with a basic image of a "house" which is displayed below with its vertices labeled. Our first step is to set up a matrix in which the columns of the matrix correspond to the corner points of the house. (See matrix H below.) We want Mathematica to plot this matrix of points, so the points are listed in order starting at (0,0) and proceeding clockwise. The final column is also the point (0,0) because we'll want Mathematica to finish its drawing at that point. Execute the following line.
H = ({ {0, 0, 1, 4, 4, 0}, {0, 3, 4, 3, 0, 0} })
To graph the house matrix, we will use the Point2D command found in the sccc package. Alternatively, you could work with Mathematica's built-in ListPlot command.
Note that both the Point2D and ListPlot commands require that the matrix be in a form where the rows correspond to the corner points. We can "flip" the rows and columns of the house matrix using Mathematica's Transpose command. Execute the line below to see both the house matrix and its transpose. H = ({ {0, 0, 1, 4, 4, 0}, {0, 3, 4, 3, 0, 0} }) Transpose[H] Execute the line below to get a picture of the house created with the Plot2D command. Notice that we are plotting the transpose of the house matrix. Also, we leave off labeling any corner points so that the plot is cleaner.
Point2D[Transpose[H], Joined -> True, Color -> Blue, LineColor -> Blue]
We are ready to manipulate the house image. Recall that the standard matrix A for the dilation transformation T(x)=3x is given by A = (3 0 0 3 ). If we multiply the house matrix on the left by matrix A, the resulting matrix will be the dilated corner points of the house. Execute below: A = ({ {3, 0}, {0, 3} }) A.H To graph the dilated house (matrix AH), recall that we need to plot the transpose of the matrix AH. We'll also make the color Red.
Point2D[Transpose[A.H], Joined -> True, Color -> Red, LineColor -> Red]
To compare the original and transformed house images, execute the cell below. original = Point2D[Transpose[H], Joined -> True, Color -> Blue, LineColor -> Blue]; dilate = Point2D[Transpose[A.H], Joined -> True, Color -> Red, LineColor -> Red]; Show[{original, dilate}, PlotRange -> All]
Exercise 1: In the space below, set up a 2x2 matrix R that will rotate points in the plane by 45 degrees counterclockwise. R = ( { {\[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder]} } ) Multiply the house matrix H on the left by R in the space below: The following lines are almost ready. Fill in what is missing to plot both the house and a rotated house. original = Point2D[ , Joined -> True, Color -> Blue, LineColor -> Blue]; rotate = Point2D[ , Joined -> True, Color -> Red, LineColor -> Red]; Show[{original, rotate}, PlotRange -> All]
Exercise 2: Define your own figure as follows: Pick three points from quadrants I and II that are the vertices of any triangle. Then form the 2*4 matrix that has these points as its columns (the final column being a repeat of the first column). Call this matrix by the name "tri". tri = ( { {\[Placeholder], \[Placeholder], \[Placeholder], \[Placeholder]}, {\[Placeholder], \[Placeholder], \[Placeholder], \[Placeholder]} } ) Use the Point2D command to draw the triangle in Blue: Create and apply a 2x2 matrix that will reflect your triangle over the x-axis. Show the reflected triangle in Red. Show all work clearly below. You may have noticed there is one basic geometric transformation that we have not come across in the textbook: translation or simply moving all points by the same translation vector Overscript[p, \[RightVector]]. Suppose we wanted to shift the house given in matrix H two units to the right and three units up: this would require that each column vector in H be added to the vector Overscript[p, \[RightVector]] = (2 3 ). There is no way to do this kind of vector addition using a matrix-vector multiplication (try it!). To get around this, computer graphics people have created a new coordinate system called homogeneous coordinates. Each point in R^2 is re-written as a 3-tuple (x,y,1), where the third "coordinate" is always one. This creates a 3 element column vector for each point in R^2. When this change is made to all the points, we must also alter our original 2 by 2 matrix transformation to a 3 by 3 matrix. This is easily done by putting the elements of the original 2 by 2 matrix in the upper left part of the 3 by 3 matrix. We then fill the remaining third column and row with zeros EXCEPT the element Subscript[a, 33] which is filled with a 1. For example, the matrix in R^2 which rotates a point 45\[Degree] counter-clockwise about the origin is A = (Sqrt[2]/2 -Sqrt[2]/2 Sqrt[2]/2 Sqrt[2]/2 ). Using homogeneous coordinates, the new transfomation matrix is Subscript[A, h] = (Sqrt[2]/2 -Sqrt[2]/2 0 Sqrt[2]/2 Sqrt[2]/2 0 0 0 1 ). So if we want to rotate the point (2,2), we would first enter the following point and transformation in Mathematica: pth = {2, 2, 1} Ah = \!\(TraditionalForm\`\((\*GridBox[{ { FractionBox[ SqrtBox["2"], "2"], FractionBox[ RowBox[{"-", SqrtBox["2"]}], "2"], 0}, { FractionBox[ SqrtBox["2"], "2"], FractionBox[ SqrtBox["2"], "2"], 0}, {0, 0, 1} }])\)\) Then we compute the matrix-vector multiplication: Ah.pth The new point coordinates after the rotation are then (0,2Sqrt[2]). We just ignore the third coordinate of 1. You can also use the Mathematica command Take to pull out only the first two elements (rows) of the the 3 element vector. Take[Ah.pth, {1, 2}]
Exercise 3: Create the homogeneous coordinate equivalent of a matrix that projects a point in R^2 onto the y=x line. Then use your new transformation on the point (-3,4). Now finally back to the issue of translation. If we want to shift a point h units to the right and k units up in R^2, we create the transformation in homogeneous coordinates Subscript[A, h] = (1 0 h 0 1 k 0 0 1 ). To check that this will take a point (-1,4) and translate two units to the right and 3 units up, execute the following: pth = {-1, 4, 1}; Ah = \!\(TraditionalForm\`\((\*GridBox[{ {1, 0, 2}, {0, 1, 3}, {0, 0, 1} }])\)\); Take[Ah.pth, {1, 2}]
Exercise 4: Take the house given by matrix H and translate it 3 units to the left and 1 unit up. This will mean you have to first replace H with a matrix that contains the new homogeneous coordinates for the house! Then graph it and check your results. HINT: You will need to use the Take command on your resultant matrix of points to remove the last row of ones before plotting.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
