# CompGeoJS Natural Cubic Spline

As I alluded to in the prior post, it is necessary to temporarily alter the direction of the CompGeoJS project to suit some near-term requirements, particularly in the area of data visualization and analysis. I will also be dividing the library into an open-source version and a clients-only version. The latter contains IP and advanced capability for which clients specifically expect a greater degree of control and assurance that such capability will not later become open-source.

So, I have temporarily diverged from the Bezier curve development and moved to the natural cubic spline. This spline interpolates a set of control points with increasing x-coordinate values. The spline is piecewise-cubic and represents (provably) the smoothest interpolator for the control points with a piecewise cubic curve.

I first programmed this spline implementation in a Numerical Analysis course in the 1980’s in Fortran. Wow, I really am old Since that time, it has seen implementations in C, C++, Java, and Flash Actionscript. It is now available in Javascript.

The Natural Cubic Spline demo illustrates basic usage of the spline. The non-minified Javascript source is available for you to deconstruct the application. If you are interested in the underlying math, you might find this white paper beneficial.

The advanced version of CompGeoJS (for clients only) currently contains methods to approximate the cubic spline with a sequence of quadratic Bezier curves. Arc length of each quadratic Bezier segment is efficiently computed during the approximation process and recorded along with each Bezier. An auxiliary array containing the list of quads that comprise each segment of the cubic spline is also recorded. This technique is very useful for fast rendering and supplemental analytics.