Degrafa Plottable Catmull-Rom Spline

Progress has been slow with regular work and dealing with family issues, but the Degrafa BasicSpline class now supports (interpolative) parametric splines as well as Cartesian.  The previous CatmullRom utility was used to ‘decorate’ BasicSpline to create a plottable Catmull-Rom spline that can be described in MXML.  A screenshot of the basic demo is shown below.

Degrafa Catmull-Rom Spline
Degrafa Catmull-Rom Spline

The Degrafa spline is plotted as a sequence of quad. Beziers in red.  The Catmull-Rom spline utility is used to plot the same spline point-to-point in blue.   As long as any (interpolative) spline utility implements the IPlottableSpline interface, it can be used to create a Degrafa-plottable spline.  The code for CatmullRomSpline is simply

public class CatmullRomSpline extends BasicSpline
{
 private var _mySpline:CatmullRom;
 private var _isClosed:Boolean;

 public function CatmullRomSpline( _myPoints:Array=null )
 {
 super(_myPoints);
 _mySpline = new CatmullRom();
 super.spline = _mySpline;
 _isClosed = false;
 }

 public function set closed(_closed:Boolean):void
 {
 if( _closed != _isClosed )
 {
 _isClosed = _closed;

 // remainder tbd - current utilty supports closure but not 'unclosing' the spline
 }
 }

 override public function getX(_t:Number):Number { return _mySpline.getX(_t); }
 override public function getY(_t:Number):Number { return _mySpline.getY(_t); }
 override public function getXPrime(_t:Number):Number { return _mySpline.getXPrime(_t); }
 override public function getYPrime(_t:Number):Number { return _mySpline.getYPrime(_t); }
}

I’ve got some more work to do on the internals of BasicSpline, but I hope this will make it easy to implement a wide variety of splines in Degrafa.  In particular, I hope it enables people who want to port splines from other languages, but do not wish to dig into the Degrafa internals to easily implement splines in Degrafa.  Or, perhaps, it will just get me committed to the mental asylum.  If only people knew I was already blogging from there 🙂

A note about the demo – there are a fixed number of points used in the point-to-point plot, so it can be a bit grainy for splines with really long arc length.  The Degrafa spline is drawn segment-by-segment.  Click the space bar to compare vs. the C-R utility plotted point-to-point.  I have not yet implemented the closure as I’m thinking about making it close and re-open.  Update SVN if you want to access the source.

View demo.

View source.

Advertisement

6 thoughts on “Degrafa Plottable Catmull-Rom Spline

    1. You’ve found a bug (like I said, this is still a bit experimental and a work in progress). Please send me the point sequence you used to generate that plot so I can arrange a standalone test to diagnose. If you can’t generate a point sequence, I can probably bring the img. into a graphics program and try to read the points off from there.

      thanks for your beta testing,

      – jim

  1. Update: I was able to use your image to create a standalone test with a small number of points that exhibited similar behavior and think I know where the typo resides. Thanks for your helpful test and I’ll post an update again when the bug is fixed and uploaded to SVN.

    regards,

    – jim

  2. Just to keep you updated, I accidentally committed the wrong file to SVN; now you know why they have me in the mental institution in a padded cell 🙂

    In the process of additional testing, however, I uncovered a numerical issue that I’m working to resolve. Depending on my schedule, I hope to have a new version online by sometime next week.

    thx,

    – jim

  3. New files are now online. Still a couple areas I want to address, but it should be incrementally better than the previous – oh no, here come the men in the white jackets to put me back in the padded cell – thx again!

    – jim

Comments are closed.