Generating Graphical Input

As mentioned in the introduction, it is not necessary to use Mathematica to develop mathlets with LiveGraphics3D. Theoretically, as long as you have a knowledge of Mathematica's syntax, you can create LiveGraphics3D input files from scratch using any text editor. However, few of us have the patience to calculate 400 vertices, let alone type out a list of 400 polygons, just to display a surface. Realistically, even if you do not use Mathematica, you will still want to avoid creating your input by hand.

One possibility is to create your graphics using some other application, and then use a special program to convert the results into a LiveGraphics3D input file. Two examples of such tools are:

If neither of these tools is suitable, you can use nearly any computer language to produce the input for LiveGraphics3D. The only key is to mimic Mathematica's output. For example, recall the following piece of Mathematica code which was used to construct a cross section of a surface on this earlier page.

(* "xmin," "xmax," "dx," etc. were defined earlier.          *)

ySection = {RGBColor[0, 0, 1], Thickness[0.005], 
                Table[Line[{{i, y, f[i, y]}, 
                            {i + dx, y, f[i + dx, y]}}], 
                      {i, xmin, xmax - dx, dx}]};

To create this output with another language, we can simply use a loop to construct the string

{RGBColor[0., 0., 1.], Thickness[0.005],
      Line[{{-1., y, 2.*2.718^(-1. - 1.*y^2)*y},
            {-0.8, y, 2.*2.718^(-0.64 - 1.*y^2)*y}}],

This can be accomplished by implementing the following pseudo-code; here string means a function which takes a number and turns it into a string:

input = "{RGBColor[0, 0, 1], Thickness[0.005],"

let i loop from xmin to xmax with stepsize dx

   if this is not the first polygon, then input = input + ","

   segment =  "Line[{" 
                 +"{"+string(i)+", y, 2*y*Exp[-"+string(i^2)+"-y2]}," 
                 +"{"+string(i+dx)+", y, 2*y*Exp[-"+string((i+dx)^2)+"-y2]}"

   input = input + segment

end of loop

input = input + "}"

While it might seem inelegant to piece together a Mathematica-style list in this manner, the difficulties are easy to overcome. One of us has created a stand-alone application version of the "Interactive Gallery of Quadric Surfaces," which appeared in this journal as a suite of mathlets on web pages (Rogness, 2005). The application version computes all of the inputs for the parametrized graphics in the gallery at runtime using for loops as described here.

JavaScript is also readily adaptable to this purpose, and provides an opportunity for a truly interactive experience. For example, you can create a web page with a form which allows a student to enter the equations for a parametric surface; the JavaScript code which parses the student's input can also generate the corresponding graph using LiveGraphics3D. For a basic demonstration, follow this link:

Click here to open the Interactive Parametric Surface Plotter in a new window.

For another example, see Amar Junankar's web page, mentioned above. It includes a "Parametric Curve Generator" which allows users to enter the parametric equations of a curve into an HTML form. The page then uses JavaScript to produce the input for LiveGraphics3D, and the curve is displayed in a pop-up window.

Next Page: Advanced Examples

Table of Contents

  1. Introduction
  2. LiveGraphics3D Overview
  3. LiveGraphics3D Input
  4. Parametrized Graphics
  5. Moving Lines and Polygons
  6. Including Text
  7. Labeling Axes and Plots
  8. Animations
  9. Occlusions of Objects
  10. Intersecting Objects
  11. Two-Dimensional Mathlets
  12. Stereo Images
  13. Generating Graphical Input
  14. Advanced Examples
  15. Future Directions
  16. References