boxes1.mws



MathClass Lesson 1:

Blocks and Bricks

Section 1.1: First steps -- Drawing boxes

In this first lesson, we give an introduction to Maple's graphical programming. We will use block and brick drawing as our running example. Users already familiar with Maple programming, polygon plotting and animations may wish to browse the examples of Lesson 1 only briefly and then quickly proceed to Lesson 2, where the MathClass package tools are introduced.

Introduction

Visual problem solving is concerned with problems whose statements or solutions (hopefully both) have a visual character which can be appreciated and even assessed without reference to the underlying mathematics. This is analogous to the manner in which we can appreciate music without reference to or even understanding of its creator's tools - the fact notwithstanding those with such knowledge can appreciate it at a higher level. In the course of this study we will find that there is an incredible variety of problems of this nature and that there are techniques for developing families of them from basic contexts. In this introduction to the subject we will primarily restrict our attention to problems which can be analyzed with the non-calculus mathematics and basic science studied in middle and high school. However, since part of what we will be doing is generating new problems from old we must be prepared to find ourselves formulating questions in that vocabulary whose solution requries new tools. We will celebrate when we do for the quest for problems not solvable within a science is the most basic process in by which it is extended.

Problem solving is about marshalling the intellectual tools at our disposal to attack a problem. The expected result of a serious attack on a problem is a
contribution to its solution. A contribution may well fall short of a complete solution but it will always present one's formulation of the problem, one's approach to analyzing the problem, and the results of one's analysis. In keeping with our visual approach at least one of these components will contain elements of a visual nature. Our primary tool will be Maple.

Maple is a computer program (sometimes called a symbolic manipulation program) which can generate and manipulate algebraic, numerical, and geometric objects. It has a language of its own (the Maple language) through which it can be directed to perform virtually any mathematical or geometric operation. More over this language is extensible which means that, like any natural language, it can be used to define new words which the program can recognize and new symbols which it can manipulate. A Maple Worksheet is an electronic file containing text and inserted images (which have meaning only to people), Maple commands (words) which direct the program to perform certain operations, and output which is text, images, or other constructs generated by the program in response to the commands. In general the responses (also called the output(s)) are not needed if one has the commands since they can always be recovered from the latter. Such a sequence of commands is typically a small amount of text which can readily be communicated by electronic means.

Mathematical Boxes

We assume that the reader is familiar with the fact that any two mutually perpendicular lines in the plane or three mutually perpendicular number lines in space define a cartesian coordinate system relative to which every point in the plane or space has a unique name, called its coordinates . Points in the plane or space may have other names such as "X","Lexington", or "Detroit", etc. and for a particular purpose these may be far more descriptive than a list of coordinates. The importance of coordinates is that that algebraic relationships among the coordinates of (collections of) points fully express geometric relationships among the points themselves. This means that we can use algebra to express and investigate geometric relationships (and visa versa). Moreover, since computers can "understand" and "communicate" algebraic relationships, this provides both a path to the physical/geometric/visual worlds we propose to explore and a vehicle take us at least part of the way there. The coordinates of a point are a list so our first task is learn about lists in Maple.

In Maple, lists are sequences of objects enclosed in brackets "[ ]". The order of the objects in a list is important. Thus the lists [1,2,3] and [2,1,3] are different and the lists [a,b,c] and [d,e,f] are equal (as lists) only if a=d, b=e, and c=f. Note also that, to Maple, only the first of [1,2,3], {1,2,3}, and (1,2,3) is a list. Our initial Maple command to plot points in space is "plots[polygonplot3d]" which is a command which accepts lists of points and plots the (spatial) polygon with those points as its vertices. Thus if we want to create a visual representation of the spatial triangle with vertices [1,2,3], [4,1,5] and [7,8,3] we enter the following at the command prompt ">" .

> plots[polygonplot3d]([[1,2,3],[4,1,5], [7,8,3]]);

[Maple Plot]

> plots[polygonplot3d]([[1,2,3],[4,1,5], [7,8,3]]);

[Maple Plot]

>

The analogous command which displays a polygon in the plane is "plots[polygonplot]."

> plots[polygonplot]([ [ 0,0], [1,2], [3,-5]]);

[Maple Plot]

>

The "plots" part of these command tells Maple to look in the "package" of commands called "plots" for the word "polygonplot3d". We can first tell Maple to "load" all of the words in the plots package into the current session by the command "with(plots)" after which it will recognize only the "polygonplot3d" part . However it is better style to use the full name plots[polygonplot] becasue this works regardless of whether the "plots" package has been loaded. Although loading the plots package may relieve us of a few keystrokes in writing down our work this should typicallybe foregone for the far greater advantage of portability and readability of our instructions. We will continuously find that we want to go back to old worksheets and reuse pieces of code via "cut and paste" operations. If such code requires that the plots package be loaded it wor't work as expected. The result can be large amounts of frustrationa and wasted time spent re-reading such material to see if perhaps it depends on packages having been loaded earlier in the worksheet.

> with(plots);

Warning, the name changecoords has been redefined

[animate, animate3d, animatecurve, changecoords, co...
[animate, animate3d, animatecurve, changecoords, co...
[animate, animate3d, animatecurve, changecoords, co...
[animate, animate3d, animatecurve, changecoords, co...
[animate, animate3d, animatecurve, changecoords, co...

>

Note the large list of interesting "visual" words which were returned uopn execution of the "with(plots);" We will visit a number of them in this study.

>

The ability of Maple to draw polygons in space provides us with the means to create images of any spatial object which consists of polygons. Lets begin with one of the most familiar objects, a cube. A cube has eight vertices , and six faces , each defined by a sequence of the vertices. Since Maple can work with symbols we can represent the vertices symbolically, say with symbols v1, v2, .. and the faces (top, bottom, left, right, front, and back) as sequences of the vertices. First we sketch our cube, labeling its vertices and faces with these symbols and then "read off" the lists we need to communicate with Maple. It is very helpful to use a temporary, hand-drawn sketch or diagram. (Which can be very crude.)

[Maple OLE 2.0 Object]

>

Notice that all of this so far is hand drawings and text. We have not communicated anything to the Maple program which "understands" a limited vocabulary and has no ability at all to understand pictures. We enter Maple commands at the command prompt ">". We want to describe to Maple each of the faces of our box using terms that have meaning (the same meaning) to both us and the computer .

DEFINITION : A polygon is an ordered list of coplanar points. An n-gon is a list of n different points. Two lists correspond to the same polygon if some circular permutation of one or yields the other or a reverse listing of the other .


The connection between our usual geometric view of a polygon and this form is that the list which describes it may be thought of as the order in which the verticies are passed as one "walks" along the boundary of the polygon along a path which passes each vertex exactly once. The fact that there are numerous paths which so this corresponds to the fact that there are numerous lists which represent a particular polygon.
Thus, for instance, the front face of our sketch is the list [v1, v2, v3, v4]. It is also [v2,v3,v4,v1] and [v3, v2,v1,v4]
.

It is posible and convenient for the same object to have more than one name in Maple. Thus for instance, with reference to the above diagram we may want to refer to the ploygon whose vertices are v1,v2,v3,v4 as the "front face" or simply to give it the name "front". Similarly there is a "back", "top", etc, the latter being names for other polygons which are easy to refer to and remember. The way we tell Maple that we want to refer to the list [v1,v2,v3,v4] as "face" is via assignment .

> front:=[v1,v2,v3,v4];

front := [v1, v2, v3, v4]

> front;

[v1, v2, v3, v4]

What we have done is create an alternate name or label for this list. We might communicate this in English with a sentence like "Let "front" designate the list [v1,v2,v3,v4]."

The same object can have any number of names.

> Front_face_of_the_cube:=front;

Front_face_of_the_cube := [v1, v2, v3, v4]

Sometimes longer names such as the above are very useful in the development of more complicated sets of instructions.

We will repeatedly use this idea of assignment for labels: alternate convenient names for certain object which will have the same meaning to us and the computer program. We will, at the same time need to understand the difference between an equation (which uses the symbol "=") and an assigned equality which uses the symbol ":=". Consider the following :

> joe:=1;

joe := 1

> sam=10;

sam = 10

The first states that joe has the value 1 - that Joe is simply another name for the number "one". The second is an equation rather than an equality. It does not provide any alternative interpretation for the value of sam .

> joe;

1

> sam;

sam

For the moment we simply need to be aware of the fact that an equation is simply two expressions separated by a equal sign. By itself it does not affect the value of either. We can write an equation involving any two experssions .

> 1=2;

1 = 2

Maple will, however, balk at attempts to assign values. For instance the following commands would attempt to redefine the value of 1.

> 1:=joe;

Error, invalid left hand side of assignment

>

> 1:=2;

Error, invalid left hand side of assignment

>

We will have numberous opportunities to take advantage of the fact that Maple can solve equations

> solve(2*x+1=0,{x});

{x = -1/2}

If you understand why it hasn't a clue as to what to do with the following then you probably understand the difference between "=" and ":="

> solve(x+1:=x^2,{x});

Error, `:=` unexpected

>

A command to Maple is always entered at the command

prompt (">") and terminated with a semicolon (";") or a colon ":" .

If a command is terminated with a semicolon then Maple displays the result of its interpretation of the command; if the command is terminated with a colon the Maple output is not displayed .

> 1+2+3+4+5;

15

> 6+7+8+9+10:

>

Multiple commands can be entered at the same prompt:

> front:=[v1,v2,v3,v4];back:=[v5,v6,v7,v8];left:=[v4,v8,v5,v1]; right:=[v3,v2,v6,v7];bottom:=[v3,v4,v8,v7];top:=[v1,v2,v6,v5];

front := [v1, v2, v3, v4]

back := [v5, v6, v7, v8]

left := [v4, v8, v5, v1]

right := [v3, v2, v6, v7]

bottom := [v3, v4, v8, v7]

top := [v1, v2, v6, v5]

Lets get back to our box. We (people) have a concept of an abstract box and we have a sketch which helps us visualize it. We and the computer "know" that there certain symbols, v1...v8 which we (people) call the vertices but this designation has no meaning to the computer. We and the computer know about certain lists of the vertices and have agreed on names for them. We have agreed that certain other lists have the same meaning (when thought of as polygons) but the computer knows only about the specific lists we chose. We can "ask" Maple how it is interpreting a symbol by entering that symbol as a command.

> top;

[v1, v2, v6, v5]

> TOP;

TOP

Lower case "top" refers to the list of symbols it returned. "Top" is simply a string to which no other meaning has been assigned.

Although we can sketch and work with an abstract figure Maple can draw only draw specific figures which we specify specific completely. The polygonplot3d command works with specific, not general lists of vertices. For instance,

> plots[polygonplot3d]([[0,0,0],[0,1,0],[1,1,0], [1,0,0]]);

[Maple Plot]

>

produces a square but

> plots[polygonplot3d]([v1,v2,v3,v4]);

Error, (in plots[polygonplot3d]) incorrect first argument

doesn't know what to do with since the items in the list its given do not represent points in space, i.e. are not themselves lists of three numbers. The solution to this is to tell Maple how to interpret v1, v2, v3, v4 as points in space. This amounts to assigning these names to specific points (or more precisely to sets of coordinates for the points relative to some reference frame). This assignment is totally up to us. We might, for instance have decided that our abstract box is actually the "unit cube" in three dimensions relative to some coordinate system. In that case our sketch might have bee n

[Maple OLE 2.0 Object]


This can be interpreted as assigning values to our previously abstract quantities v1, v2, v3, v4, ... -- something we now know how to do .

> v1:=[1,0,1]; v2:=[1,1,1]; v3:=[1,1,0]; v4:=[1,0,0]; v5:=[0,0,1]; v6:=[0,1,1]; v7:=[0,1,0]; v8:=[0,0,0];

v1 := [1, 0, 1]

v2 := [1, 1, 1]

v3 := [1, 1, 0]

v4 := [1, 0, 0]

v5 := [0, 0, 1]

v6 := [0, 1, 1]

v7 := [0, 1, 0]

v8 := [0, 0, 0]

The computer will assign these meanings whenever it encounters the symbols v1..v8. Since they occur in our previously defined names for the faces, those names now represent specific polygons in space .

> top;

[[1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 0, 1]]

> bottom;

[[1, 1, 0], [1, 0, 0], [0, 0, 0], [0, 1, 0]]

Now we can ask Maple to render visualizations of these faces:

> plots[polygonplot3d](top); plots[polygonplot3d](bottom);plots[polygonplot3d](right);

[Maple Plot]

[Maple Plot]

[Maple Plot]

Of course this isn't satisfactory, we don't want to see the faces separately, we want them all together. To do this we simply give the command the complete list of faces which directs the program to render all of them in the same image :

> plots[polygonplot3d]([top, bottom, left, right, front, back]);

[Maple Plot]

>

This is better but we can't identify front, back, etc. nor does the picture have the "wireframe" format of our sketch. This can be remedied in by asking for axes and altering the plotting style. Left clicking on the image encloses it in a box and creates a "tool bar" of manipulations of the image. The reader should explore the effect of each of the toolbar buttons and should note that the image can be rotated by draging the cursor across it. In addition there are "command line" options corresponding to each of the buttons on the tool bar. We will now explore several of them: style, scaling, and color which will be of immediate use. Each of these is an option for the plots[polygonplot3d] command. The way to learn about a command and its options is through the help system. As noted earlier this can be invoked in a number of ways. When we know exactly what we are looking for the command line approach is the most efficien t:

> ?plots[polygonplot3d];

Note that the "help" page this takes us to describes the command and refers us to other help sheets for further information. We are interested in the options which we are told can be reached by the command ?plot3d[options] or by clicking on that hyperlink at the bottom of the sheet. In either case we reach a page which lists a large number of options. Our main objective at this point is to know that the page exists and how to reach it. A few examples of the use of some of the options generally suffices to give us enough information to work out for ourselves how others are used. Note that the primary plots[polygonplot] help sheet contains some examples. These can be copied and pasted into our work session and executed to see what they do. For now we will apply some of these options to our example. First lets take advantage of our ability to assign short names :

> box:=[top, bottom, right, left, front, back];

box := [[[1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 0, 1]...
box := [[[1, 0, 1], [1, 1, 1], [0, 1, 1], [0, 0, 1]...

Now we can simply have the computer draw "box" - but we want to do this with some of the options. The first changes the plotting style from the default "hidden line" to the "wireframe" format indicated in our rough sketch .

> plots[polygonplot3d](box, style=wireframe);

[Maple Plot]

>

We can color the edges of the frame as we wish. The plot3d[options] refers us to plot[color]

> ?plot3d[options]

> ?plot[color]

Which gives us the following list : 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 - as well as instructions for making our own colors. For now we will stuck with the "off-the-shelf" colors.

> plots[polygonplot3d](box, style=wireframe,color = tan);

[Maple Plot]

The "patch" style allows us to specify a color for the entire box.

> ?plot3d[options]

> plots[polygonplot3d](box, style=patch,color = tan);

[Maple Plot]

The axes option allows us to include coordinate axes in different ways :

> plots[polygonplot3d](box, style=patch,color = green, axes= normal);

[Maple Plot]

When creating a general plot Maple attempts to do the best job it can of placing the entire picture in the space available. In doing so it often scales the coordinate axes so that the image produced does not appear "to scale". The option which turns this off or on is "scaling" which is "constrained" (i.e. to scale) or "unconstrained". The symmetry of our box makes it a poor choice to illustrate thi s but we can readily define other objects such as the following

> skinnytriangle:=[ [-1,0,0], [1,0,0],[0,0,20]];

skinnytriangle := [[-1, 0, 0], [1, 0, 0], [0, 0, 20...

> plots[polygonplot3d](skinnytriangle, style=patch,color = green, axes= normal);

[Maple Plot]

> plots[polygonplot3d](skinnytriangle, style=patch,color = green, axes= normal, scaling=constrained);

[Maple Plot]

An obvious disadvantage of the coloring option as used on our box to this point is that we can specify only one color in a command and therefore our box can be only one color. The solution to this is to "draw" each of the faces separately with whatever color we want and plot them together. To do this we need another command, plots[display] which displays a list of individual plots in the same picture, relative to the same coordinates. Suppose we want our box to have a blue top, yellow sides, and a purple bottom. We can separately construct the pieces with different colors :

>

> bluetop:=plots[polygonplot3d](top, style=patch,color = blue );
purplebottom:=plots[polygonplot3d](bottom, style=patch,color = red);
yellowsides:=plots[polygonplot3d]([left,right,front,back], style=patch,color = yellow);

bluetop := INTERFACE_PLOT3D(POLYGONS([[1., 0., 1.],...

purplebottom := INTERFACE_PLOT3D(POLYGONS([[1., 1.,...

yellowsides := INTERFACE_PLOT3D(POLYGONS([[1., 0., ...
yellowsides := INTERFACE_PLOT3D(POLYGONS([[1., 0., ...
yellowsides := INTERFACE_PLOT3D(POLYGONS([[1., 0., ...

We have not told Maple to draw these items. What we have done is assigned names to the "plot structures", the sets of information needed by Maple to display the images. The command plots[display] accepts a list of such images and displays them simultaneously :

> BT:=plots[display]([bluetop, purplebottom, yellowsides]):

> BT;

[Maple Plot]

If we would like to be able to "see through" the top of our box we could draw the top in the "wireframe" style . To see the frame top we probably need to thicken the blue lines.

> bluetop:=plots[polygonplot3d](top, style=wireframe,color = blue ,thickness=3);

bluetop := INTERFACE_PLOT3D(POLYGONS([[1., 0., 1.],...
bluetop := INTERFACE_PLOT3D(POLYGONS([[1., 0., 1.],...

> plots[display]([bluetop, purplebottom, yellowsides]);

[Maple Plot]

>

Note that the second assignment of a value to "bluetop" redefines "bluetop" to be a wireframe style plot structure. It does not change BT (which still has its solid blue top) since that is an image computed from the previous meaning.

> BT;

[Maple Plot]

>

Exercise : (drawing colored cubes): Have Maple draw a cube on which each face has a different color. Have it draw a cube on which each pair of opposite faces have the same color but no two faces which share an edge have the same color.