Math 236  • 30 January 2001

Graphing and image utilities

⚠  When you open this notebook, you will be asked whether to evaluate its initialization cells.  You should answer "yes".  Then:

(1)  the package Graphics`Colors` will automatically be loaded and will make color names available;
(2)  the utility functions view and image will automatically be defined;
(3)  the small circle ( ∘ ) notation will automatically be enabled to mean composition; and
(4)  a "NotationPalette.nb" window will pop up on-screen (you may close that palette window after you see it.)

If you do not answer "yes", then you will need to evaluate manually the input cells in the Definitions subsections in the closed cell groups below.

Description

This notebook defines two main functions: 

	view		Displays 2D graphics objects
	image		Calculates images of objects under transformations of the plane
	
For examples of how each of these functions is used, see the closed Examples subsections of the first two sections below.  For a quick reminder of the usage, type and evaluate  ?view  or  ?image .

This notebook also assigns the meaning of function composition to the symbol ∘.  To see how to use this notation, see the closed Examples subsection of the section "Composition notation ∘" below.

Finally, this notebook loads the Standard Add-On package Graphics`Colors`, which makes many color names available directly, without your having to use the RGBColor built-in function to create these colors.

Colors

The following cell loads the package Graphics`Colors` (unless it is already loaded).

Needs["Graphics`Colors`"]

To see what color names are now defined, evaluate the following cell:

Names["Graphics`Colors`*"]

Graphing objects with the function view

Definitions

\(\(\(view::usage\  = \ 
		"view[objs] displays the 2D graphics objects in the list objs

		with both axes running from -1 to 1.

		view[objs, lo, hi] displays the objects with both axes running from lo to hi. ";\)\(
\)
    \)\)
\(\(\(view[objects_, \ low_:\  - 1, \ high_:  1]\  := \ 
      Show[makeFigure[objects, \ low, \ high]]\)\(
\)
    \)\)
\(makeFigure[objects_, \ low_:\  - 1, \ high_:  1]\  := \ 	
	
      Graphics[objects, \ 
        PlotRange\  -> \ {{low, \ high}, \ {low, \ 
              high}}, 
		\ AspectRatio\  -> \ Automatic, \ 
        Axes\  -> \ True]\)

Examples

view[{PointSize[0.02],  Point[{0.75, 0.25}]}];

vee  =  Line[{{-1, 1}, {0, 0}, {1, 1}}];
triangle  =  
        Line[{{-2, -2}, {-1, -1}, {0, -2}, {-2, -2}}];
circ  =  
        Line[Table[{5 + 2 Sin[θ], 5 + 2 Cos[θ]}, {θ, 
              0, 2 π, 0.025}]];
view[vee];
view[vee,  -5,  5];
view[{triangle,  circ},  -10,  10];
view[{RGBColor[1, 0, 0],  triangle,  RGBColor[1, 0, 1],  
          circ},  -10,  10];

Instead of using the built-in function RGBColor directly as above, you may use color names provided by the package Graphics`Color`, which was automatically loaded when you agreed to have Mathematica evaluate the initialization cells in this notebook.

view[{Red,  triangle,  Purple,  circ},  -10,  
        10];

For more examples, see notebook FirstLook.nb.

The transformation utility function image

Definitions

\(\(\(image::usage\  = \ 
		"image[T, objs] evaluates the plane transformation T

		at all the points of the object or list of objects objs.";\)\(
\)
    \)\)
\(image[T_, \ objects_]\  := \ 
      objects\  /. \ \(\(pt_?Point2DQ\  :> \ T[pt]\)\(
\)
        \)\)
Point2DQ[p_] := VectorQ[p, NumericQ]  &&  Length[p] == 2

Examples

translate[pt_] := {pt[[1]] + 2, 
        pt[[2]] + 3}

triangle  =  
        Line[{{-2, -2}, {-1, -1}, {0, -2}, {-2, -2}}];

Image of the triangle under translate:

image[translate,  triangle]

view[image[translate,  triangle],  -3,  3];

Both the original and the translated triangles:

view[{triangle,  image[translate,  triangle]},  -3,  
        3];

Use colors to indicate which is which:

\(\(view[{Red, \ triangle, \ 
		Blue, \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

Or, for printing purposes, use dashing, line thickness, or levels of gray to indicate which is which:

\(\(view[{triangle, \ 
		Thickness[0.008], \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

\(\(view[{triangle, \ 
		Dashing[{0.03, \ 0.01}], \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

\(\(view[{triangle, \ 
		GrayLevel[0.6], \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

Note that the higher the argument to GrayLevel, the lighter the image:

\(\(view[{triangle, \ 
		GrayLevel[0.8], \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

You may combine the graphics primitives specifying color, dashing, or gray level:

\(\(view[{triangle, \ 
		GrayLevel[0.6], \ Dashing[{0.03, \ 0.01}], \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

Notice that the directives are cumulative.  For example, if you give the color directive Green, then successive objects in the argument to view—no matter what their dashing or thickness, will all be green unless you change the color, too.

\(\(view[{Green, \ triangle, \ 
		Dashing[{0.03, \ 0.01}], \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

\(\(view[{Green, \ triangle, \ 
		Dashing[{0.03, \ 0.01}], \ Red, \ 
          image[translate, \ triangle]}, \ \(-3\), \ 3];\)\)

For more examples using image, see notebook FirstLook.nb.

Composition notation ∘

If you did not say "yes" to the question about evaluating all initialization cells when you opened this notebook, then you need to evaluate both input cells in the Definitions subsection below—in the order given—if you want to tell Mathematica to use the small circle ( ∘ ) notation to mean composition.

Definitions

\(\(\(Needs["Utilities`Notation`"]\)\(\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \)\( (*\ load\ package\ if\ needed\ *) \)\)\)

InfixNotation[∘,Composition]

If you didn't already do so, you may now close the "NotationPalette.nb" window that popped popped up on-screen.

Examples

To produce the character ∘ you type EscscEsc  (use lower-case s and c between the Escpaes; the mnemonic is: small circle).

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

reflect[
        v_]  :=    {-v[[1]],  
        v[[2]]}
shrink[v_]  :=  0.5 v
(reflect∘ shrink)[{1, 2}]
triangle  =  
        Line[{{-2, -2}, {-1, -1}, {0, -2}, {-2, -2}}];
view[triangle,  -2,  2];
view[image[reflect ∘ shrink, triangle],  -2,  
        2];

To see separately the original triangle, its image under the "inside" transformation shrink, and its image under the composite transformation reflect ∘ shrink, use different colors.  (Or, for printing purposes, use directives to change line thickness, dashing, or gray level—see the earlier examples.)

view[{triangle,  Green,  image[shrink,  triangle],  Red,  
          image[reflect ∘ shrink,  triangle]},  -2,  
        2];