Degrafa Natural Cubic Spline

Spare time has been in short supply lately, so this has moved slowly.  Just committed the new files to SVN.  The natural cubic  spline is now plottable in the Degrafa geometry pipeline and can be described directly in MXML.   A sample description looks like

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

In talking with people who might actually use this capability in math/science visualization and charting applications, one of the requests was the ability to easily highlight ‘vertical strips’ or sections of the area above/below a spline in between knots.

Any spline that will be eventually integrated into Degrafa will return a quad. Bezier approximation to the spline. Since the large majority of splines are expected to be purely interpolative, the algorithm ensures the approximation is exact at the knots. An index array is returned that provides the index to the raw quad. Bezier data at the beginning of each knot.   A sample highlight is illustrated in the following diagram.  Each ‘section’ highlight is a small number of lineTo() and curveTo() calls.

Highlighting area under a natural cubic spline
Highlighting area under a natural cubic spline

A simple demo was created to illustrate this highlighting.  In order to get the demo out quickly, a lot of stuff was hardcoded.  So, one useful exercise would be to make the code more general-purpose.  Click on the numeric stepper to shift the highlight from section to section.

In the near future, I will release another method that returns a quad. Bezier sequence that approximates the spline in any interval [x1,x2], x2 > x1 (for a cartesian spline).  This will enable an even greater set of charting/visualization applications.   There is still some work to be done on the internal architecture, but the long-term goal is the ability to integrate a wide variety of splines into Degrafa with minimal effort and little, if any, understanding of the internal geometry pipeline.

View demo

View source