.bp
.H 1 "Implementation"
.sp
.P
The program was conceived by Professor David Goldschmidt of the Berkeley 
mathematics department during a demonstration by the author of a previous X
application.  The author then proceeded to design 
and implement the program under the
direction of Professor Goldschmidt and with the approval of Professor
Richard Fateman who had referred the author to Professor Goldschmidt.  The bulk
of the work was done during the Spring 1988 semester.
.P
The tools originally available included Sun 3/50 workstations with monochrome 
monitors and
X version 10.  The diagrammatic approach taken fit very the mouse driven 
workstation very well.  X was chosen over SunTools (another window manager
used on the math department machines) because of the portability enjoyed by
X applications.  A deep concern in the implementation was that while
may of the mathematics graduate students and faculty regularly used the
Sun 3/50 computers they used them mostly for text processing and typesetting.
With this in mind much care was take to "bullet proof" the program.  All signals
are trapped and any sort of catastrophic termination of the program results
in the users work be saved in a "panic file".  The prototype would even log
the disaster and its circumstances in a record file in my account and mail
the user a letter describing where they could find their saved work.  The
log file has since been removed since it was considered intrusive though it
did allow the author on several occasions to approach users with "the program
booted you out last night, what went wrong?"  
.P
The program has since been changed into an X11 application (the X10 version
will be allowed to die) and has been expanded to include color support.  This
feature is especially useful when dealing with multiple knots that are
tangled together, though the program is fully functional on monochrome
workstations.  
.P
The original hardcopy was produced by emitting Tektronics drawing commands
and filtering these through a Postscript translator.  This cumbersome method
was used instead of dumping a bitmap image of the screen to make the image
independent of the resolution of the screen (since most monitors are nowhere
near the 300 dots per inch pixel density that is common in laser printers) and
actually turned out to be a tremendous performance improvement over dumping
bitmaps.
The drawings in this paper were emitted directly from the program as PIC 
commands which were then typeset (along with this text) by troff.  Additional 
back ends are planned.  The hardcopy model was made purposefully "stupid"; the
program requires only operations to draw hardcopy:  the ability to draw
a line segment and the ability to draw text at a given location. 
Erasure is not used to draw the undercrossings.
.P
The isotopy lock is based on a natural generalization of the Reidemeister moves.
The reader certainly noticed that the Reidemeister moves took three steps
to straighten the mangled trefoil, where simply erasing the area in question
and redrawing it would obviously have been legal.
In fact it is easy 
to see that all three Reidemeister moves can be performed by erasing
a segment of a knot that involves either crossings that are entirely over
or crossings that are entirely under and redrawing the segment anywhere 
constrained only that it must be entirely over or entirely under the rest of
the knot (depending on if it was originally over or under, a segment that 
didn't cross can be redrawn entirely over or entirely under) or such that it
does not cross the rest of the knot at all and that it does not cross itself.
Since this move is clearly legal and is able to generate the Reidemeister
moves we see that it is necessary and sufficient to generate (by repeated
application) all legal knot transformations.
Every time the user alters a knot the isotopy lock (if activated) checks that
the replaced segment meets the above criteria (actually it relaxes the criteria
a little in allowing the replaced segment to ignore trivial self crossings
of the type shown in the Reidemeister 1 move).  This method was chosen above
the method of pointing at a crossing and specifying what Reidemeister move
to perform because the Reidemeister moves are in no way natural (they were
contrived to prove theorems) and this method of altering the knot would require
that the editor have extensive routing capabilities to draw the new segment
so that it did not introduce spurious crossings.  Also for a mathematician
working on a chalk board the "always over or always under" rule appears to be
the one they actually use.  Thus knotEd would have allowed the user to fix
the example trefoil in one step.
.P
The smoothed curves are actually based on two different spline models.  The
first model treats each line segment as a parameterized arc in 3-space
and fits two 3rd degree polynomials to generate the curve.  The polynomials
are determined such that they match value at the endpoints and such that
the derivative at each endpoint is a line parallel to the line segment
formed by drawing a line form the control point preceding the endpoint to
the control point succeeding the endpoint 
(this method of determining the derivatives
was inspired by memories of the mean value theorem for derivatives from
freshman calculus).  The endpoints of the smoothed curve are allowed to
miss the control points (they can go to a point determined by the weighted
average of the control point and its two immediate neighbors) but they must
hit the crossings (since we don't wish to determine where the splines would
cross we force it) though the bottom string always stops drawing just before
a crossing.  
.P
The second model is again a Hermetian spline and picks its
derivatives in the same way the first one does.  The difference is that this
model insists on hitting all control points and that it fits only one 
polynomial.
This is done by rotating the line segment to be splined so that it is 
horizontal.  In this configuration it is not necessary to parameterize and
y can be a function of x.  The spline is then rotated back into the proper
orientation.  The second model has the advantage that it does not allow 
the splines to cross their selves (they may still spuriously cross each other
if draw too close) or to form cusps.  This model has the disadvantage that
a division is used to compute the derivative ( deltaY/deltaX ) so if deltaX
(in the rotated perspective) is small the derivative can become excessively
large (causing the curve to run away).  The run away can be checked by inserting
an extra control point.
