The Journal of Online Mathematics and Its Applications, Volume 7 (2007)
Experiments with Matrices and Vectors in Calculus and Linear Algebra, Sulewski, Kobylski, and Wattenberg

Sample Curriculum Materials

Lesson 34: Matrix Applications IV: Animations

Vectors and matrices are often used to manipulate images and create special effects on television and in movies like Harry Potter and Star Wars. By the end of this section you will be able to produce animations and other special effects involving moving, magnifying, shrinking, and rotating images. The key to all of this is representing each point in an original image by a column-vector:

\vec x = \left[{\begin{array}{c}x_1 \\ x_2 \\ \end{array}}\right]

and each location on a television, movie or computer screen by a column-vector:

\vec y = \left[{\begin{array}{c}y_1 \\ y_2 \\ \end{array}}\right]

Then each point, \vec x, from the original image is placed at the location \vec y = A \vec x + \vec b, on the computer screen where A is a matrix

A = \left[{\begin{array}{cc}a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array}}\right]

and \vec b is a column vector

\vec b = \left[{\begin{array}{c}b_1 \\ b_2 \\ \end{array}}\right].

Notice that we can write this as

\vec y = A \vec x + \vec b \quad \quad {\rm or} \quad \quad \left[{\begin{array}{c}y_1 \\ y_2 \\ \end{array}}\right] = \left[{\begin{array}{cc}a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array}}\right] \left[{\begin{array}{c} x_1 \\ x_2 \\ \end{array}}\right] + \left[{\begin{array}{c}b_1 \\ b_2 \\ \end{array}}\right] \quad \quad {\rm or} \quad \quad \begin{eqnarray} y_1 &=& a_{11} x_1 + a_{12} x_2 + b_1\\ y_2 &=& a_{21}x_1 + a_{22} x_2 + b_2\\ \end{eqnarray}.

We begin by looking at an example in which

\vec b = \left[{\begin{array}{c}0 \\ 0 \\ \end{array}}\right],

so that

\vec y = A \vec x \quad \quad {\rm or} \quad \quad \left[{\begin{array}{c}y_1 \\ y_2 \\ \end{array}}\right] = \left[{\begin{array}{cc}a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array}}\right] \left[{\begin{array}{c} x_1 \\ x_2 \\ \end{array}}\right] \quad \quad {\rm or} \quad \quad \begin{eqnarray} y_1 &=& a_{11} x_1 + a_{12} x_2\\ y_2 &=& a_{21}x_1 + a_{22} x_2\\ \end{eqnarray}.

Open the OSSLET that you will be using in this lesson. Don't click any of the buttons in this live window yet but you may want to resize the live window and arrange your desktop so that you can move easily back-and-forth between this window and the live window as you do this section. The live window shows an example using the matrix

A = \left[{\begin{array}{rr} 1 & 0 \\ 0 & -1\\ \end{array}}\right],

so that

\begin{eqnarray} y_1 &=& x_1\\ y_2 &=& - x_2\\ \end{eqnarray}.

Thus the x-coordinate (the first coordinate), denoted x_1, of a point in the original image is unchanged on the screen and the y-coordinate (the second coordinate), denoted y_2, of a point in the original image is multiplied by -1 before it is placed on the screen. In effect, this flips the original image upside-down. Click the green Play button in the live window to see this effect. Notice that the entries of the matrix A above appear in the upper left area of the live window in the areas highlighted in pink. If you want to see this example again, click the reload button in the browser's toolbar for the live window and then click the Play button in the window again.

For a glimpse into the kinds of things you will be able to do by the end of this lesson, click the Example 2 button in the upper right area of the live window and then click the Play button. Notice that only the Black Knight in the lower left part of the window moves. The other Black Knight is controlled by the matrix shown in upper left section of the window. This matrix is the identity matrix because we don't want to give away the way this animation is done. By the end of this section you will be able to fill in the entries in this matrix (and in the vector \vec b) to reproduce this example and many other effects in the lower right area of the window. Don't close the live window. You will be using it again.

To produce different effects, we need to know a bit more about how the image manipulation

\left[{\begin{array}{c}y_1 \\ y_2 \\ \end{array}}\right] = \left[{\begin{array}{cc} a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array}}\right] \left[{\begin{array}{c}x_1 \\ x_2 \\ \end{array}}\right]

affects the location at the point \vec y on your computer screen of each point \vec x in the original image. First, notice that these image manipulations always leave the point (0, 0) unchanged since \vec b = (0, 0). Two additional good points to look at from the original image are the points (1, 0) and (0, 1), which we write as column-vectors

\left[{\begin{array}{c}1 \\ 0 \\ \end{array}}\right] \quad {\rm and } \quad \left[{\begin{array}{c} 0 \\ 1 \\ \end{array}}\right] .

Notice that

\left[{\begin{array}{cc} a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array}}\right] \left[{\begin{array}{c}1 \\ 0 \\ \end{array}}\right] = \left[{\begin{array}{c} a_{11} \\ a_{21} \\ \end{array}}\right].

So, whatever part of the original image is located at the point (1, 0) is placed at the location given by the first column of the matrix A in the new image. Similarly,

\left[{\begin{array}{cc} a_{11} & a_{12} \\ a_{21} & a_{22} \\ \end{array}}\right] \left[{\begin{array}{c} 0 \\ 1 \\ \end{array}}\right] = \left[{\begin{array}{c} a_{12} \\ a_{22} \\ \end{array}}\right].

So whatever part of the original image is located at the point (0, 1) is placed at the location given by the second column of the matrix A in the new image.

Example

Click the Example 3 button in the live window. You should see the original image of the Black Knight in the lower right area. In the lower left area you should see the Black Knight rotated counterclockwise by 30^{\circ} = \pi/6 \ {\rm radians}. Before going on to the next page try to determine the matrix A that would accomplish this rotation. Begin by determining the location on the screen of each of the image points (0, 1) and (1, 0). You can check your work by changing the entries of the matrix A in the pink areas in the upper left area of the live window and then pressing the Play button to see if you have successfully reproduced in the lower right the rotation seen in the lower left area of the live window.