Math 236  • 30 January 2001

A First Look at Mathematica:
Transformations of the plane

This notebook provides some utilities useful in visualizing transformations of the plane.  Some examples illustrate how to use these utilities.

Transformations and objects for examples

We shall use a triangle as an example.  First we form the list pairs of pairs of coordinates of its vertices and the Line (that is, broken line) primitive graphics object:

pairs  =  {{-1, 1 },  {0.25,  -1},  {0.75,  
            0.65}, {-1, 1 } };
edges  =  Line[pairs]

To see the triangle's three edges, form a Graphics object...

Graphics[edges]

... and then Show that Graphics object:

Show[Graphics[edges]];

The triangle's vertices will constitute a list of Point primitive graphics objects:

vertices  =  Map[Point,  pairs]

Here's the edges and vertices together...

Show[Graphics[{edges,  vertices}]];

... but it's rather hard to see the vertices because they are so small.  So we enlarge the points by using the PointSize graphics directive.  (The parameter to PointSize is expressed as a fraction of the graphics image width.)

triangle  =  {edges, PointSize[0.025],  vertices}

Now we can see vertices as well as edges:

Show[Graphics[triangle]];

Below we'll use two transformations of the plane—reflection across the vertical axis and translation by the vector (1,  2):

reflect[
        p_]  :=    {-p[[1]],  
        p[[2]]}
translate[p_]  :=  p  +  {1, 2}

For example:

reflect[{ 0.75,  0.65}]

translate[ {0.75,  0.65}]

Graphics utility "view"

We define two functions:
•  The function makeFigure forms a graphics object and associates some display options with it.
•  The function view simply displays the result of evaluating makeFigure.
You now know what these functions do.  But you do not need to know today how they do it!

\(makeFigure[objects_, \ low_:\  - 1, \ high_:  1]\  := \ 	
	
      Graphics[objects, \ 
        PlotRange\  -> \ {{low, \ high}, \ {low, \ 
              high}}, 
		\ AspectRatio\  -> \ Automatic, \ 
        Axes\  -> \ True]
\)
view[objects_,  low_:  - 1,  high_:  1]  :=  
      Show[makeFigure[objects,  low,  high]]

Example:

view[triangle];

The functions both allow optional second and third arguments to specify the lower and upper bounds of the plot window.  For example:

view[triangle,  -2,  2];

To enlarge or shrink the graphics display:
	•  Click once inside the display's cell.  A bounding box will be shown and "handles" will appear around the bounding box.
	•  Click on one of the handles and drag it to change the image size.
	•  Click anywhere outside the display cell or else double-click inside the cell.

Transformation  utility "image"

We define two functions:
•  The function Point2DQ tests whether its argument is a list of two numbers.
•  The function image applies its first argument T (intended to be a plane transformation) to all the points of the objects constituting its second argument.
You now know what these functions do.  But you do not need to to understand today how they do it!  Just notice, though, the economy of programming here.

\(Point2DQ[p_] := 
      VectorQ[p, NumericQ] && \(\(Length[p]\)\(==\)\(2\)\(
\)\)\)
image[T_,  object_]  :=  
      object  /.  pt_?Point2DQ  :>  T[pt]

Here's our example again...

triangle

... and its image under the transformation reflect:

image[reflect,  triangle]

view[image[reflect,  triangle]];

Log[2,  32]

2 ~Log~ 32

reflect~image~triangle

view[reflect~image~triangle];

You can see both the original object and its image on the same axes:

view[{triangle,  image[reflect,  triangle]}];

And you can make it easier to distinguish the original from the image by using color:

view[{triangle,  RGBColor[1, 0, 0], 
          image[reflect,  triangle]}];

Some advanced techniques (skip on first look)

To see several graphics objects at the same time, form a GraphicsArray.  For example, here's both our triangle and its reflected image:

Show[
        GraphicsArray[{Graphics[triangle],  
            Graphics[image[reflect,  triangle]]}]];

If you want to see a plane object and its image at the same time but on different axes, use the following utility:

\(viewAndImage[objects_, \ T_, \ low_:\  - 1, \ high_:  1]\  := 
	
      Show[GraphicsArray[
			{makeFigure[objects, \ low, \ high], \ 
            makeFigure[T\ ~image~\ objects, \ low, \ 
              high]}
		]]\)

viewAndImage[triangle,  reflect];

To see a better picture, use the method for enlarging the display described above.

Images under composition of transformations

To get the image of an object under the composition of two (or more) transformations, just apply the transformations in order.  For example:

stretch[v_]  :=  0.6 v

stretch[{1,  2}]
reflect[%]                              
reflect[stretch[{1, 2}]]

The expression for applying first one transformation, then the other, gets a bit complicated when it is used with the function image:

view[image[stretch,  image[reflect, triangle]],  -2,  
        2];

A way to simplify expressions such as in the preceding input cell is explained in the next section.

Composition notation ∘

The Notation package allows us to use the symbol ∘ to denote function composition, just as in traditional mathematical notation.

Needs["Utilities`Notation`"]

InfixNotation[∘,Composition]

Did you notice that after loading the Notation package, a small "NotationPalette.nb" window popped up on-screen?  You can close that window now by clicking its corner.

You use ∘ to compose transformations in Mathematica in exactly the same way as in our mathematical notation.  For example:

(reflect∘ stretch)[{1, 2}]

view[image[stretch ∘ reflect, triangle],  -2,  
        2];