Closed facelessuser closed 2 years ago
For fun, here is a more natural B-spline:
Though, as seen in the image above, it passes right through the points, but it does have an overshoot. This can be seen below as well. The white tries to transition to yellow but overshoots out of the gamut. Unfortunately, gamut mapping doesn't cope too well in this particular spot, so this creates a bit of a break.
Monotonic spline from SAO/NASA: https://adsabs.harvard.edu/full/1990A%26A...239..443S. Seems surprisingly easy to understand. Should be nice to experiment with.
Instead of coercing a b-spline into a natural curve, by recalculating the control points, we can probably do a Catmull-Rom curve. Matrix approach here: http://www2.cs.uregina.ca/~anima/408/Notes/Interpolation/Parameterized-Curves-Summary.htm.
Catrom seems to do just as well.
As far as colors go, I can't see a reason not to clamp the colors, or to allow otherwise. The only exception would be if we ever allowed "closed" interpolation, but that would just connect the end back to the beginning.
We were able to get extrapolation to handled in a sane way. Here is Catmull-Rom extrapolating when its boundaries are reached. Ignore the title, it is indeed Catmull-Rom.
Of course, this would require a user to specifically enable it:
Color.interpolate(['red', 'blue', 'green'], method='catrom', extrapolate=True)
This says nothing as to whether extrapolating such an interpolation is helpful or not, but I wanted to make sure when we allow extrapolation with mixing and interpolating that we could make it work with splines.
I'll look into monotonic splines more when I have time. I want to get out what I already have. I need to focus on some other projects.
I think the issue is the monotonic spline monotonic to? In all the examples I've seen, that is to the Y axis...but we are dealing with many colors in 3-D (x, y, z) space (or more). Is there a generalized way to do this? Or are we chasing our tail? I'm okay not bothering with monotonic if we cannot generalize an approach, or waiting to see if someone else knows how to do this properly. I think it would be neat to have, but not a necessity to have. To be honest, only linear interpolation is needed, the rest of the spline implementations are nice to have.
Closing this one in favor of a monotonic specific issue as we've addressed other splines of interest already.
Okay, so we implemented B-spline, which is pretty cool. As I've dug deeper, I realize that all methods have strengths and weaknesses.
B-spline (Proper...natural? Not sure what to call it) would require us to calculate the control points such that they yield our points as the data points. In this one we use the relationship between the control points and the data points to calculate better control points:
This draws the lines right through our points, which is great, but we now have an overshoot issue, not to mention even more overhead to calculate proper control points. I may throw this up as an experimental approach in ColorAide Extras...maybe. I'll have to see generally how practical it is overall. The overshoot is kind of an annoying issue.
There are, of course, other approaches as well, such as Catmull-Rom Curves, and other various algorithms. I may dig into some of these for fun and see how they compare to some other approaches.
There is no strong need to implement any or all of these, and definitely no rush. I'd like to take my time and explore and evaluate these. I think, right now, that B-spline provides a nice alternative to piecewise. We'll finish cleaning up the processing of undefined values in a sane way, and I think we'll have a pretty decent alternative. It will, of course, have more overhead than linear, but mainly that is upfront, pre-calculation work.