Home > Degrafa, Flex > Natural Cubic Spline in MXML

Natural Cubic Spline in MXML

May 12, 2009

I originally placed the natural cubic spline (refer to this TechNote) in Degrafa as a utility.  It was not practical to draw the spline as it could only be plotted with small line segments.  With the first version of the spline->Bezier utility near completion,  it is now possible to efficiently draw cartesian splines (y as a function of x, not x,y as functions of t) in the Degrafa pipeline.  Parametric splines (x,y as functions of t) are to be addressed in the future.

The following screenshot illustrates a preview of the upcoming NaturalCubicSpline class,

Natural Cubic Spline Drawn in Degrafa

Natural Cubic Spline Drawn in Degrafa

The MXML for this spline is

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

That’s all it will take to draw a natural cubic spline in Degrafa! For applications where the data points naturally describe a Cartesian function (i.e. curves that don’t loop back over themselves), the natural cubic spline is an attractive interpolation and drawing method.  I can see some application in charting and scientific visualization applications.  If it proves valuable, I’ll work on extending the spline->Bezier utility to parameteric splines.  That would enable efficient drawing of Camull-Rom and parameteric cubic splines, for example.

More to come …

Categories: Degrafa, Flex Tags: , , ,
  1. May 13, 2009 at 2:45 am

    Catmull Rom could be seen as special Bezier-3 spline, and thus with existing methods of approximating Bezier-3 by multiple Bezier-2 segments (didnt you post a demo of such approximation a month ago or so) can already be drawn quite easy.

    • May 13, 2009 at 5:14 am

      The tangent specifications are different, especially at the initial and terminal knots. You really see this when attempting to do a closed-loop implementation of both splines, meaning it would not be a straightforward task to use the existing cubic Bezier spline in Degrafa. In terms of extracting a single cubic Bezier for each C-R segment, there is work that can be done to make the matrices for a single segment comparable. That would not translate directly when moving from C-R to parametric cubic spline, though. If you had a general methodology for approximating *any* parametric spline with quad. Beziers, it is much easier to just use it than attempt to convert every specific type of spline into something you already have. That’s doing more work with little or no potential for re-use and you are suggesting going through two conversion steps instead of just one.

      • May 14, 2009 at 3:42 am

        yes but it’s two easy steps that were already done🙂 e.g., feel free to visit http://makc.coverthesky.com/FlashFX/ffx.php?id=15

      • May 14, 2009 at 4:38 am

        And still irrelevant as it does not address the issue of how to effectively integrate a wide variety of splines, both cartesian and parameteric (as well as non-cubic and non-polynomial) into the Degrafa geometry pipeline and I would always prefer to perform one step instead of two🙂

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