Math
All the mathematics needed to understand
this program is covered in a
multivariable calculus course (Calc III), though the
program also uses the
Gram-Schmidt process for orthonormalizing a vector basis
(which may
not be covered until Linear Algebra).
The surface that the program graphes
is stored as a two dimensional
array of verticies, where a vertex is an (x,y,z) triplet
of doubles. The
user specifies the surface by defining the x, y, and
z coordinates as
independent functions of s and t, which are the domain
variables. For
example then, x, y, and z could each be of the form:
f(s,t) = As^3 + Bs^2*t + Cs*t^2 + Dt^3 + Es^2 + Fst + Gt^2 + Hs + It + J
The user simply provides the coefficients (the capital
letters above) and
the boundaries of the domain variables s and t.
Then, the program
stores at each element of the array the triplet
x = X(s0, t0); y = Y(s0, t0); z = Z(s0, t0);
where s0 and t0 are proportional to the row and column
indecies of the
array element. And that's the surface as we vary
s0 and t0.
For further convenience, s0 and t0
and a three double array containing
the unit normal to the surface at (s0,t0) are also stored
at that element of
the surface array.
The mathematics behind the tangent
plane are as follows. The general
tangent plane to a surface parametrically described in
s and t at a point
x0, y0, z0 is the span of the two vectors, the partial
of the surface with
respect to s evaluated at the point, and the partial
with respect to t. This
plane is shifted by the x0, y0, z0 vector. The
program stores a piece of
the tangent plane, around (x0,y0,z0), by keeping another
(smaller) two
dimensional array of vertices, where those verticies
are determined by
evaluating linear combinations of the two partials and
shifting by (x0,y0,
z0). Also, for the tangent plane to look like a
square, the program
orthonormalizes the two partials using the Gram-Schmidt
process. For
web resources on calculus, good luck
(my advice is to just pick up a
calculus
or linear
algebra text book).
Rendering
The program has gone through several
stages of development in this
area. Still in the code as of now (though perhaps
commented out) is
rendering thorugh display lists and through gl_Vertex_Arrays.
Basically,
through a clever traversal of the surface array of points,
the program
has gl render either large number of triangles or triangle
strips.
For the mathematics behind the process of
taking 3D points and
outputing a realistic image of a surface (taken from
some point of view,
with lighting, etc.), look into this undergraduate book.
source.zip
This source last compiled in win2k Visual C++. You need glut
to compile, and the glut libs to run it.
See here for information
on putting glut on a win machine. Otherwise, this is pure C++, and
could
just as easily run on SGI. Thank you for your interest and good
luck. Joshua Stough