Last edited May 12, 2003 by wtbaker@uiuc.edu
Find this document at http://www.ncsa.uiuc.edu/Classes/MATH198/wtbaker/opinstruct.html
Back Home
Back To Project Page

### Permutation and Associahedron Code Explanation:

The functions of illiSkel that have been drastically altered, and those new ones that have been added deserve a bit of explanation. In the creation of both of these objects, there are three main stages. First, the object (wire-frame or solid) must be drawn. Second, the balls at each vertex must be drawn. Finally, the wire-frame rectangular boxes must be drawn around the balls at the vertices (this step only applies to the associahedron). Below is a brief overview of how each of these steps is accomplished in the attached code.

Creating the Polyhedron:

The first step as mentioned before is drawing the polyhedron itself. This is done by the functions drawash() and drawpermut(). The way in which these functions accomplish their tasks is relatively simple. There are two global arrays, one named vertices[] and one named path[]. Vertices[] is an array that holds the 3D Cartesian coordinates of each vertex, and these are hard-coded into the array by the programmer at its declaration. The path[] array is also hard coded, and it contains the path from vertex to vertex to follow in order to complete the polyhedron. It is important to note that this is not a minimum path, it is a path that traverses the object one side at a time, so that if the users desires that the sides have color and not simply be wire-frame, that task is easy to accomplish. The way in which these draw functions use the arrays is very simple. Path[] is looped through until its end, and on each loop a line segment is drawn from one vertex to another until the object is complete. These lines are drawn one side at a time, so that in the event solid sides are requested, a color will be assigned and then GL_POLYGON can be used in place of a line strip.

Creating the Vertex Balls:

The drawing of the shiny spheres that appear at the vertices involves three functions, drawballs(), sballs(), and drawvert(). Of these, drawballs() is the function most responsible for the creation and placement of the spheres, and it is the function that is called specifically in drawall(). Drawballs() moves and creates the spheres by repeatedly doing the following for each vertex. First, drawballs() finds a vector from the center of the polyhedron to a vertex. Next, the unit vector on the same path is found, and this will be used in determining how to move the balls. Finally, drawballs() takes the original length of the vector, and adds a small amount to place a sphere outside the vertex, and then the color of the sphere currently being drawn is sent into sballs() and it creates a shiny sphere of the correct color. In the associahedron the color order will always be the same, however, in the permutahedron drawballs() makes use of the ballorder[] array to determine which color the next ball should be. Sballs() and drawvert() work together to draw the shiny spheres in almost the same exact way as drawtor() and drawvert() do in the illiSkel, in fact, sballs() is near identical to drawtor() and drawvert() is also virtually unchanged. The few changes that were made is that now a sphere is drawn instead of a torus, and illiPaint is no longer used, instead the color is determined by the parameter sent in by drawballs().

Creating the Wire-frame Vertex Boxes (Associahedron Only):

The boxes are drawn and moved into place in the function drawrects(). Similar to drawballs(), this is done through the use of vectors. First, a unit vector is calculated from the center of the associahedron to a vertex. Then drawrects() finds one of the infinitely many vectors perpendicular to the unit vector we found earlier. Finally, a third perpendicular vector is found using the cross-product of the two vectors found earlier. These three vectors are then used together to draw the boxes around the spheres. A brief explanation of how the boxes know where to go should be given. There is an array parens[] that stores how the boxes should be arranged for each vertex. Each row of parens[] represents one long string of 1's, 2's and 3's. The 1 represents a ball, a 2 represents the start of a box and the 3 represents the close of a box. For example 12211321133 would equate to O((OO)(OO)), where O is a ball. Drawrects() reads the values from the right to the left, when a 3 is encountered, its position (in terms of which ball is before or after) is pushed onto a stack. Then drawrects() continues to the left until it finds a 2, when it does it pops a position of the stack, and then draws a box from its current position to the position that was just popped off the stack.