Math 421  •  Fall 2006

Graphical objects in the complex plane:
Using David Park's Cardano3 application

Revised 20 September 2006

Original documentation written by David Parks, edited and amended by Murray Eisenberg

This notebook is for reference.  You may want to consult it before tackling the notebook nthRoots.nb.  The latter provides additional examples.

When you open this notebook, you should see a small pop-up window asking whether you want to evaluate the Initialization Cells.  You should select Yes.

Explanation:  In the section "The Cadano3 packages" below, there's an Input cell consisting of the expressions
	Needs["Cardano3`ComplexGraphics`"]
	Needs["Cardano3`ComplexRoutines`"]
and I made this cell into an "initialization cell".  When you answered yes, that cell was evaluated automatically, and this loaded the Cardano3 packages.

The Cardano3 packages

The following two add-on packages to Mathematica are part of the Cardano3 application writen by David Parks.  The Cardano3`ComplexGraphics` package contains many functions for creating graphical representations of complex objects.  The Cardano3`ComplexRoutines` package contains auxiliary routines that aid in complex analysis calculations.

To prepare to use these packages, evaluate the following cell.  It loads the two packages (unless they have already been loaded because you answered "yes" to the prompt when you opened this notebook), so that the definitions made in each package are available for use.

Needs["Cardano3`ComplexGraphics`"]
Needs["Cardano3`ComplexRoutines`"]

To obtain a complete list of the functions defined in these packages, evaluate:

?Cardano3`ComplexRoutines`*

?Cardano3`ComplexGraphics`*

To obtain information on any one of the names just listed, click the displayed link above.

Or type and evaluate a new ?name information request directly, for example:

?ComplexPoint

It is recommended that, whenever you load the Cardano3 packages, you also evaluate the following two expressions.  Doing so will suppress some annoying warning messages you'd otherwise see when you try to use similarly-named objects.

Off[General::spell]
Off[General::spell1]

Most other Math 421 notebooks that use these packages will include initialization cells that automatically evaluate those Needs and Off commands.  If you use these packages in your own notebooks, you may want to copy such initializations to your own and evaluate them there.

Forming ComplexGraphics objects

The basic method for plotting graphical objects with Mathematica is to use a Show[Graphics[{…}]] expression, and then include within it a set of commands that set the graphics directives to be used (such as color or line thickness) and then the graphics primitives that actually draw the objects (such as Point and Line).  In this way, you can build up a rather complicated graphic with complete control.

The ComplexGraphics package contains a number of complex primitives that mirror the regular Mathematica graphics primitives, but allow complex numbers to be used instead of real coordinate pairs.  For example, to construct the point 1  +  i in the complex plane, you may use…

ComplexPoint[1  +  I]

…which yields as a result a regular Mathematica Point graphics primitive expression.  And to construct the polygonal curve—the "broken line"—that goes from 0 to 1 to 1  +  i to i and back to 0, you may use...

ComplexLine[{0,  1,  1  +  I,  I,  
        0}]

…which yields as result a regular Mathematica Line graphics primitive expression.

The complex graphics primitives of this type that are provided are:  ComplexArrow, ComplexCircle, ComplexDisk, ComplexLine, ComplexPoint, ComplexPolygon, and ComplexText.  Also available is the graphics primitive ComplexCurve, which draws a curve in the complex plane that is parameterized by a real variable.

Displaying ComplexGraphics objects

A graphics primitive such as ComplexPoint[1 + i] or  ComplexLine[{0, 1, 1 + i, i, 0}] does not actually display the graphics.  To do that, use the function ComplexGraphics,  which is a shortcut substitute for Mathematica's Show[Graphics[{…}]] statement.  The ComplexGraphics function automatically sets new defaults for several overall plot options, such as drawing the axes in Gray and putting a frame around the entire plot.  (You may override any of these defaults.)

Let's plot a few simple complex objects using this method.  We will draw a blue point at 1 + i and then draw the complex line mentioned in the preceding paragraph. The commands below are broken into separate lines in order to show how we set the directives and draw one item after another.  The later items are drawn on top of the earlier items so the order of drawing is sometimes important.  Comments, enclosed in (* … *) pairs, have been included to make each action clear.  Such comments will not normally be included.

ComplexGraphics[
{ (* 
            Set color and point size for plotting point *) 
DodgerBlue, 
          PointSize[0.03], 
 (* 
            Draw point *) 
ComplexPoint[
            1  +  I], 
 (* 
            Set color for plotting line *) 
IndianRed, 
 (* 
            Plot line *) 
ComplexLine[{0,  1,  
              1  +  I,  I,  0}]}];

There are two ways to select a color:
	• By name:  If you don't already know the name you want, first evaluate:  ?Graphics`Colors`* to see what named colors are available.
	• From an actual color sample:  from the Files menu select Palettes and then select the DrawGraphicsPalette.  In your working notebook, put the cursor to the place in the ComplexGraphics expression where you want the color name to go.  Then click the desired color on the DrawGraphicsPalette.

(The palette is part of David Park's DrawGraphics package, which is automatically loaded when you load the ComplexAnalysis packages.)

Exercise.  The graphics objects in the preceding input expression with head ComplexGraphics are all in a list.  Experiment with the effects of:
	(a) changing the argument to PointSize;
	(b) changing the thickness of the polygonal line by using the Thickness function (try, for example, Thickness[0.01]); and
	(c) changing the colors of the point and line from DodgerBlue and IndianRed to some other attractive colors.

Including plot options

Now we add an overall plot option, ImageSize, at the end, after the brace-enclosed list that includes all the drawing commands. The ImageSize is specified in printer's points, and there are supposed to be 72 points to the inch.  (But that depends upon the details of your graphics display and the magnification of the notebook.)

ComplexGraphics[
{
DodgerBlue, 
        PointSize[0.03], 
ComplexPoint[
          1  +  I], 
IndianRed,  
        Thickness[
          0.01],  
ComplexLine[{0,  1,  
            1  +  I,  I,  
            0}]
}, 
ImageSize -> 
        72*4]

Plot options such as ImageSize allow you to control the overall "look" of the display.  The above display does not give a very good feel for the objects plotted.  Let's:
	• plot the line first and the point second, so that the point will be over the line;
	• use the PlotRange option to enlarge the plot "window", so that the objects may be seen in a larger view;
	• add coordinates and tick marks to the frame (ComplexGraphics normally suppresses them);
	• put a Honeydew color background behind the plot to better set it off from the rest of the notebook; and
	• add a plot label.

\(\(ComplexGraphics[
{IndianRed, \ 
          Thickness[
            0.01], 
ComplexLine[{0, \ 1, \ 
              1\  + \ I, \ I, \ 
              0}], 
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1\  + \ I]
}, 
FrameTicks -> 
          Automatic, 
PlotRange\  -> \ {{\(-1.51\), \ 
              1.5}, \ {\(-1.51\), \ 
              1.5}}, 
Background\  -> \ 
          Honeydew, 
PlotLabel\  -> \ "Point and Line in the Complex Plane", 
ImageSize\  -> \ 
          72*5];\)\)

That's beginning to look better.  But we're not done yet.

The PlotRange option specifies the "window" used for plotting.  To specify a window consisting of points z  =  x  +  y i with (Subscript[x, min])  ≤  x  ≤  
        (Subscript[x, max]) and (Subscript[y, min])  ≤  y  ≤  
        (Subscript[y, max]), use the form PlotRange -> { {(Subscript[x, min]), (Subscript[x, max])}, {(Subscript[y, min]), (Subscript[y, max])} }.

Exercise.  Copy below the preceding ComplexGraphics expression.  Change it so as to use a different window, a different background color, and a different label for the plot.

Annotating ComplexGraphics displays

To further annotate a complex graphics display, you may include text at any locations by invoking Park's function ComplexText.  This function is used in the form
	ComplexText[txt, z]
where the txt is the text you want to display and z is the complex number in the plane where (the center of) the text is to be displayed.

Let's enhance the same display as before but now also:
	• use a ComplexText statement to label the plane as the Complex Plane;
	• label the point.

\(\(ComplexGraphics[
{IndianRed, \ 
          Thickness[
            0.01], 
ComplexLine[{0, \ 1, \ 
              1\  + \ I, \ I, \ 
              0}], 
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1\  + \ I], 
Black, 
ComplexText["1 + I", \ 
            1.15\  + \ 
              1.15  I], 
DimGray, 
ComplexText[
            StyleForm["Complex Plane", \ 
              FontFamily\  -> \ "Helvetica", \ 
              FontSize\  -> \ 
                10], \ \(-0.75\)\  - \ I]
}, 
FrameTicks -> 
          Automatic, 
PlotRange\  -> \ {{\(-1.51\), \ 
              1.5}, \ {\(-1.51\), \ 
              1.5}}, 
Background\  -> \ 
          Honeydew, 
PlotLabel\  -> \ "Point and Line in the Complex Plane", 
ImageSize\  -> \ 
          72*5];\)\)

To typeset the label for the point in a traditional mathematical format, wrap the complex number with TraditionalForm:

\(\(ComplexGraphics[
{IndianRed, \ 
          Thickness[
            0.01], 
ComplexLine[{0, \ 1, \ 
              1\  + \ I, \ I, \ 
              0}], 
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1\  + \ I], 
Black, 
ComplexText[TraditionalForm[1\  + \ I], \ 
            1.15\  + \ 
              1.15  I], 
DimGray, 
ComplexText[
            StyleForm["Complex Plane", \ 
              FontFamily\  -> \ "Helvetica", \ 
              FontSize\  -> \ 
                10], \ \(-0.75\)\  - \ I]
}, 
FrameTicks -> 
          Automatic, 
PlotRange\  -> \ {{\(-1.51\), \ 
              1.5}, \ {\(-1.51\), \ 
              1.5}}, 
Background\  -> \ 
          Honeydew, 
PlotLabel\  -> \ "Point and Line in the Complex Plane", 
ImageSize\  -> \ 
          72*5];\)\)

Look closely at the label for the point in the two preceding plots.  In the first, the label is 1 + i, appearing in an upright Courier font; in the second, the label is 1  +  i, appearing in a Times font with an italic i.

Doesn't that look better?  Obviously you can have lots of fun building up the graphics so that it gives a clean and artistic representation of the mathematical idea you are trying to understand or convey.

Sometimes you want to label a point or other object with an expression involving complex numbers but you want the form of that expression to display, not its numerical value.  For example, suppose you had calculated the point 1  +  i from…

(1  +  3  I)/(2  +  I)

…but you want to label the point with the actual expression \(TraditionalForm\`\(1\  + \ 3  i\)\/\(2\  + \ i\)\).  Try it:

ComplexGraphics[
{
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1  +  I], 
Black, 
ComplexText[(1  +  3  I)/(2  +  I),  
            1.15  +  
              1.15  I]
}, 
PlotRange  ->  {{-1.51,  1.5},  {-1.51,  
              1.5}}, 
ImageSize  ->  
          72*5];

Mathematica evaluates the argument (1 + 3I)/(2 + I) inside ComplexText before forming the ComplexText graphics primitive object.  To prevent that evaluation, wrap the argument with HoldForm:

ComplexGraphics[
{
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1  +  I], 
Black, 
ComplexText[
            HoldForm[(1  +  3  I)/(2  +  I)],  
            1.15  +  
              1.15  I]
}, 
PlotRange  ->  {{-1.51,  1.5},  {-1.51,  
              1.5}}, 
ImageSize  ->  
          72*5];

And to typeset the label in traditional mathematical notation, include TraditionalForm as well:

ComplexGraphics[
{
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1  +  I], 
Black, 
ComplexText[
            TraditionalForm[HoldForm[(1  +  3  I)/(2  +  I)]],  
            1.15  +  
              1.15  I]
}, 
PlotRange  ->  {{-1.51,  1.5},  {-1.51,  
              1.5}}, 
ImageSize  ->  
          72*5];

It is especially important to use HoldForm when the expression involves a variable and you do not want the value of that variable to be used instead of the variable's name.  Look first at this display:

(Subscript[z, 0]) =  (1  +  3  I)/(2  +  
              I);
ComplexGraphics[
{
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1  +  I], 
Black, 
ComplexText[TraditionalForm[z  =  (Subscript[z, 0])],  
            1.15  +  
              1.15  I]
}, 
PlotRange  ->  {{-1.51,  1.5},  {-1.51,  
              1.5}}, 
ImageSize  ->  
          72*5];

That ComplexGraphics expression had a possibly unfortunate and unintended side-effect: it set z to be the value of (Subscript[z, 0]):

z

So first clear that value z…

Clear[z]

… and then compare the following display:

(Subscript[z, 0]) =  (1  +  3  I)/(2  +  
              I);
ComplexGraphics[
{
DodgerBlue, 
          PointSize[0.03], 
ComplexPoint[
            1  +  I], 
Black, 
ComplexText[TraditionalForm[HoldForm[z  =  (Subscript[z, 0])]],  
            1.15  +  
              1.15  I]
}, 
PlotRange  ->  {{-1.51,  1.5},  {-1.51,  
              1.5}}, 
ImageSize  ->  
          72*5];

Using ComplexCircle and ComplexDisk

To draw a circle
	\(TraditionalForm\`\(C\_r\)(
          z\_0)\  = \ {z\  ∈ \ \(ℂ\  : \ \(\(|\)\(z\  - \ z\_0\)\(|\)\)\)\  = \ r}\) 
with specified center (Subscript[z, 0]) (as a complex number) and radius r  >  0, use ComplexCircle.  For example:

ComplexGraphics[{Red,  Thickness[0.01],  
          ComplexCircle[I/2,  1]},  
        PlotRange  ->  {{-2,  2},  {-2,  2}},  
        ImageSize  ->  3 * 72];

And to draw an open disk 
	\(TraditionalForm\`\(D\_r\)(
          z\_0)\  = \ {z\  ∈ \ \(ℂ\  : \ \(\(|\)\(z\  - \ z\_0\)\(|\)\(\ \)\(\(<\)\(\ \)\(r\)\)\)\)}\)
—without the boundary circle—use ComplexDisk.  For example:

dsk  =  
        ComplexGraphics[{Pink,  
            ComplexDisk[I/2,  
              1]},   PlotRange  ->  {{-2,  2},  {-2,  
                2}},  ImageSize  ->  3 * 72];

To represent a closed disk 
	\(TraditionalForm\`\(D\&_\_r\)(
          z\_0)\  = \ {z\  ∈ \ \(ℂ\  : \ \(\(|\)\(z\  - \ z\_0\)\(|\)\(\ \)\(\(≤\)\(\ \ \)\(r\)\)\)\)}\)
(with its bounding circle), you may use both a ComplexDisk and a ComplexCircle object.

Exercise.  Use both ComplexDisk and ComplexCircle to display the closed disk of radius 1 centered at i with the open disk lavender and the bounding circle blue.

Exercise.  How might you represent graphically a punctured disk—a set of the form \(TraditionalForm\`\(\(D\&_\_r\^*\)\(\ \)\(=\)\(\ \)\({z\  ∈ \ \(ℂ\  : \ \(\(0\)\(\ \)\(<\)\)\  | 
                z\  - \ z\_0 | \ \(\(<\)\(\ \)\(r\)\)\)}\)\(\ \)\)\)?  Do this for the punctured disk of radius 1 centered at (1/2) i.

The function CirclePoint and utilties ToCoordinates and ToComplex

Although the ComplexGraphics package does not directly provide a single primitive for drawing a closed disk, there's another way to do it with a single object: you may use the function CirclePoint.

The function CirclePoint is part of Park's DrawGraphics package.  The latter package is automatically loaded by the ComplexGraphics package.

The form of CirclePoint is:
	CirclePoint[location, size, rimcolor, diskcolor]
where center must be a pair {x, y} of real coordinates (and size is given in printer's points).

To convert a complex number that's the center of the disk to its corresponding pair of real coordinates, use the ComplexGraphics utility function ToCoordinates:

ToCoordinates[I/2]

clsed  =  
        ComplexGraphics[
{
CirclePoint[
              ToCoordinates[I/2],  53,  Blue,  
              Lavender]
}, 
  PlotRange  ->  {{-2,  2},  {-2,  2}},  
          ImageSize  ->  3 * 72
];

The ComplexGraphics package utility function ToComplex is the inverse of ToCoordinates, that is, ToComplex converts a pair (x,  y) of real numbers into the corresponding complex number z  =  x  +  i y.  For example:

ToComplex[{2,  (1/5)}]

Exercise.   You might expect results of the expression in the following input cell to be {x, y} and x + i y, respectively.  Evaluate the expressions to see what the results actually are.  Then apply another Mathematica function to each result so that the final results are indeed {x, y} and x + i y.  (Hint:  See the appendices in notebook CardanBombeli.nb.)

Clear[x,  y]
ToCoordinates[ToComplex[{x,  y}]]
ToComplex[ToCoordinates[x  +  I y]]

Using ComplexCurve

A curve in the complex plane is (the set of points on the image of) a continuous function
	γ  :  [a,  
            b]  ->  ℂ
with domain some closed interval [a,  b].  For each t  ∈  [a,  b], the complex number γ(t) has the form
	γ(t)  =  z(t)  =  
          x(t)  +  i y(t)
where the functions
	x  :  [a,  
            b]  ->  ℝ,     y  :  [a,  
            b]  ->  ℝ
are real-valued.  Then the trace of the curve is the parametric plot of the pair of functions (x(t),  y(t)).

The function ComplexCurve, defined in the Cardano3`ComplexGraphics` package, facilitates drawing curves in the complex plane.

?ComplexCurve

Consider, for example, the upper semicircle of radius 2 with center the origin:

γ[θ_]  :=  2 Exp[I θ]

ComplexGraphics[
{
Blue, 
ComplexCurve[γ[θ],  {θ,  
              0,  π}]
},  
FrameTicks  ->  Automatic,  
        ImageSize  ->  4 * 72];

Another example is a spiral:

ComplexGraphics[
{
Blue, 
ComplexCurve[
            Exp[(1  +  2  I) t],  {t,  -2,  
              3}]
}, 
PlotRange  ->  All, 
ImageSize  ->  4 * 72] ;

The option PlotRange -> All in the preceding input ensures that all points on the curve, from t  =  -2  to t  =  3 are actually displayed.

Of course ComplexCurve objects may be combined with other ComplexGraphics primitive objects.  For example:

ComplexGraphics[
{
Blue, 
ComplexCurve[
            Exp[(1  +  2  I) t],  {t,  -2,  
              3}], 
Red,  
          Dashing[{0.04,  
              0.02}], 
ComplexLine[{Exp[-2  -  
                  4  I],  
              Exp[3  +  
                  6  I]}]
}, 
PlotRange  ->  All, 
ImageSize  ->  
          4 * 72] ;

Exercise.  Draw the line segment  from 1 to 1  +  i in two different ways:
	(a) By using ComplexLine.
	(b) By using ComplexCurve.  (Hint: How can you parameterize a line segment from a point a to a point b? ) 
Then evaluate just your ComplexCurve expression—without the enclosing ComplexGraphics function—so as to see what it gives to Mathematica to display.

What you see in the displays produced from (a) and (b) in the preceding exercise should be the same.  However, there is a critical difference in what's actually happening "behind the scenes":
•  Your ComplexLine expression gives Mathematica just the two endpoints 1  =  (1,  0) and 1  +  i  =  (1,  1) of the line segment, and then the ComplexGraphics expression causes Mathematica to draw the line segment connecting those two points.
•  Your ComplexCurve expression gives Mathematica a whole bunch of points along that line segment, and then the ComplexGraphics expression causes Mathematica to "connect the dots", each one to the next, with very short line segments, to obtain the entire line segment.
To see that this is so, look again at the result you obtained in the preceding exercise when you evaluated your ComplexCurve[…] expression by itself.

This little discussion may seem, er, pointless right now.  But later, when you try to visualize what happens to a line segment when you transform it by a function \(TraditionalForm\`f : \ ℂ\  -> \ ℂ\), it will be crucial to use ComplexCurve rather than ComplexLine to form the segment.

Exercise.  Draw circle with center 1  +  i and radius 2 in two different ways:
	(a) By using ComplexCircle.
	(b) By using ComplexCurve.  (Hint: How can you parameterize a line segment from a point a to a point b? ) 
Then evaluate just your ComplexCurve expression—without the enclosing ComplexGraphics function—so as to see what it gives to Mathematica to display.

Syntax of the ComplexGraphics function

The general form of a ComplexGraphics expression is
	ComplexGraphics[{primitives}, options]	
where:
	•  the argument {primitives} is a list consisting of one or more complex graphics objects (ComplexPoint, ComplexLine, ComplexCircle, ComplexDisk, ComplexCurve, ComplexText, etc., objects) together with zero or more graphics directives (PointSize and Thickness expressions, color specifications, etc.), in any order; and
	• options, if present, is a sequence of graphics options (ImageSize -> …, PlotRange -> …, Background -> …, PlotLabel -> …, FrameTicks -> , etc., options).

What's next?

The TwoPanelPlot function from the ComplexGraphics package is used to visualize the way a function \(TraditionalForm\`f : \ ℂ\  -> \ ℂ\) maps the plane.  See the notebooks VisualizeFunctions.nb and RiemannSphere.nb.