c4s5shortb.mw

Computer Graphics -- Adapted from a Visual Linear Algebra (VLA) Module by Eugene A. Herman and Michael D. Pepe 

> with(LinearAlgebra): with(plots):
 

 

Example 1: The plot below shows a red triangle with vertices (4, 3), (4, 9), and (6, 3) that has been translated up and to the right. 

Plot_2d 

Our red triangle above can be represented using homogeneous coordinates by the matrix "triangle":  

> triangle := Matrix([[4,4,6,4],[3,9,3,3],[1,1,1,1]]);
 

Matrix(%id = 18446744078096937678)
 

Our translation can be represented in homogenous coordinates by the translation matrix which takes each vertex Vector[column](%id = 18446744078096937438) to it's translated point (up and to the right by the vector Vector[column](%id = 18446744078096938038)): 

> translation:=Matrix([[1,0,3],[0,1,2],[0,0,1]]);
 

Matrix(%id = 18446744078096937798) (1.1)
 

> translation.triangle;
 

Matrix(%id = 18446744078096937918) (1.2)
 

Example 2 :  Rotate the triangle figure counterclockwise 45 degrees about its top vertex, (4, 9). 

 

Solution:  We break the problem into the following three steps.  

 

 

 

Each of these steps is accomplished (see below)  by applying a matrix transformation in homogeneous coordinates. The product of the three matrices gives us a single matrix that accomplishes the desired rotation in one step. 

 

Step 1. Translate the triangle so the vertex (4, 9) is moved to the origin. We therefore translate the triangle by the vector Vector[column](%id = 18446744078096938158). 

> T := Matrix([[1, 0, -4], [0, 1, -9], [0, 0, 1]]);
 

T := Matrix(%id = 18446744078096953494)
 

> T.triangle;
 

Matrix(%id = 18446744078096953646)
 

Plot_2d
 

Step 2. Rotate the translated figure 45 degrees. Apply this rotation matrix R to the translated triangle, which we call "triangle1". 

> triangle1 := T.triangle;
 

triangle1 := Matrix(%id = 18446744078096953798)
 

> R := Matrix([[cos(Pi/4), -sin(Pi/4), 0], [sin(Pi/4), cos(Pi/4), 0], [0, 0, 1]]);
 

R := Matrix(%id = 18446744078096953950)
 

> R.triangle1;
 

Matrix(%id = 18446744078096954102)
 

Plot_2d
 

Step 3. Translate the figure so the top vertex is moved back from (0, 0) to (4, 9). Apply this translation matrix U to the rotated triangle, which we call "triangle2". (Note that the translation matrices T and U are inverses of one another.) 

> triangle2 := R.triangle1;
 

triangle2 := Matrix(%id = 18446744078096954254)
 

> U:=Matrix([[1, 0, 4], [0, 1, 9], [0, 0, 1]]);
 

U := Matrix(%id = 18446744078096954406)
 

> U.triangle2;
 

Matrix(%id = 18446744078096954558)
 

Plot_2d
 

Now we multiply all three matrices together (right to left, like functions) and thereby construct a single matrix that performs the rotation about the vertex (4, 9) with a single multiplication. 

> M := U.R.T;
 

M := Matrix(%id = 18446744078096954710)
 

> U.R.T.triangle;
 

Matrix(%id = 18446744078096954862)
 

Plot_2d
 

==================== 

Making Movies 

We can also apply the product matrix M repeatedly to create a simple animation:  Here is a movie created by 20 frames of applying M: 

Plot_2d
 

Careful of the order - if I do T.R.U instead of U.R.T, we get 

Plot_2d 

 

Example 3: Homogeneous Coordinate Transformations in 3-space 

We define the homogeneous coordinates for a point Vector[column](%id = 18446744078096938398) in `*`(`^`(R, 3)) to be Vector[column](%id = 18446744078096938638).  The geometric transformations of `*`(`^`(R, 3)) are then represented by 4 by 4 matrices.  For example, here are transformations side by side with their homogeneous versions. Notice that, in each pair, the original transformation makes up the 3 by 3 block in the upper-left corner of the 4 by 4 matrix. The rest of the matrix is filled out with zeros, except for a 1 in the lower-right corner.  What is the effect of each transformation in `*`(`^`(R, 3))? 

 

        Matrix(%id = 18446744078099939326)       Matrix(%id = 18446744078099939446)                   Matrix(%id = 18446744078099939566)       Matrix(%id = 18446744078099939686)                         

 

We can also create homogeneous rotation matrices for `*`(`^`(R, 3)): 

> Matrix([[cos(theta), -sin(theta), 0, 0], [sin(theta), cos(theta), 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]);
 

Matrix(%id = 18446744078096955014)
 

This is no longer a rotation about the origin since this is not possible in `*`(`^`(R, 3)): instead we rotate about the z-axis.   

=================== 

Example 4: Let's rotate a 3-D figure by 30 degrees about the z axis. 

> Rz := Matrix([[cos(Pi/6), -sin(Pi/6), 0, 0], [sin(Pi/6), cos(Pi/6), 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]);
 

Rz := Matrix(%id = 18446744078096955166)
 

Plot_2d 

Next, let's see what happens when this rotation is applied 12 times: 

Plot_2d
 

================== 

Example 5: Explore ~~ Here is an animation based on a composition of two matrices. Can you predict what the animation will look like before running it?  

> T := Matrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 1], [0, 0, 0, 1]]);
 

T := Matrix(%id = 18446744078096955318)
 

> Rz := Matrix([[cos(Pi/6), -sin(Pi/6), 0, 0], [sin(Pi/6), cos(Pi/6), 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]);
 

Rz := Matrix(%id = 18446744078096955470)
 

> M := Rz.T;
 

M := Matrix(%id = 18446744078096955622)
 

24 frames: 

Plot_2d