MathClass Lesson 3:
Triangles and Polygons
In this lesson, you will learn how to create diagrams of triangles and polygons for Geometry and Trigonometry class. We'll show you how to include vertex labels and angle indicators on your diagrams. As a special application, we use these tools to draw labeled cardboard rectangles with the corners marked for folding into a box.
Introduction
A remarkable number of diagrams require nothing more than the ability to draw line segments and label points of intersection, segments, etc. in figures comprised of line segments. Although Maple has general graphical tools for these and a few other basic constructions, it is convenient to use specialized forms contained in the MathClass package.
We will use only two of these at first: MathClass[DL] for "draw line" and MathClass[PT] for "put text". The syntax for each of these is:
MathClass[DL](A,B,thickness, style, color) draws a line segment from point A to point B with the following properties:
"thickness" is an integer from 0 to 9. Larger numbers result in thicker lines.
"style" is an integer from 1 to 4. For 1 the line is solid, for 2 the style is dot, 3 gives dash, and 4 gives dash-dot.
"color" determines the color of the line. There are a fairly large number of pre-defined colors in Maple: aquamarine black blue navy coral cyan brown gold green gray grey khaki magenta maroon orange pink plum red sienna tan turquoise violet wheat white yellow
MathClass[PT]( location, text, font size, color) places the string "text" centered at the point specified by "location" rendered in TIMES NEW ROMAN bold in point size specified by "font size" and color specified by "color". In general, darker colors are best for both line and text color in problem diagrams.
One of the simplest yet most common figures is a triangle. Some variant of this one appears as a portion of innumerable diagrams in geometry, algebra, calculus, etc:
It evidently consists of six primary components: three lines and three text labels
The with the MathClass[DL] command we can construct each of the lines and with the MathClass[MathClass[PT]] command we can construct each label.
The three lines are described by
MathClass[DL](A,B,3,1,blue)
MathClass[DL](A,C,3,1,blue)
MathClass[DL](B,C,3,1,blue)
As discussed above each of these actually defines a Maple plot structure and the sequence of them describes all of the lines in the figure. We give that sequence a convenient name that Maple can interpret and which has meaning to us.
> restart;
> libname := "C:/mylib/MathClass", libname:
> LNS:=MathClass[DL](A,B,3,1,blue), MathClass[DL](A,C,3,1,blue), MathClass[DL](B,C,3,1,blue):
We could attempt to display the lines of our figure with "plots[display]([ LNS ])" but Maple would return an empty plot since we defined the points A,B,C by giving their cartesian coordinates. In the absence of any additional information their definition is strictly up to us. Of course we want to choose them so that the triangle has the indicated shape. From our experience we know that if A=(0,0), B=(1,0), and C=(0,1) then the resulting triangle will have the inidcated configuration. In Maple such coordinates are described as a list of two numbers, i.e. A would have coordinates [0,0]. Now we could do the following
> LNS:=MathClass[DL]([0,0],[1,0],3,1,blue), MathClass[DL]([0,0],[1,1],3,1,blue), MathClass[DL]([1,0],[1,1],3,1,blue):
> TRNG:=plots[display](LNS):
> TRNG;
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
XX := MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
plots[display](XX);
which would produce the blue triangle. However it is MUCH BETTER PRACTICE to do the following:
> LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
> TRNG:=plots[display]([LNS]):
> TRNG;
>
Although both produce a blue triangle the latter is far preferable:
a. it is far more readable,
b. it is far more flexible.
Simply by changing the definition of the points A, B, and C we use this to produce any blue triangle at all. The advantages of keeping such descriptions readable and flexible will be more and more apparent as we develop more interesting diagrams. For now we still have work to do on our triangle.
So far we have a blue triangle which is missing the labels and accompanied by some cartesian "scaffolding" that we need to suppress. The simple addition of t he option "axes=none" in the plots[display] command will do this. However when building a diagram is almost always much better to leave the reference frame there -- for reference.
The labels "A", "B", "C" are nothing but plot structures. Collectively they comprise the text component of the diagram. We can use the MathClass[PT] command to generate them individually and as a first approximation we simply define a text expression sequence and insert it into the current description of the diagram. The "obvious" thing to try is the following which is almost right but may produce some unexpected results
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A,"A",16,red),MathClass[PT](B,"B",16,red),MathClass[PT](C,"C",16,red):
> TRNG:=plots[display]([LNS,TXT]):
> TRNG;
The declaration A:=[0,0]: tells Maple to substitute [0,0] for A. Thus we need to tell it that we want the string "A" rather than the value of the variable A. Fortunately this is simple. Whenever an expression is contained in double quotes (" ") the resulting expression is interpreted literally as the string of characters in inside the quotes, rather than as the any value that string may have been previously assigned. Thus what we wanted (almost) is:
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A,A,16,red),MathClass[PT](B,B,16,red),MathClass[PT](C,C,16,red):
> TRNG:=plots[display]([LNS,TXT]):
> TRNG;
This is much closer to what we want. As mentioned earlier we can remove the reference frame simply by adding an option to the plots[display] command so the only problem is that the letters are not perfectly placed and they are too small.
Increasing the size of the letters is simply a matter of increasing the font size in the MathClass[PT] command. Thus we can make several changes and select one that suits us.
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A,"A",50,red),MathClass[PT](B,"B",40,red),MathClass[PT](C,"C",20,red):
> TRNG:=plots[display]([LNS,TXT]):
> TRNG;
The 40-point B is interesting so we change A and C to that size, realizing that it is a simple matter to change to another size later. We still have to adjust the placement of the characters. The problem is that the command MathClass[PT](A,"A",50,red) instructs Maple to place an "A" centered precisely at the point described by A (in this case [0,0]). We need to adjust the placement. This is done simply by adding (or subtracting) and offset to each of their placements. In other words we change MathClass[PT](A,"A",50,red) to MathClass[PT](A+offset,"A",50,red) where "offset" is a vector we add to the point A to shift it to where we want the center of the letter "A" to be. BEFORE DOING THIS, however, we need to adjust the size of the diagram to the approximate size we will want it to be when used.
The diagram initially produced by Maple is usually much larger than we need. The size of the diagram produced by a command can be adjusted visually simply by clicking the mouse on a corner and draging the corner until the approximate correct size is attained. Then, the next time that code is executed the diagram will be the selected size. The reason for doing this is that the size of text placed in a diagram does not change as the diagram is re-scaled. Consequently, the amount of text offset required for a particular diagram may depend on the size at which it will be used. This is why we select the text offsets last , after selecting the size of the diagram and the text font sizes.
After shrinking our triangle, the 40 point text looks a bit outsized and we change to 30 point before selecting the offsets.
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A,"A",30,red),MathClass[PT](B,"B",30,red),MathClass[PT](C,"C",30,red):
> TRNG:=plots[display]([LNS,TXT]):
> TRNG;
Although it can be automated to a degree the selection of offsets is primarily a matter of esthetics (after all, what is really wrong with the diagram we have?). So even when it can partially be automated there will almost always remain some manual tweaking to be done.
In the current example we can see with reference to the coordinate axes that the characters need to be parallel to the axes about .1 - in different directions.
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A+[-.1,-.1],"A",30,red),MathClass[PT](B+[.1,-.1],"B",30,red),MathClass[PT](C+[.1,.1],"C",30,red):
> TRNG:=plots[display]([LNS,TXT]):
> TRNG;
This has the appearance we want so we complete this figure by removing the reference frame. This is done with the option "aces=none" in the plots[display] command
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A+[-.1,-.1],"A",30,red),MathClass[PT](B+[.1,-.1],"B",30,red),MathClass[PT](C+[.1,.1],"C",30,red):
> TRNG:=plots[display]([LNS,TXT],axes=none):
> TRNG;
Before continuing a few remarks are in order.
1. Name Conventions : We have used a naming convertion for component groups of our figure which consists of taking a descriptive word for the group, making it all upper case, and deleting as many of the vowels as we can while retaining the sense of the word . This we use LNS for "lines" and TXT for "text". In principle there is nothing wrong with using the entire word (including the vowels) in lower or mixed case. The problem is that one may run into maple "reserved words" and receive mysterious and frustrating error messages. For instance "line" and "TEXT" are reserved in Maple, the reader may want to investigate what happens if "line" is used in place of "LNE" or "TEXT" in place of "TXT". Experience has shown that the use of variables such as these will retain readability and avoid reserved word conflicts - with one, unfortunate, critical, exception: the letters "D", "I", and "O".
"D", "I", and "O" are reserved words in Maple: they cannot be assigned alternative values. Even the most experienced user will periodically forget and attempt to assign a value to one of these which constructing a diagram. The author generally elects to use "DD", "II", and "OO". Thus for instance if we had been making a square rather than a triangle the points might have been
A:=[0,0];
B:=[1,0];
C:=[1,1];
DD:=[0,1];
Note that MathClass[PT](DD,"D",30,green) ; would work fine since "D" refers to the character "D" rather than the value Maple assigns the variable D.
Finally, one must be aware of the possibility of inadvertently encroaching on reserved words and be prepared to encounter them. They usually result in error mesages containg phrases such as the following:
".. attempted recursive definition .."
".. reserved word .."
2. More on Offsets In the above we used method of inspecting the diagram (after resizing) and estimating the offset from the reference frame in the picture. There is another, very convenient method. Simply place the mouse pointer at the point one would like to have the text centered. Then click the mouse and the coordinates of that point will appear in a small window in the upper left corner th window. For instance in our diagram if we place the mouse pointer about where we would like to see the "C" centered the window appears as below
PICTURE -- (coords read 1.09, 1.12 )
It is a simple matter to highlight the pair of coordinates paste them into the "location" slot of the MathClass[PT] command. For instance in this case we might paste over the A in
MathClass[PT](A,"A",30,red) to get MathClass[PT](1.09, 1.12,"A",30,red) to which we need to add the brackets to finish with MathClass[PT]([1.09, 1.12],"A",30,red) .
This will work even with the coordinate frame suppressed as Maple still has to maintain those references to know where to place things. When doing a "quick and dirty" diagram for an in-class quiz, a slide for a talk, etc. this is perfectly reasonable. However it is generally a much better idea to retain the "A" and do a little subtracting and rounding to get an offset.
You can even get Maple to do the calculation. Just start with the following line
and paste the coordinates into the brackets
> [1.09, 1.12] -C;
This gives us an offset which we can use directly by copying and pasting.
MathClass[PT](C,"C",30,red)
becomes
MathClass[PT](C +
,"C",30,red):
Why would we want to do it this way? For portability.
In the form below we can easily use this code to create other triangles simply by redefining A,B, and C. The offsets of the resulting triangle may need a little adjusting but as we have seen that is very easy as long as the picture is approximately right.
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A+[-.1,-.1],"A",30,red),MathClass[PT](B+[.1,-.1],"B",30,red),MathClass[PT](C+[.1,.1],"C",30,red):
> TRNG:=plots[display]([LNS,TXT],axes=none):
> TRNG;
However, if the TXT line is
> TXT:=MathClass[PT]([-0.14, -0.14] ,"A",30,red), MathClass[PT]([1.10, -0.10],"B",30,red),MathClass[PT]( [1.10, 1.08],"C",30,red):
Then changing A=[1,0],B=[2,0] ,C=[2,1] will not affect this line all so when the code is executed the result will be:
code
> A:=[1,0];
> B:=[2,0];
> C:=[1,1];
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT]([-0.14, -0.14] ,"A",30,red), MathClass[PT]([1.10, -0.10],"B",30,red),MathClass[PT]( [1.10, 1.08],"C",30,red):
> TRNG:=plots[display]([LNS,TXT],axes=none):
> TRNG;
>
In this simple example it is more or less evident what to do to correct the code however in a more complex example one can easily get to the point where it is easier to start over. The small amount of time invested in a systematic approach will pay handsome dividends in reusable, adaptable, sharable materials, time savings, and reduced frustration.
Some Additional Examples
Example: Adapt the previous example to to indicate that the triangle is a right triangle by adding two small, black line segments, one parallel to each side.
Solution: The exercise asks use to create something like the following
This is accpmplished simply by adding a new construct which we label RTANGL below. It consists of two lines and might have been included in the LNS construct. There are two reasons not to do it that way. First, the code is more readable when the expression sequences comprising the components are not lengthy. Second, and much more important is that each of our component constructs is comprised of very similar commands. It is usually the case that once the first of such a sequence is constructed then the rest are very minor and very logical modifications of the first. This often permits us to construct the component by getting the first one right, copying and pasting additional copies of the first to it, and then quickly going down that sequence making changes according to some evident pattern.
Notice that we have not forgotten to append the RTANGL construct to the list in the plots[display] command.
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A+[-.1,-.1],"A",30,red),MathClass[PT](B+[.1,-.1],"B",30,red),MathClass[PT](C+[.1,.1],"C",30,red):
> RTANGL:=MathClass[DL](B-[.2,0],B-[.2,0]+[0,.2],1,1,black),MathClass[DL](B-[.2,0]+[0,.2],B+[0,.2],1,1,black):
> TRNG:=plots[display]([LNS,TXT,RTANGL],axes=none):
> TRNG;
Example: Add a second triangle, congruent to the first to the diagram by shifting the original triangle 2 units to the right and up 1. Let the second triangle be green with vertices labeled D, E, and F
Solution: We are asked to produce the following (or a similar one with the D,E,F labels permuted):
All we want to do is create to plot structures and merge them with a plots[display] command. Let us call our original triangel TRNG1
> A:=[0,0]:
> B:=[1,0]:
> C:=[1,1]:
>
LNS:=MathClass[DL](A,B,3,1,blue),MathClass[DL](A,C,3,1,blue),MathClass[DL](B,C,3,1,blue):
TXT:=MathClass[PT](A+[-.1,-.1],"A",30,red),MathClass[PT](B+[.1,-.1],"B",30,red),MathClass[PT](C+[.1,.1],"C",30,red):
> RTANGL:=MathClass[DL](B-[.2,0],B-[.2,0]+[0,.2],1,1,black),MathClass[DL](B-[.2,0]+[0,.2],B+[0,.2],1,1,black):
> TRNG1:=plots[display]([LNS,TXT,RTANGL],axes=none):
Now we have removed the "TRNG" line as that simply instructed Maple to draw a picture of the triangle for us. Now we make a duplicate of the code with copy and paste. The idea is to adapt the original with as few changes as possible.
Our instructions are to shift the original triangle 2 to the right and up 1. The way we do this in cartesian geometry is simply by adding [2,1] to each point of the figure. Since the figure is defined in terms of the points A,B, C all we need to do is shift them. Note that in the following we are having to recall that we can't redifine D in Maple.
All we do is "reinterpret" A,B,C by shifting them, give the shifted points new names and replace the original names by the new names in the code. Thus each A (when used as a point) is replaced by DD and when used as a string it is replaced by D. B is simply replaced by E and C by F. We call the resulting figure TRNG2
> SHFT:=[2,1]:
> DD:=A+SHFT:
> E:=B+SHFT:
> F:=C+SHFT:
>
LNS:=MathClass[DL](DD,E,3,1,blue),MathClass[DL](DD,F,3,1,blue),MathClass[DL](E,F,3,1,blue):
TXT:=MathClass[PT](DD+[-.1,-.1],"D",30,red),MathClass[PT](E+[.1,-.1],"E",30,red),MathClass[PT](F+[.1,.1],"F",30,red):
> RTANGL:=MathClass[DL](E-[.2,0],E-[.2,0]+[0,.2],1,1,black),MathClass[DL](E-[.2,0]+[0,.2],E+[0,.2],1,1,black):
> TRNG2:=plots[display]([LNS,TXT,RTANGL],axes=none):
Now we simply "glue" the two triangles together
> TRNG3:=plots[display]([TRNG1,TRNG2]):
> TRNG3;
>
>
> #assemble the figureThe Maple command which creates such figures is plots[polygonplot]
A polygon is described in Maple by giving a list of its vertices as one treaverses its perimeter (in either order. Thus we can describe the parallelogram in the diagram below by: [[0,0],[2,0],[3,1],[1,1]] . This is not unique, there are seven more equally valid descriptions such as [[3,1],[2,0],[0,0],[1,1]]
To plot this polygon with plots[polygonplot]
> DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,INRECT,RECT],scaling=constrained,axes=none):
> DGRM;
> pgrm:= [[0,0],[2,0],[3,1],[1,1]] :
> PGRM:=plots[polygonplot](pgrm):
> PGRM;
The default color is white however we can specify the color just as with other commands and can suppress the axes just as before.
> PGRM:=plots[polygonplot](pgrm,color=blue,axes=none):
> PGRM;
If we want a transparent polygon with the edge of specified color, style, and thickness we elect style=line and deterimine the other paramenters as before:
> PGRM:=plots[polygonplot](pgrm,style=line,thickness=3,linestyle=3,color=blue,axes=none):
> PGRM;
In a previous exercise we made a "Happy Face" using circles and circular arcs. The face on such a figure is usually painted on a yellow disk rather than a white one. The plottools[disk] command places disks of a given radius and color at any point.
> hdisk:=plottools[disk]([0,0],1,color=yellow):
> plots[display](hdisk);
We omit the axes and constrain the scaling in plots[display] commans in the usual manner
> hdisk:=plottools[disk]([0,0],1,color=yellow):
> plots[display](hdisk,scaling=constrained, axes=none);
Now we can use polygons and disks as components of our diagrams
Example: Make a happy face on a yellow disk
Solution : The figure below is an example
The figure consists of the yellow disk, the smile and the eyes so we build these three components using plottoold[disk] for the yellow disk and MathClass[PC] and MathClass[PA] for the eyes.
smileyface
> #face
> FCECNTR:=[0,0]:# face center
> FCERDS:=1:#face radius
> LEYECNTR:=FCECNTR+FCERDS*[-.5,.25]:#Left eye center
> REYECNTR:=FCECNTR+FCERDS*[+.5,.25]:#right eye center
> EYERDS:=.15*FCERDS:#eye radius
> FCECLR:=yellow:# face color
> EYECLR:=black:#eye color
> #smile (stolen from stickman)
> SMLCNTR:=FCECNTR+FCERDS*[0,.25]: #smile center
> SMLRDS:=.9*FCERDS: #smile radius
> SMLANGL1:=9*Pi/8:
> SMLANGL2:=15*Pi/8:
> SMLCLR:=black:# smile color
> #components
> DSK:=plottools[disk](FCECNTR,FCERDS,color=FCECLR):
> EYS:=MathClass[PC](REYECNTR,EYERDS,3,1,EYECLR),MathClass[PC](LEYECNTR,EYERDS,3,1,EYECLR):
> SML:=MathClass[PA](SMLCNTR,SMLRDS,SMLANGL1,SMLANGL2,3,1,SMLCLR):
> #assembly
> SMFACE:=plots[display]([EYS,SML,DSK],scaling=constrained,axes=none):
> SMFACE;
Exercise: Examine the smiley face code and build the eyes with plottools[disk] rather than MathClass[PC].
Exercise: Adapt the smiley face to make a "frowning face" with a (solid) red left eye and a green right eye
Exercise: Use MathClass[PA] to give the smiley face some eyebrows
>
It is often convenient to place diagrams on a background of a color of our chosing. For instance if we wanted to place the smiley face on a green background we can use plots[polygonplot] to make a green rectangle and them place the face on the rectangle with plots[display]
>
> bkgrnd:=[[-2,-2],[2,-2],[2,2],[-2,2]]:
> BKGRND:=plots[polygonplot](bkgrnd,color=green):
> plots[display]([SMFACE,BKGRND],axes=none,scaling=constrained);
Note: when we assemble a diagram by having plots[display] act on a list of figures it places the individual components in the list is the opposite order in which they appear in the list. That is plots[display]([A,B,C]) puts A on top of B on top of C. Failure to keep track of this can lead to some unexpected results. For instance if we reverse the order of the face and background in the previous example
> plots[display]([BKGRND,SMFACE],axes=none,scaling=constrained);
Example: Illustrating a standard calculus problem using plots[polygonplot]
A problem appearing in most calculus books asks the maximum possible volume of an open-top box made from a rectangular piece of cardboard by cutting squares of material from each corner folding up the resulting four edge panels. Create a diagram to illustrate this problem.
Solution: The following is the basic diagram
To systematically construct the diagram we proceed to identify parameters that define the figure.
There is a large rectangle with four smaller squares. We elect to treat these as separate components although it would be equally reasonable to treat the four small squares collectively as one component. To start we elect to make the rectangle orange, the small squares grey, and the edge of the small squares 20% of the width of the rectangle.
rectangle/squares
> #diagram parameters
> WDTH:=10:# width of the rectangle
> LNGTH:=20:# length of the rectangle
>
SQSIDE:=.2*WDTH:#edge of small square =.2*length
LLRECT:=[0,0]:# lower left corner of rectangle
> RECTCLR:=orange:#color of rectangle
> SQCLR:=grey:#color of the squares
>
> #corners of the rectangle
> A:=LLRECT:
> B:=A+[LNGTH,0]:
> C:=A+[LNGTH,WDTH]:
> DD:=A+[0,WDTH];
>
> # make the rectangle
> rect:=[A,B,C,DD]:
> #make the squares:
> llsq:=[A+[0,0],A+[SQSIDE,0],A+[SQSIDE,SQSIDE],A+[0,SQSIDE] ]:#lower left
> lrsq:=[B+[0,0],B+[-SQSIDE,0],B+[-SQSIDE,SQSIDE],B+[0,SQSIDE] ]:#lower right
> ursq:=[C+[0,0],C+[-SQSIDE,0],C+[-SQSIDE,-SQSIDE],C+[0,-SQSIDE] ]:#upper right
> ulsq:=[DD+[0,0],DD+[SQSIDE,0],DD+[SQSIDE,-SQSIDE],DD+[0,-SQSIDE] ]:#upper left
> #create the plots
>
>
>
>
> RECT:=plots[polygonplot](rect,color=RECTCLR):
> LLSQ:=plots[polygonplot](llsq,color=SQCLR):
> LRSQ:=plots[polygonplot](lrsq,color=SQCLR):
> URSQ:=plots[polygonplot](ursq,color=SQCLR):
> ULSQ:=plots[polygonplot](ulsq,color=SQCLR):
>
> #assemble the figure
> DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,RECT],scaling=constrained,axes=none):
> DGRM;
As we have noted before the order in which one assembles a diagram can be important. In the previous example the assembly instruction
DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,RECT],scaling=constrained,axes=none) lays the orange rectangle, then the upper left square is placed on top of that figure, then the lower right, ... ect. The effect of DGRM:=plots[display]([LLSQ,URSQ,RECT,LRSQ,ULSQ],scaling=constrained,axes=none) would be to lay down the upper left and lower right squares before laying down the rectangle with the resulting diagram the following:
switched assembly
> DGRM_switched:=plots[display]([LLSQ,URSQ,RECT,LRSQ,ULSQ],scaling=constrained,axes=none):
> DGRM_switched;
Although this is not an unreasonable diagram one may want to improve it. For instance one may wish to more clearly indicate that the squares are to be removed by having them white with dashed edges. To make this more visible we may want to increase the size of the small squares.
To increase the side length of the square we would edit the "SQSIDE" declaration
SQSIDE:=.3*WDTH:
To change the colors of the squares we edit the SQCLR declaration
SQCLR:=white:
To make the edges of the squares dashed we edit their plot declarations. For instance
LLSQ:=plots[polygonplot](llsq,color=SQCLR,linestyle=3):
Note we have added the option "linestyle=3" which specifies that the square border will be dashed - exactly as with MathClass[DL] instructions.
These changes produce:
rectangle, white, dashed inner squares
> #diagram parameters
> WDTH:=10:# width of the rectangle
> LNGTH:=20:# length of the rectangle
>
SQSIDE:=.3*WDTH:#edge of small square =.3*length
LLRECT:=[0,0]:# lower left corner of rectangle
> RECTCLR:=orange:#color of rectangle
> SQCLR:=white:#color of the squares
>
> #corners of the rectangle
> A:=LLRECT:
> B:=A+[LNGTH,0]:
> C:=A+[LNGTH,WDTH]:
> DD:=A+[0,WDTH];
>
> # make the rectangle
> rect:=[A,B,C,DD]:
> #make the squares:
> llsq:=[A+[0,0],A+[SQSIDE,0],A+[SQSIDE,SQSIDE],A+[0,SQSIDE] ]:#lower left
> lrsq:=[B+[0,0],B+[-SQSIDE,0],B+[-SQSIDE,SQSIDE],B+[0,SQSIDE] ]:#lower right
> ursq:=[C+[0,0],C+[-SQSIDE,0],C+[-SQSIDE,-SQSIDE],C+[0,-SQSIDE] ]:#upper right
> ulsq:=[DD+[0,0],DD+[SQSIDE,0],DD+[SQSIDE,-SQSIDE],DD+[0,-SQSIDE] ]:#upper left
> #create the plots
>
>
>
>
> RECT:=plots[polygonplot](rect,color=RECTCLR):
> LLSQ:=plots[polygonplot](llsq,color=SQCLR,linestyle=3):
> LRSQ:=plots[polygonplot](lrsq,color=SQCLR,linestyle=3):
> URSQ:=plots[polygonplot](ursq,color=SQCLR,linestyle=3):
> ULSQ:=plots[polygonplot](ulsq,color=SQCLR,linestyle=3):
>
> #assemble the figure
> DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,RECT],scaling=constrained,axes=none):
> DGRM;
It appears that the inner edges of the cutouts are dashed in this picture but not the outer. Actually the perimeters of each of the squares is dashed but the outer portions are laying on top of the perimeter of the rectangle. One fix for this is to remover the border of the rectangle. This is done with the "patchnogrid" option. That is if we change the instructions that produced the previous diagram by changing the RECT plot declaration to
RECT:=plots[polygonplot](rect,color=RECTCLR,style=patchnogrid): we get
rectangle, white, dashed squares
> #diagram parameters
> WDTH:=10:# width of the rectangle
> LNGTH:=20:# length of the rectangle
>
SQSIDE:=.3*WDTH:#edge of small square =.3*length
LLRECT:=[0,0]:# lower left corner of rectangle
> RECTCLR:=orange:#color of rectangle
> SQCLR:=white:#color of the squares
>
> #corners of the rectangle
> A:=LLRECT:
> B:=A+[LNGTH,0]:
> C:=A+[LNGTH,WDTH]:
> DD:=A+[0,WDTH];
>
> # make the rectangle
> rect:=[A,B,C,DD]:
> #make the squares:
> llsq:=[A+[0,0],A+[SQSIDE,0],A+[SQSIDE,SQSIDE],A+[0,SQSIDE] ]:#lower left
> lrsq:=[B+[0,0],B+[-SQSIDE,0],B+[-SQSIDE,SQSIDE],B+[0,SQSIDE] ]:#lower right
> ursq:=[C+[0,0],C+[-SQSIDE,0],C+[-SQSIDE,-SQSIDE],C+[0,-SQSIDE] ]:#upper right
> ulsq:=[DD+[0,0],DD+[SQSIDE,0],DD+[SQSIDE,-SQSIDE],DD+[0,-SQSIDE] ]:#upper left
> #create the plots
>
>
>
>
> RECT:=plots[polygonplot](rect,color=RECTCLR,style=patchnogrid):
> LLSQ:=plots[polygonplot](llsq,color=SQCLR,linestyle=3):
> LRSQ:=plots[polygonplot](lrsq,color=SQCLR,linestyle=3):
> URSQ:=plots[polygonplot](ursq,color=SQCLR,linestyle=3):
> ULSQ:=plots[polygonplot](ulsq,color=SQCLR,linestyle=3):
>
> #assemble the figure
> DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,RECT],scaling=constrained,axes=none):
> DGRM;
Exercises:
Exercise 1: Modify the instructions for the "cutout" diagram to produce:
and
exercise1
> #diagram parameters
> WDTH:=10:# width of the rectangle
> LNGTH:=20:# length of the rectangle
>
SQSIDE:=.3*WDTH:#edge of small square =.3*length
LLRECT:=[0,0]:# lower left corner of rectangle
>
RECTCLR:=white:#color of rectangle
RECTCLR:=grey:#color of rectangle
> SQCLR:=white:#color of the squares
>
> #corners of the rectangle
> A:=LLRECT:
> B:=A+[LNGTH,0]:
> C:=A+[LNGTH,WDTH]:
> DD:=A+[0,WDTH];
>
> # make the rectangle
> rect:=[A,B,C,DD]:
> #make the squares:
> llsq:=[A+[0,0],A+[SQSIDE,0],A+[SQSIDE,SQSIDE],A+[0,SQSIDE] ]:#lower left
> lrsq:=[B+[0,0],B+[-SQSIDE,0],B+[-SQSIDE,SQSIDE],B+[0,SQSIDE] ]:#lower right
> ursq:=[C+[0,0],C+[-SQSIDE,0],C+[-SQSIDE,-SQSIDE],C+[0,-SQSIDE] ]:#upper right
> ulsq:=[DD+[0,0],DD+[SQSIDE,0],DD+[SQSIDE,-SQSIDE],DD+[0,-SQSIDE] ]:#upper left
> #create the plots
>
>
>
>
> RECT:=plots[polygonplot](rect,color=RECTCLR):
> LLSQ:=plots[polygonplot](llsq,color=SQCLR,linestyle=3):
> LRSQ:=plots[polygonplot](lrsq,color=SQCLR,linestyle=3):
> URSQ:=plots[polygonplot](ursq,color=SQCLR,linestyle=3):
> ULSQ:=plots[polygonplot](ulsq,color=SQCLR,linestyle=3):
>
> #assemble the figure
> DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,RECT],scaling=constrained,axes=none):
> DGRM;
Exercise 2: Modify the instructions for the "cutout" diagram to produce:
and
exercise2
> #diagram parameters
> WDTH:=10:# width of the rectangle
> LNGTH:=20:# length of the rectangle
>
SQSIDE:=.2*WDTH:#edge of small square =.3*length
LLRECT:=[0,0]:# lower left corner of rectangle
>
#RECTCLR:=white:#color of rectangle
RECTCLR:=magenta:#color of rectangle
> SQCLR:=white:#color of the squares
>
> #corners of the rectangle
> A:=LLRECT:
> B:=A+[LNGTH,0]:
> C:=A+[LNGTH,WDTH]:
> DD:=A+[0,WDTH];
>
> # make the rectangle
> rect:=[A,B,C,DD]:
> #make the squares:
> llsq:=[A+[0,0],A+[SQSIDE,0],A+[SQSIDE,SQSIDE],A+[0,SQSIDE] ]:#lower left
> lrsq:=[B+[0,0],B+[-SQSIDE,0],B+[-SQSIDE,SQSIDE],B+[0,SQSIDE] ]:#lower right
> ursq:=[C+[0,0],C+[-SQSIDE,0],C+[-SQSIDE,-SQSIDE],C+[0,-SQSIDE] ]:#upper right
> ulsq:=[DD+[0,0],DD+[SQSIDE,0],DD+[SQSIDE,-SQSIDE],DD+[0,-SQSIDE] ]:#upper left
> #create the plots
>
>
>
>
> RECT:=plots[polygonplot](rect,color=RECTCLR,style=patchnogrid):
> LLSQ:=plots[polygonplot](llsq,color=SQCLR,style=patchnogrid):
> LRSQ:=plots[polygonplot](lrsq,color=SQCLR,style=patchnogrid):
> URSQ:=plots[polygonplot](ursq,color=SQCLR,style=patchnogrid):
> ULSQ:=plots[polygonplot](ulsq,color=SQCLR,style=patchnogrid):
>
> #assemble the figure
> DGRM:=plots[display]([LLSQ,URSQ,LRSQ,ULSQ,RECT],scaling=constrained,axes=none):
> DGRM;
Exercise 3: Modify instructions for the "cutout" diagram to produce the following.
and
It will be necessary to add the new lines using either "MathClass[DL]" or plots[polygonplot]. The latter is preferable
exercise3
> #diagram parameters
> WDTH:=10:# width of the rectangle
> LNGTH:=20:# length of the rectangle
>
SQSIDE:=.2*WDTH:#edge of small square =.3*length
LLRECT:=[0,0]:# lower left corner of rectangle
>
#RECTCLR:=white:#color of rectangle
RECTCLR:=orange:#color of rectangle
>
SQCLR:=white:#color of the squares
#INRECTCLR:=grey:#color of the inner rectangle
INRECTCLR:=black:#color of the inner rectangle
>
> #corners of the rectangle
> A:=LLRECT:
> B:=A+[LNGTH,0]:
> C:=A+[LNGTH,WDTH]:
> DD:=A+[0,WDTH];
> #corners of the inner rectangle
> AI:=A+[SQSIDE,SQSIDE]:
> BI:=B+[-SQSIDE,SQSIDE]:
> CI:=C+[-SQSIDE,-SQSIDE]:
> DDI:=DD+[SQSIDE,-SQSIDE]:
>
>
> # make the rectangle
>
rect:=[A,B,C,DD]:
#make the inner rectangle
inrect:=[AI,BI,CI,DDI]:
> #make the squares:
> llsq:=[A+[0,0],A+[SQSIDE,0],A+[SQSIDE,SQSIDE],A+[0,SQSIDE] ]:#lower left
> lrsq:=[B+[0,0],B+[-SQSIDE,0],B+[-SQSIDE,SQSIDE],B+[0,SQSIDE] ]:#lower right
> ursq:=[C+[0,0],C+[-SQSIDE,0],C+[-SQSIDE,-SQSIDE],C+[0,-SQSIDE] ]:#upper right
> ulsq:=[DD+[0,0],DD+[SQSIDE,0],DD+[SQSIDE,-SQSIDE],DD+[0,-SQSIDE] ]:#upper left
> #create the plots
>
>
>
>
>
RECT:=plots[polygonplot](rect,color=RECTCLR,style=patchnogrid):
#INRECT:=plots[polygonplot](inrect,color=INRECTCLR):
INRECT:=plots[polygonplot](inrect,color=INRECTCLR,style=line,linestyle=3):
>
#LLSQ:=plots[polygonplot](llsq,color=SQCLR,style=line,linestyle=3):
#LLSQ:=plots[polygonplot](llsq,color=SQCLR,linestyle=3):
LLSQ:=plots[polygonplot](llsq,color=SQCLR,style=patchnogrid):
> LRSQ:=plots[polygonplot](lrsq,color=SQCLR,style=patchnogrid):
> URSQ:=plots[polygonplot](ursq,color=SQCLR,style=patchnogrid):
> ULSQ:=plots[polygonplot](ulsq,color=SQCLR,style=patchnogrid):
>
>
Exercise 4: Modify the "cutout" diagram to produce the following diagram: