Maple and Geogebra

10Mar09

Exhibit A: Maple, a sapling of the University of Waterloo. It is a computer algebra system allowing you to perform both symbolic and numerical computation. It has lots of built-in “packages” including one called GraphTheory, and other people can design add-on packages as well, such as convex (for polyhedral combinatorics, related to linear programming).

Exhibit B: Geogebra, a graphical dynamic algebra/geometry program. It hearkens back to the days of Geometer’s Sketchpad and Cabri Geometry. The idea is that “compass and straightedge”-like constructions are automated and made dynamic. Example: to construct an equilateral triangle on base AB, use the circle tool to draw a circle centred at A through B, and one centred at B through A, then their intersection C makes ABC equilateral. Then drag A or B, and watch C magically update as you go. Geogebra is even more awesome because it is free, and because it can create high-quality graphics suitable for publication.

I was recently using Maple to do some polyhedral combinatorics on graphs; but Maple is pretty bad at making nice pictures of graphs. Borne of this need, I wrote a Maple procedure which exports to Geogebra (which is in turn an .xml file that has been .zip compressed) – vertices are points, and edges are line segments. I’m posting my sketchy code below in case it is somehow useful to a future searcher (thanks google!) but first, the pretty pictures resulting from these hijinx!

10-Vertex Extreme Point Solution

30-Vertex Extreme Point SolutionBuzzwords to describe these pictures: extreme point solutions for the parsimonious undirected cut relaxation of the spanning tree polytope. These solutions (pictured on 10 and 30 vertices) are special because they have high (support) degree and high denominator (the |V|/2th fibonacci number).

Code follows the jump

ExportGraphToGGB := proc(G, x) local fd, n, i, s:
fd := fopen("c:\\tmp\\geogebra.xml", WRITE);
fprintf(fd, "<?xml version=\"1.0\" encoding=\"utf-8\"?><geogebra format=\"3.01\"><gui><show algebraView=\"true\" auxiliaryObjects=\"false\" algebraInput=\"true\" cmdList=\"true\"/><splitDivider loc=\"250\" locVertical=\"400\" horizontal=\"true\"/>	<font  size=\"12\"/></gui><euclidianView>	<size  width=\"500\" height=\"500\"/>	<coordSystem xZero=\"250\" yZero=\"250\" scale=\"15\" yscale=\"15\"/>	<evSettings axes=\"false\" grid=\"true\" pointCapturing=\"2\" pointStyle=\"0\" rightAngleStyle=\"1\"/>	<bgColor r=\"255\" g=\"255\" b=\"255\"/>	<axesColor r=\"0\" g=\"0\" b=\"0\"/>	<gridColor r=\"192\" g=\"192\" b=\"192\"/>	<lineStyle axes=\"1\" grid=\"10\"/>	<axis id=\"0\" show=\"false\" label=\"\" unitLabel=\"\" tickStyle=\"1\" showNumbers=\"true\"/>	<axis id=\"1\" show=\"false\" label=\"\" unitLabel=\"\" tickStyle=\"1\" showNumbers=\"true\"/>	<grid distX=\"2.0\" distY=\"2.0\"/></euclidianView><kernel>	<continuous val=\"false\"/>	<decimals val=\"2\"/>	<angleUnit val=\"degree\"/>	<coordStyle val=\"0\"/></kernel><construction title=\"\" author=\"\" date=\"\">");
n := NumberOfVertices(G);
for i from 1 to n do
  fprintf(fd, "<element type=\"point\" label=\"V%d\">	<show object=\"true\" label=\"false\"/>	<objColor r=\"0\" g=\"0\" b=\"255\" alpha=\"0.0\"/>	<labelMode val=\"0\"/>	<animation step=\"0.1\"/>	<fixed val=\"false\"/>	<breakpoint val=\"false\"/>	<coords x=\"%e\" y=\"%e\" z=\"1.0\"/>	<coordStyle style=\"cartesian\"/>	<pointSize val=\"3\"/></element>", i, 10.0*cos(2*Pi*i/n), 10.0*sin(2*Pi*i/n));
end:
for i from 1 to nops(Edges(G)) do
  s := cat("E", i, "n", numer(x[i]), "d", denom(x[i])):
  fprintf(fd, "<command name=\"Segment\">	<input a0=\"V%d\" a1=\"V%d\"/>	<output a0=\"%s\"/></command><element type=\"segment\" label=\"%s\">	<show object=\"true\" label=\"true\"/>	<objColor r=\"0\" g=\"0\" b=\"0\" alpha=\"0.0\"/>	<labelMode val=\"0\"/>	<breakpoint val=\"false\"/>	<lineStyle thickness=\"2\" type=\"0\"/>	<eqnStyle style=\"implicit\"/>	<outlyingIntersections val=\"false\"/>	<keepTypeOnTransform val=\"true\"/></element>", Edges(G)[i][1], Edges(G)[i][2], s, s);
end:  
fprintf(fd, "</construction></geogebra>");
fclose(fd);
system("c:\\Progra~1\\7-Zip\\7z.exe a c:\\tmp\\new.zip c:\\tmp\\geogebra.xml");
system("del c:\\tmp\\geogebra.xml");
system("move c:\\tmp\\new.zip c:\\tmp\\new.ggb");
system("c:\\tmp\\new.ggb");
return NULL:
end:
Advertisements


One Response to “Maple and Geogebra”

  1. Hi Dave. I have created a lot of GeoGebra tutorials here:

    http://math4allages.wordpress.com/view-posts-by-topics/

    You may want to check it out.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: