Linear Transformations on the Plane

A linear transformation on the plane is a function of the form  T(x,y) = (ax + by, cx + dy) where a,b,c and d are real numbers.  If we start with a figure in the xy-plane, then we can apply the function T to get a transformed figure.  It turns out that all linear transformations are built by combining simple geometric processes such as rotation, stretching, shrinking, shearing and projection.  As a consequence linear transformations are important in computer graphics.   If for example we need to represent a 3-dimensional object on a 2-dimensional computer screen and we want to look at the object from various angles, then projections and rotations come into play.  Motion effects can be achieved as well;  as a simple example,  shrinking an object will make it appear to move away from the viewer.   Linear transformations and matrices are also an important tool if we want to control the motion of a robot.  In both these applications we probably need three dimensional transformations and translations as well.  That is, we may want to have our robot walk across the room or we may want to slide a figure to a new position on the computer screen.  Translation is not a linear transformation, but there is a simple and useful trick that allows us to treat it as one (see Exercise 9 below).

This geometric point of view is obviously useful when we want to model the motion or changes in shape of an object moving in the plane or in 3-space.  However, it is useful in higher dimensions as well.  The idea that any matrix can be thought of as the product of simpler matrices that correspond to higher dimensional versions of rotation, reflection, projection, shearing, dilation and contraction is of enormous importance to both pure and applied mathematicians.
 

Linear Maps take Parallelograms to Parallelograms

In this assignment we learn how to draw simple plane figures in MATLAB and their transformations by various linear transformations.  We will use the fact that linear transformations map parallelograms to (possibly degenerate) parallelograms.  Closely related is the fact that if a parallelogram has vertices at the points P_1, P_2, P_3 and P_4 then the linear transformation T will take it to a new parallelogram whose vertices are the points T(P_1), T(P_2), T(P_3) and T(P_4).  Thus for example, if we start with the parallelogram whose vertices are
                (1,2), (3,3), (4,4) and (2,3)
then the linear transformation T(x,y) = (x - y, x + y) will transform it to a parallelogram with vertices at
                (-1,3), (0,6), (0,8) and (-1,5)
The mathematical justification for this is quite simple.  Skipping a few details, since any parallelogram in the plane can be described simply in terms of vector sums and scalar multiples and since linear transformations "preserve" vector sums and scalar multiples, the image of the parallelogram must be a new parallelogram (or a line segment or a point).

Exercise 1:  In general a parallelogram in the plane can be described using vectors.  The collection of all points of the form

p + au + bv  |  0  < a  < 1 and 0 < b < 1 }

(where p, u and v are vectors and a and b are scalars) will be a parallelogram with vertices at  the points p, p + u, p + u + v, and p + v.  Find p, u and v for the parallelogram P with vertices at (1,2), (3,3), (4,4), (2,3) -- note that there are four ways to do this.    If T is a linear transformation defined by T(x) = Ax, where A is a 2 x 2 matrix, then show that the image T(P) is also a parallelogram by finding its vector description.  Show that the vertices of the transformed parallelogram are found by transforming the vertices of the original parallelogram P.
 

Graphing Figures in MATLAB

The basic MATLAB command for producing a graph  is plot and in the exercises and examples below you will learn a few of the many options available to customize the kind of figure it produces.   (At a later point you may wish to look at the various plotting options in the MATLAB help files.  In other words,  you may wish to check out the function plot at the help desk.)

A common use of plot is to take a list of data points and graph them, connecting them with straight line segments.  For example,

     >> plot( [ 1, 3, 4, 2, 1 ], [ 2, 3, 4, 3, 2 ] )
pairs up each number in the first list with the corresponding number in the second list to get the data points (1,2), (3,3), (4,4), (2,3) and (1,2) again.  The command above will thus produce a graph of the parallelogram P with these points as vertices.  We can adjust the axes so that the parallelogram does not fill the entire plot window with a command like
     >> axis( [ -8, 8, -8, 8 ])
And the command below forces MATLAB to use the same scale on the vertical and horizontal axes.
     >> axis equal
Consider the linear map defined by (u,v) = (x - y, x + y).  Next we want to make a plot that will contain one copy of the plane using the usual x and y coordinate and another copy of the plane where we will call the horizontal coordinate u and the vertical coordinate v.  In the xy-plane we will draw the parallelogram P and in the uv-plane we will draw its transformation under the given linear map.
The MATLAB command subplot lets us make an m x n array of plots all in the same window.  In this case we will make two plots side-by-side.    First we compute the vertex points for the transformed parallelogram:
     >> x = [ 1, 3, 4, 2, 1 ]
     >> y = [ 2, 3, 4, 3, 2 ]
     >> u = x - y
     >> v = x + y
Next we build the plots:
     >> subplot(1,2,1), plot(x,y), xlabel('x'), ylabel('y'), axis([-8,8,-8,8]),...
                   axis equal, title('The original parallelogram')
     >> subplot(1,2,2), plot(u,v), xlabel('u'), ylabel('v'), axis([-8,8,-8,8]),...
                   axis equal, title('The transformed parallelogram')
Since we want an array of plots with one row and two columns we start with subplot(1,2,..).  When we are ready to give the details of the first plot we use subplot(1,2,1) and for the second plot we use subplot(1,2,2).   In the first plot the horizontal axis is labeled x, the vertical axis is labeled y and the whole plot is in a window where x runs from -8 to 8 and so does y.   There are further details to specify but we are out of room on this line.  The three dots at the end allow us to continue the command on the next line.  We force MATLAB to use the same scale on the vertical and horizontal axes and we give the plot a descriptive title.   The second plot is very similar.

The geometric effect of the transformation (u,v) = (x + y, x - y) is clearer if we look at how the unit square transforms.    It also helps to look at what happens when we apply the same transformation repeatedly.  To make this easier we will use matrices.  We begin as before by setting up a vectors x and y that correspond to the vertices of the unit square:

     >> x = [ 0, 1, 1, 0, 0 ]     % S has vertices at (0,0), (1,0), (1,1) and (0,1)
     >> y = [ 0, 0, 1, 1, 0 ]     % we list them in the order we want to connect them
Now instead of simply working with x and y as we did above, it is easier in the long run if we make a matrix S whose columns contain the vertices of the square.  In other words, our vector x will be the first row of S and the vector y will be the second row:
     >> S = [x;y]
     >> plot(S(1,:), S(2,:))      % has the same effect as plot(x,y)
     >> axis equal, axis([-2,2,-2,2])
Since the vertices of the square are now listed as the columns of the matrix S, we can easily transform them.  We just define the coefficient matrix for our transformation, in this case:
     >> A = [ 1 -1; 1  1]         % sends a vector (x,y) to (x-y,x+y)
and then multiply:
     >> T1 = A*S
     >> plot(S(1,:), S(2,:), T1(1,:), T1(2,:)), ...
           axis equal, axis([-2,2,-2,2])          % to plot the square with its transform
We can then transform further if we wish:
     >> T2 = A*T1
     >> plot(S(1,:), S(2,:), T1(1,:), T1(2,:), T2(1,:), T2(2,:)),...
             axis equal, axis([-3,3,-3,3])

Transforming a Disk

Sometimes it is useful to look at what a transformation does to the unit disk instead.  Let's see how to get MATLAB to draw the pictures.  We can think of the disk as all points bounded by the curve (cos t, sin t) as t runs from 0 to 2pi.  The colon operator allows us to pick evenly spaced values of t in that interval.  In this case, let t run from 0 to 6.3 in steps of length 0.1.  We don't want to see this big list of numbers so we end the command with a semicolon.  This tells MATLAB not to print its results.  The commands below allow us to plot the disk and its transform together on the same set of axes.
     >> t = 0:0.1:6.3;
     >> x = cos(t);
     >> y = sin(t);
     >> D = [x;y];
     >> A = [1 -1; 1 1];
     >> T1 = A*D;
     >> plot( D(1,:), D(2,:), T1(1,:), T1(2,:) ), ...
               axis equal, axis([-2,2,-2,2])


NOTE:  Be sure to use the plotting option axis equal in the exercises below.  This ensures that your disks will be round, not elliptical.  Typically, the transformed disk will be elliptical and you want to get a true picture of how the disk changed under the linear transformation.

Exercise 2:  Let S be the unit square and let T be the transformation T(x,y) = (x - y, x + y) as discussed in the examples above.  Plot S, T(S), T(T(S)), and T(T(T(S))) together on the same coordinate axes.  Label each figure and summarize your results - that is, explain the geometric effect of the transformation T as clearly as you can.

Exercise 3:  Consider the linear transformation defined by T(x,y) = (0.8x, 1.4y).   What is the geometric effect of this transformation?  Plot the disk D together with its transform T(D).  Also include the figure you get by applying T to D five times.  Label each of the three figures by hand or using the menu bars in your MATLAB plot window to add text to your plot.  Again, be sure to use the axis equal option so that disks look like disks, not ellipses.  What will the limit figure look like if we continue transforming by T forever?

Exercise 4:  Consider the linear transformation defined by T(x,y) = (2x+y, x +y).

Exercise 5:  Consider now a sequence of linear transformations.  Start by rotating a vector x counterclockwise through an angle of 15 degrees.  Recall from class that the matrix for such a rotation is
                R = [ cos(15 degrees)   - sin(15 degrees) ]
                    [ sin(15 degrees)     cos(15 degrees) ]
Don't forget that the cosine and sine functions in MATLAB are set up under the assumption that you work in radians.
After you rotate, then transform by  (x,y) -> (0.8x, 1.4y) as in Exercise 3.  Finally, rotate clockwise through 15 degrees. Exercise 6:  (continuation of exercises 4 and 5)   The transformations you worked with in exercises 4 and 5 were quite similar.   In both cases the original disk was transformed into an ellipse. Exercise 7:  Consider the linear transformation defined by T(x,y) = (1.0347 x - 0.1008y, 0.1548 x + 1.0150y).  What is the geometric effect of this transformation?  What does it do to the unit disk?  Attach supporting plots.  Can you explain in terms of some combination of rotations, reflections, stretching, shearing etc. as discussed in class.

Exercise 8:  Consider the basic shearing transformation (x,y) -> (x + y, y).  As we discussed in class, this is a shear parallel to the horizontal axis.  What happens if we consider the following sequence of transformations?  If we first rotate by 45 degrees the horizontal axis moves into the line y = x.  Then apply the shear (x,y) -> (x+y,y).  Finally, rotate in the opposite direction by 45 degrees.  What is the combined geometric effect and what is the matrix of the resulting transformation?

Exercise 9:   A translation is a particularly simple kind of transformation -- for example, a map of the form (x,y) -> (x  + 2,  y -3) takes any figure and  slides it right by 2 and down by 3.   This is not a linear transformation since it cannot be expressed as a matrix A times the vector (x,y).   We can use a simple trick called homogeneous coordinates to get around this difficulty if we want to combine translations with rotations or other linear transformations.  We simply use (x,y,1) instead of (x,y) to talk about points in the plane.  With this change of coordinate system, the translation above becomes (x,y,1) maps to (x + 2, y + 3, 1) and this we can describe this using matrix multiplication:
 

                   [  1   0   2 ]   [ x ]       [ x + 2 ]
                   [  0   1   3 ] * [ y ]   =   [ y + 3 ]
                   [  0   0   1 ]   [ 1 ]       [   1   ]
Rotation through an angle t can easily be translated into these coordinates as well:
                   [ cos t   -sin t   0 ]   [ x ]      [ x*cos t - y*sin t ]
                   [ sin t    cos t   0 ] * [ y ]  =   [ x*sin t + y*cos t ]
                   [   0        0     1 ]   [ 1 ]      [         1         ]
Multiplying these 3 x 3 matrices corresponds to composing these transformations on the plane.  Find the matrix for reflection across the line y = x followed by translation by the vector (3,4).