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

curveCubicX? #118

Open
danburzo opened this issue Mar 5, 2018 · 1 comment
Open

curveCubicX? #118

danburzo opened this issue Mar 5, 2018 · 1 comment

Comments

@danburzo
Copy link

danburzo commented Mar 5, 2018

Issue was originally in d3-interpolate#49

I'm proposing the addition of a new type of curve for d3-shape — aptly called curveCubicX by @mbostock on the original thread — that treats the Y coordinate as a function of the X coordinate, such that for any X coordinate there's a single corresponding Y value.

In the image below, the proposed curveCubicX in comparison with curveNatural and curveBasis:

36937290-cffd7590-1f19-11e8-82ce-8ede07b6e619

(the cubic curve is generated with a cubic spline interpolator through small line segments joining 1000 samples of <x, f(x)>)

The algorithm for the interpolator is described on Wikipedia (also of note is its talk page, which makes it apparent that the page suffered various incarnations of the algorithm, of various readability levels).

There are also some demos and implementations of the algorithm:

However, these are all oriented towards finding the interpolator function, and any SVG paths are drawn with sampling the function, and I am severely out of my comfort zone in regards to obtaining the Bézier control points needed to draw the SVG path, so I'm hoping for some pointers or ideas on the matter...

As for the utility: I started with trying to recreate the Curves interface in Adobe Photoshop, which seems to be using such a cubic spline to interpolate the values. For data visualization, on the one hand it maintains Y being a function of X which makes sense in most types of charts, and the spline does pass through all the points, but on the other hand it tends to overshoot much more than other types of curves.

@danburzo
Copy link
Author

danburzo commented Mar 6, 2018

Back from the field: I could not find any literature on how to implement this as a Bézier spline (it's possibly hidden in terms/explanations I don't understand) — but I did manage to independently re-implement curveNatural and curveBasis based on this explanation :). Unfortunately I'm lacking the theoretical foundation to have any intuition on how to use the algorithms for parametric splines (descriptions of which abound) to a non-parametric (explicit) spline... hopefully someone on Math StackExchange has some ideas.

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

1 participant