Parametric Rendering On The Web

Abstract

This report details the design and problems encountered in the creation of a web-page which graphs parametric equations. The web page utilizes the HTML form fill-out capability to interface with a C program (known as a CGI script), which then interfaces with Matlab's External Engine to render the graph. The C program creates a new web page which displays the graph, as well as supplying an additional form fill-out to transform (translate, scale, and rotate) the image. This form then interfaces with a second C program, which also uses Matlab to render the transformed graph. The transforming can repeat ad nauseum. 27 different kinds of two and three dimensional graphs can be plotted, as well as myriad plot options, to provide the user maximum flexibility. Due to the interface with Matlab, the user must use Matlab syntax to enter the equations. A tutorial is provided for those users not familar with it.

My project can be found here.


The Goal

The goal of this project was to create a web page, which could graph parametric equations (and secondarily transform the resulting graph), and could be usable by anyone with any web browser and from any computer.


Approaches

My first decision was to decide what tools I would use to design such a page. It appeared there were two options open to me:
  1. Create the page using Java.
  2. Use a CGI (Common Gateway Interface) C program which then interfaces with a graphics engine, such as Matlab's.
After researching the first option, I discarded the idea of using Java because one of the goals of the project was that any web browser on any computer should be able to display the image. This may very well be true in a few years, but for the present, Java is not omnipresent. A Java viewer has not, for example, come out for the Macintosh yet. Besides, even if the Java viewer is made for a computer, that does not necessarily mean everyone who owns that computer will have the Java viewer.

The essential difference between a CGI Script and a Java applet is that CGI programs run on the server, whereas Java runs on the web browser's computer. Therefore, with a CGI program, it does not matter what platform the browser is on. Matlab has a powerful external interface, capable of all the needs of this project, which CGI scripts can use. My decision was made.


The Early Design Stages

CGI scripts can be used for a variety of purposes; however, the most common one is for reading HTML form submissions. An HTML form allows the user to make choices and enter arbitrary text. These choices are represented as variables, and the whole set of variables, both name and value, are passed as environment variables to a CGI script which can read them.

I first set out to find a sample CGI Script form reader, the creation of which is not a trivial task. Since the external interface with Matlab is intended for C or Fortran use, I set out to find the C code for such a program (most CGI Scripts are written in Perl, since the variables are passed as strings). I used the code I found to create a sample form fill-out, a music survey. The variable parser used in that script proved indispensable to my later project.


Usage Of The Matlab External Interface

The Matlab external interface is very elegant in its simplicity, while retaining the power of the whole language. Essentially, it works by spawning a Matlab process, which can then be communicated with by sending strings to it to be evaluated as if they were actually being entered at Matlab's command prompt.

The user interface of my project took shape as one in which the fancy details of plotting, such as the colors involved and the line styles, would be presented via menus and radio boxes, but the actual equations to be plotted would be kept as strings and sent directly to Matlab to be evaluated as is.

From there, Matlab would plot the desired graph, and perform the gif conversion. It would also save all the variables in a workspace file, to be loaded again for the transforming program's use if necessary.


Capabilities/Examples Of The Graphing Page

16 types of one-parameter equation plots and 11 types of two-parameter equation plots can be chosen. There is a surface plot which takes into account lighting, and another which shows surface normals. What follows are some examples of these:

Equations entered for a surface plot:

Equations entered for a surface with lighting plot:

Equations entered for a surface with normals plot:

The capabilities, explanations, and examples of every type of graph and every plot control feature are detailed in Graph-It's extensive on-line help


Capabilities And Theory Of Transforming Page

The transforming form utilizes the following equations: The user is offered the option of keeping the axes as they were before the transformation; otherwise the only transform which changes the graph noticeably is rotation. Matlab just scales the appropriate axes in the case of the other two.

An example of a transformed sphere (of earlier example 1):


Overview Of The Graphing Program's Execution


Overview Of The Transforming Program's Execution


The How And Why

Many of the steps taken above were in response to problems that deserve further discussion.


The Final Conflict

The last task of my project was to move the project from the Sunlab machines, where it was developed, onto the Theory Center machines. This task turned out to be the most frustrating of all. As far as I can tell, the Matlab External Interface on the TC machines was not set up correctly. Even attempting to run the sample source code that came with Matlab provided core dumps. Thus the transer was not accomplished. This result is disappointing, not only for the question of permanent storage, but also the expectations of faster processing by the more powerful Theory Center machines.


What I Might Have Done Differently


Bibliography And Source Code

"The Student Edition of Matlab, Version 4 User's Guide", MathWorks Inc., Prentice Hall, Englewood Cliffs, NJ 07632, 1995
(although the interface is with the professional version)

"MATLAB User's Guide for UNIX workstations", MathWorks, Inc., 1992.

"3-D Computer Graphics, Second Edition", Alan Watt, Addison-Wesley, 1993

Download the source code
It is made up of six files:

Note that the paths set up in the Makefile for Matlab are for the Sunlab.