-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
closed interpolation outside [0, 1]? #91
Comments
Oops? This chart left we wondering if this was really a "monotone cubic" interpolator… as it overshoots in X and Y. So I think there is a small mistake here, the function is a standard cubic not a monotone cubic? |
Thanks for bringing this up! I'll have to get back to speed, but the spline should be implemented based on this paper that
The culori/src/interpolate/splineMonotone.js Lines 3 to 18 in a846314
...should implement the equations (1) – (7) from page 445 (3 of 8 in the PDF). However I can't remember how I derived It does indeed seem the code produces a non-monotone result. As for the initial issue you raised, I had t pinned to I'll take a look and get back, thanks again! |
In culori/src/interpolate/splineMonotone.js Lines 23 to 45 in 8e64a25
(I changed the variables a bit so I can better keep track of Basically I had forgotten to apply equation (11) from the paper. I still need to add some tests for the spline, but adding it to the Observable notebooks seems to indicate the problem is fixed. |
I've given closed splines further thought and I'm convinced at least the monotone one needs adjustments. What follows is me talking out loud :P A basis spline can be clamped (the default), open, or closed. It's only for the clamped version that we have the property that Now, for interpolating splines (such as the monotone spline):
And, since the goal is to be able to swap a linear interpolation with a spline interpolation seamlessly, does that mean that piecewise-linear interpolation also needs a "closed" concept? And, is "closed" as a term too closely tied to the B-spline? Should it be called cyclical or something to that effect? Part of my problem with color interpolation is that I can't find a good abstraction to allow all the possible combinations without spelling them out explicitly and duplicating implementations (see #80):
|
|
I guess parallels from basis splines to other splines are not too far-fetched; in d3-shape they're implemented with the idea that in the open version of an interpolating spline (cardinal, Catmull-Rom), you "sacrifice" the first and last value in the array to be used merely as control points (to adjust the curve's slope at either ends) without having the curve pass through them. That would work equally well for the monotone spline. But yeah, I'm not sure if they're that meaningful / useful when interpolating colors specifically...
I've tried to solve this by tentatively introducing interpolate: {
h: interpolateLinear(interpolateHue),
c: interpolateLinear(),
l: interpolateLinear(),
alpha: interpolateLinear(interpolateAlpha)
} However, the API strikes me as a bit convoluted.... |
I wanted to use the closed interpolator outside [0,1], so in principle I thought it would be periodic; but in fact its domain is [0, 1 + 1/n], and it "crashes" outside.
Here's how I "fix" this:
now the domain of culoriClosed is [0, 1] (we have a complete curve if t in [0, 1]), and we have f(t + integer) === f(t).
https://observablehq.com/d/f2e94a3321c17726 draws a spiral with -5 < t < 30, and the main domain as a loop, in heavy black.
The text was updated successfully, but these errors were encountered: