Skip to content
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

interpolateMonotone #52

Open
danburzo opened this issue Apr 10, 2018 · 2 comments
Open

interpolateMonotone #52

danburzo opened this issue Apr 10, 2018 · 2 comments

Comments

@danburzo
Copy link

danburzo commented Apr 10, 2018

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:

screen shot 2018-04-10 at 13 11 08

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?)

@RenaudF
Copy link

RenaudF commented Jul 27, 2018

I was looking for that too, would be a great addition, along with the other interpolation functions in https://bl.ocks.org/emmasaunders/f7178ed715a601c5b2c458a2c7093f78 that seem to be readily available for svg lines in d3.

@einarpersson
Copy link

I came looking here for a monotone interpolation implementation as well. :/ Since there existed a monotone curve option in d3-shape I expected it to be available in d3-interpolate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants