Home > Degrafa, Flex > Degrafa Plottable Catmull-Rom Spline

Degrafa Plottable Catmull-Rom Spline

July 24, 2009

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.

Categories: Degrafa, Flex Tags: , ,
  1. July 27, 2009 at 5:36 am

    Awesome🙂 However, does it should look like that?

    • July 27, 2009 at 6:23 am

      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

  2. July 27, 2009 at 4:30 pm

    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

  3. July 28, 2009 at 3:58 am

    Always glad to help, keep on doing great job🙂

  4. July 29, 2009 at 6:58 am

    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

  5. July 30, 2009 at 6:33 am

    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

  1. No trackbacks yet.
Comments are closed.
%d bloggers like this: