Home > Degrafa > Degrafa Catmull-Rom Spline Utility

Degrafa Catmull-Rom Spline Utility

July 6, 2009

The Degrafa spline architecture has been modified to structurally achieve the desired sepration between the computational elements of a spline and the internal Degrafa geometry pipeline.  This is illustrated by the new NaturalCubicSpline.  In MXML, the spline is treated as before,

<NaturalCubicSpline id=”cubicSpline” graphicsTarget=”{[splineLayer]}” knots=”104,299 166,168 217,236 307,225 370,142 440,299 506,309″ >
<stroke>
<SolidStroke weight=”2″ color=”#0000FF”/>
</stroke>
</NaturalCubicSpline>

The actual Degrafa code is

public class NaturalCubicSpline extends BasicSpline
{
 private var _cubicSpline:PlottableCubicSpline;
 public function NaturalCubicSpline( _myPoints:Array=null )
 {
  super(_myPoints);
  _cubicSpline = new PlottableCubicSpline();
  super.spline = _cubicSpline;
 }

 override public function eval(_x:Number):Number { return _cubicSpline.eval(_x); }
 override public function derivative(_x:Number):Number { return _cubicSpline.derivative(_x); }
 }

The computational basis for the spline is in the PlottableCubicSpline class which implements the IPlottableSpline interface.  The integration into the Degrafa geometry pipeline is handled by BasicSpline.  The basic idea is to supply an external utility that conforms to an established interface to handle the spline computations.  A reference to the utility is used to ‘decorate’ BasicSpline in a simplistic sense.  This makes it possible for people to author splines for Degrafa without having to understand much about Flash or the internals of Degrafa.

Currently, BasicSpline is only functional for cartesian splines.  To preparare a set of test cases for parametric splines, the old Singularity Catmull-Rom spline has been ported to Degrafa as two utility functions.  One is a straight Catmull-Rom spline (with auto-closure) that conforms to the IPlottableSpline interface.  The other extends the base utility to include approximate arc-length parameterization for use in path animation or keyframing (where the path is not intended to be drawn).

A simple demo is available to illustrate the utility.  Click in the draw area to define a few points, then hit the space bar.  The spline is plotted old-school (point-to-point) to illustrate the path.   A set of markers is distributed along the path at roughly equal intervals of arc length.  A Degrafa ellipse is drawn and animated along the path.  The ellipse is also oriented to follow the path.  A screen shot is shown below.

Degrafa Arc-Length Parameterized Catmull-Rom Spline

Degrafa Arc-Length Parameterized Catmull-Rom Spline

Like I said, it’s a pretty simple demo, but it should give you an overview of how to use the new utility.  An SVN update is required if you want the new source.

View demo.

View source.

Categories: Degrafa Tags: , ,
%d bloggers like this: