Points were to be entered using a left click of the mouse, existing points could be reomved with a right click on a point. Points could be moved by left clicking and dragging them.
The tension of a cardinal spline was to be set with the +/- keys.
We were allowed to use the SVL library to support our program.
Implementation
I went a little overboard in the program, partially because of initial
conceptual difficulty and problem in understanding the assignment. In
addition to the two curve types specified, I added the ability to draw
hermite curves complete with the ability to modify the slope lines.
Because there were two different ways to plot curves, using the matrix method for everything and also expanding the matrix to get equations, I demonstrated them both. The hermite and cardinal splines use matrix math via SVL while the bezier curve uses expanded equations. For the straight lines, it should be obvious that no iteration was needed.
I was a little unclear on what was meant by inputing line segments for cardinal cubic splines. Thus I chose to do it as described by Alvy Ray Smith, where the slope is based on the two adjacent points. Thus for the cardinal cubic spline, the first and last points are not connected to the curve. When a point is included in the curve, a line is drawn showing the slope at that point in the curve.
For a Bezier curve, the curve begins when two points are plotted. As opposed to the Cardinal where the first and last points are not included, in the Bezier the only points included are the first and the last points.
The Hermite splines is probably the coolest portion of the program.
In this mode, when you plot a point, another green point also
appears. Use this to select the tangent for the point. Then tension
factor is then used as a scaling factor, this reduces the need to make
the tangents very long to produce desired results. Drag the green
points around to move the tangents.
Compilation and Execution
This program was written, compiled and tested on a RedHat Linux
7.2 system with XFree86 4.1.0. If you're running a different version
of Linux or a different version of XFree86 then you'll want to
recompile the program.
Fortunately when it comes to compilation, I've included a nice
little makefile that will help you compile the program. To use it all
you need to do is type:
Execution of the program is trivial, it accepts no command line
arguments.
Upon execution, the program will display information about each object
in the scene and it will draw the object in a new window with a default
size of 500 pixels by 500 pixels. This window is always mapped to a
coordinate system of (-50,-50) to (50,50) regardless of window size.
Here is a description of the keys available in the program:
$ ./splines
b set drawing mode to bezier curve
c set drawing mode to cardinal spline
h set drawing mode to hermite spline
l set drawing mode to straign lines
+/- increase/decrease tension in 0.1 steps
{/} increase/decrease tension in 1.0 steps
Left click on empty locations adds points
Left click and draw on points moves points
Right click on empty location toggles curve plotting
Right click on points deletes points
Output Results
Here is simple output from each of the four methods of drawing a curve
with the same points:




Longer Curves
This is an example of longer cardinal, bezier and hermite
splines. Note the differences in the curves and their range of
values. See how the tangent value in the Hermite spline generates
vastly different values and how the Bezier curve does not vary nearly
as much.



The Effect of Tension
Below shows the same cardinal curve from above with different settings
of tension.



Miscellanea
This program can also be found at http://patrick.wagstrom.net/projects/cs411/prog4/.
source code
$Revision: 1.4 $