-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
I've experimented with monotone cubic interpolation (as per the Steffen method you reference in d3-shape) and with the array values being evenly spaced, the formula is quite simplified, as long as I read the paper correctly:
const monotone = (t1, h, v0, v1, v2, v3) => {
let h2 = h * h;
let t2 = t1 * t1;
let t3 = t2 * t1;
let s20 = (v2 - v0) / (2 * h);
let s31 = (v3 - v1) / (2 * h);
let s21 = (v2 - v1) / h;
return (
(s20 + s31 - 2 * s21) / h2 * t3 +
(3 * s21 - 2 * s20 - s31) / h * t2 +
s20 * t +
v1
);
}where h = 1 / n, t1 = t - i / n and i, n, and v0...v3 being computed the same as with the basis spline.
I tried it for the purpose of color interpolation, although it turned out to be of questionable usefulness, at least in RGB:
Nevertheless, if you think it would be a good addition to d3-interpolate, I'm happy to make a PR. (Could be useful for animations, since it smoothly interpolates the data points?)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
