Interactive Graphics Everywhere

This article gives a short introduction to the use of LiveGraphics3D and highlights some of its real-world applications.

by Martin Kraus

There are several platform-dependent software solutions for the interactive presentation of three-dimensional Mathematica™ graphics. However, the non-commercial Java™ 1.1 applet LiveGraphics3D can serve this purpose in any HTML page, and therefore may be viewed with any popular web browser on any platform, i.e., with the majority of modern personal computers. This article gives a short introduction to the use of LiveGraphics3D and highlights some of its real-world applications.

Creating three-dimensional graphics and animations is one of the key features of Mathematica. Dozens of books, hundreds of notebooks and thousands of questions in MathGroup prove the great interest of Mathematica users in the production of graphics. Still more impressive is the popularity of Mathematica graphics in publications, presentations, on posters, clothes, web pages etc. Traditionally, most of these media are restricted to flat and static pictures. Nowadays, however, modern electronic media, e.g., graphics software, the WWW (World Wide Web), and multimedia CD-ROMs, offer new possibilities for the presentation of three-dimensional graphics. In fact, many specialized visualization tools now allow the user to rotate, color, enlighten, clip and modify graphics interactively in ways which were never before available.

Is it possible to use this kind of interactive presentation with Mathematica graphics in the WWW, for multimedia CD-ROMs, and just for the fun of it? The answer is: Yes! It has been done already for more than thousand graphics on hundreds of HTML (HyperText Markup Language) pages with the help of a non-commercial tool called LiveGraphics3D. In this article, the author of LiveGraphics3D gives a short technical description, an introductory explanation of its usage, and an overview of existing applications.

Using LiveGraphics3D

LiveGraphics3D is a small application (a so-called applet) programmed in Java™ 1.1. It is free for non-commercial purposes and can be licensed from Wolfram Research, Inc. for commercial products. As opposed to VRML (Virtual Reality Modeling Language), this Java applet allows the seamless integration of interactive graphics into HTML pages and can be viewed with all popular web browsers supporting Java™ 1.1 (namely Communicator 4.0 or higher, Internet Explorer 4.0 or higher, and others) without the use of plug-ins or other platform-dependent extensions.

However, including really three-dimensional Mathematica graphics on HTML pages is slightly more complicated than the procedure for pictures in the GIF (Graphics Interchange Format) or JPEG (Joint Photographic Experts Group) format. Therefore, a short (and in most cases sufficient) description is given below.

The first step is to download the applet, which is distributed as a Java archive called "live.jar". (See the LiveGraphics3D homepage at http://theorie3.physik.uni-erlangen.de/~mkraus/Live.html or the corresponding MathSource item at http://www.mathsource.com/cgi-bin/MathSource/Enhancements/Interfacing/Web/0209-281. These links also point to the LiveGraphics3D documentation which is much more detailed than this introduction.)

A Graphics3D object must then be created. Here is a simple plot created with the built-in Mathematica function ParametricPlot3D:

paraplot = 
      ParametricPlot3D[{r Cos[ϕ], r Sin[ϕ], 
          Cos[r^2] Exp[-r^2/10]}, {r, 0, 3}, {ϕ, 0, 2  π}]

As illustrated above, ParametricPlot3D returns a Graphics3D object, which is assigned to the variable paraplot.

The second step is to create a file describing the Graphics3D object. This can be done easily with a new function called WriteLiveForm:

WriteLiveForm[filename_,  g_]  :=  
      (WriteString[filename, ToString[NumberForm[InputForm[N[g]],  5]]]; 
        Close[filename]; )

With this definition, the following commands will write a textual description of the plot (its InputForm) into a file called "paraplot.m" in the directory (i.e. folder) "~mkraus/public_html/":

\(SetDirectory["~mkraus/public_html/"]; 

    WriteLiveForm["paraplot.m", \ paraplot]; \)

(Replace the name of the directory above with the one appropriate for you.)

The new file "paraplot.m" should now contain a rather long list of graphics primitives contained in a Graphics3D expression (which is a valid Mathematica expression):

Graphics3D[{Polygon[{{0., 0., 1.}, {0.15789, 0., 0.9972}, {0.14934, 0.051268, 0.9972}, {0., 0., 1.}}], Polygon[{{0.15789, 0., 0.9972}, {0.31579, 0., 0.98516}, {0.29868, 0.10254, 0.98516}, {0.14934, 0.051268, 0.9972}}], Polygon[{{0.31579, 0., 0.98516}, {0.47368, 0., 0.9533}, {0.44802, 0.15381, 0.9533}, {0.29868, 0.10254, 0.98516}}], Polygon[{{0.47368, 0., 0.9533}, {0.63158, 0., 0.88546}, {0.59736, 0.20507, 0.88546}, {0.44802, 0.15381, 0.9533}}], ...

With the Java archive "live.jar" and the graphics description in "paraplot.m", we are now ready to create an HTML page including a LiveGraphics3D applet. The simplest possibility is:

<HTML>
<APPLET ARCHIVE="live.jar" CODE="Live.class" WIDTH=300 HEIGHT=300>
<PARAM NAME=INPUT_FILE VALUE="paraplot.m">
</APPLET>
</HTML>

These HTML commands define a complete HTML page, which should be stored in a file with the ending ".htm" or ".html". This HTML file (which has to be located in the same directory as "live.jar" and "paraplot.m") can be viewed with any web browser supporting Java 1.1. (Do not forget to activate Java in the preferences or options menu of your web browser.) The web browser should display the plot in almost the same way that Mathematica does. (Differences in colors are primarily due to a well-known bug in Mathematica.) However, it is now possible to rotate the plot by dragging with the left mouse button held down. In fact, it is also possible to zoom, strip polygons, let the graphics spin continuously, or switch to stereo graphics. For a detailed description of these features, see the LiveGraphics3D documentation.

Until now, this introduction covered only parametric plots (and Graphics3D objects in general). Using the more popular Plot3D command requires a bit more caution, since Plot3D returns a SurfaceGraphics object instead of the needed Graphics3D object. The conversion, however, is simple, as we only have to wrap the SurfaceGraphics inside a Graphics3D object:

surfplot1 = 
      Plot3D[Cos[x^2 + y^2] Exp[-(x^2 + y^2)/10], {x, -3, 3}, {y, 
          -3, 3}]

surfplot2 = Graphics3D[surfplot1]

WriteLiveForm["surfplot.m", surfplot2];

In order to view the new graphics, of course, the HTML page has to be modified by replacing the filename "paraplot.m" by "surfplot.m".

With this technique, almost any three-dimensional Mathematica graphic may be displayed by LiveGraphics3D. But LiveGraphics3D does not stop here. It also allows the display of animations, bitmap backgrounds, hyperlinks, etc. Again, the interested reader is refered to the documentation at http://theorie3.physik.uni-erlangen.de/~mkraus/Live.html for additional details.

Real-World Applications

No list of technical features demonstrates the usefulness of LiveGraphics3D as well as existing applications do. Currently, the applet is used primarily within educational publications and to present scientific visualization on the WWW.  Examples of the latter are the pages showing Zernike polynomials and Fraunhofer diffraction patterns by James C. Wyant at http://www.optics.Arizona.EDU/jcwyant/math.htm, visualizations of groups, Hopf algebras, pseudo-random numbers, tori coloring etc. by Rick Kreminski at http://www.tamu-commerce.edu/coas/math/FACULTY/KREMIN/kremin.html, a presentation of geological research results by Xinglin Lei at http://www.gsj.go.jp/dER/bussei/aeloc.html, or some three-dimensional color gamut representations  by Patrick Herzog at http://www.ite.rwth-aachen.de/herzog/3D.html.

LiveGraphics3D is also frequently used for educational purposes. Examples in English include the chemistry and dynamics course of the METRIC (Mathematics Education Technology Research at Imperial College) project at http://metric.ma.ic.ac.uk/chem/ and http://metric.ma.ic.ac.uk/dynamics/,  two surface plotting JavaScript applications by Christopher D. Sinclair at http://www.arlut.utexas.edu/~sinclair/plot3D.html and http://www.arlut.utexas.edu/~sinclair/parametric.html, and the WWW version of the "CRC Concise Encyclopedia of Mathematics" by Eric W. Weisstein at http://www.astro.virginia.edu/~eww6n/math/math.html.

The LiveGraphics3D hompage at http://theorie3.physik.uni-erlangen.de/~mkraus/Live.html includes many more sample graphics and lists all WWW pages using LiveGraphics3D of which the author is aware.

The first commercial application of LiveGraphics3D is the forthcoming CD-ROM version of the "CRC Concise Encyclopedia of Mathematics" by Eric W. Weisstein which will include several hundred of three-dimensional graphics and animations. In this project, LiveGraphics3D allows the conversion of the book's contents into real multimedia presentations.

Limitations and Alternatives

Certainly LiveGraphics3D is not the silver bullet to all visualization problems. Especially the extremely ambitious project of Eric W. Weisstein highlighted several limitations of LiveGraphics3D only been partly solved. Most of the remaining limitations are due to the limited performance of Java 1.1, which allows neither state-of-the-art real-time rendering techniques nor an extensive preprocessing of the graphics. In particular, any intersections of graphics primitives cannot be displayed correctly. The same is true for lines lying on the surface of polygons. But even in figures without intersections, the implemented hidden-surface algorithm sometimes fails to produce correct results. In many cases, however, it is possible to compensate for these limitations by preprocessing the graphics with the help of several specialized Mathematica functions (available at http://www.astro.virginia.edu/~eww6n/math/notebooks/LiveGraphics3D.m). The LiveGraphics3D documentation offers a more complete list of limitations and differences between the ways graphics are displayed by LiveGraphics3D and Mathematica.

Due to the limited performance of Java, LiveGraphics3D will never be able to replace more sophisticated (but platform-dependent) visualization tools such as Dynamic Visualizer (Wolfram Research, Inc.), Conix 3D Explorer (Conix Enterprise, Inc.), and MathGL3d (Jens-Peer Kuska). However, there are no other tools currently available which offer a seamless and platform-independent integration of interactive Mathematica graphics and animations into HTML pages. At present, the only serious competitor of LiveGraphics3D in this respect is VRML, which, however, is not yet as well supported by web browsers as is Java. Additionally, the convertion of Mathematica graphics and animations to the VRML format is not yet solved completely. (One of the best converters is VRMLConvert by H. Edward Donley, see http://www.ma.iup.edu/MathDept/Projects/VRMLConvert/; though axes, arbitrary box ratios, and animations cannot be converted.)

What Next?

LiveGraphics3D is constantly being improved. For example, the latest version includes the (platform-independent) option for using archives which have been compressed by the popular zip programs in order to accelerate downloading. Further improvements are already planned. Additionally, the preprocessing of graphics within Mathematica will be one of the main directions for future developments.

Surely interactive presentations of three-dimensional graphics will become still more popular as electronic media start to accompany and even replace traditional media. While Mathematica is a great tool which allows three-dimensional illustrations, visualizations, and animations to be created easily, LiveGraphics3D is in many cases the perfect companion to display these graphics interactively without losing the platform-independence shared by Mathematica and common two-dimensional picture formats.

The success of technologies is usually unpredictable. However, given the enthusiastic reception and widespread use the applet already enjoys, there seems reason to be extremely optimistic.

ABOUT THE AUTHOR

by Martin Kraus

ELECTRONIC SUBSCRIPTIONS

Included in the distribution for each electronic subscription is the file InterGraph.nb containing Mathematica code for the material described in this article.