Thursday, March 12, 2009

Improved smooth curves in javascript: now with more smoothiness

I just updated the smoothcurve.js library at github (first blogging) because I had a few mathematical insights.

I decided to drop out any emphasis on doubly differentiable curves: those polynomials are still supported but they seem to offer very little extra. More importantly I added a 3rd method to determine the slopes at various points. I think the result is smoother curves.

Previously I was using a sort of heuristic to attempt to force the interpolation curves to fall strictly inside the rectangle defined by the data points. This is the method used in type 2 smoothing. Type 3 is actually guaranteed to remain with in this box (unless I made a mistake in my math). This is done by making sure the slope is always less than 3 times the slope of the diagonal of the rectangle.

Smooth data i is the curve generated with type i where type 1 is basically catmull-rom, type 2 is my first attempt, and type 3 is the new smoothing type.

Update: Added the ability to use the new smoothing technique without respecting local maxima and minima (which I call sanity).

First, here is an example with a small fixed data set to see the differences (or you can go to the page if the iframe doesn't work for you).

And here is the large set of random data (and here is the page).

No comments: