-
Notifications
You must be signed in to change notification settings - Fork 305
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
Expose interpolation formulas in line() #124
Comments
I think the issue is that d3-shape does not fully implement the curve algorithms itself, it just translates them to Beziers. d3 takes advantage of the fact that svg natively understand Bezier curves. d3 has interpolation for splines which could be used, see |
@andreasplesch even more reason to expose the underlying algorithm, right! |
Most algorithms do not define a line as a function y(x) but in effect as a parametrized, piecewise, spline/Bezier function pointXY(t). So a proposed Therefore, a |
https://talk.observablehq.com/t/obtain-interpolated-y-values-without-drawing-a-line/1796 for a related discussion. |
@andreasplesch if But I don't understand what makes it expensive to find the solution for a piecewise bezier function if you already know all the pieces. Maybe there's something I'm missing? In my mind an algorithm for finding f(x), where f is composed of known piecewise bezier functions could look like this
|
The find t corresponding to x part requires a search, for example by bisection. Depending on the target accuracy this can be somewhat expensive. |
Why? If d3 generated the path, d3 should know the start and end x value for each segment of the path |
Yeah, but it does not know what t corresponds to a given x between the start and end points. |
I don’t have any plans to do evaluation of Bézier curves in this library. This library assumes you have an implementation of CanvasPathMethods (such as a Canvas context or a d3-path instance); it doesn’t evaluate the curves directly. I’d take a look at Bezier.js if you want something at that level of abstraction: https://pomax.github.io/bezierjs/ |
When using curves, it can be cumbersome to derive the actual value that a particular point on a path represents. This information is useful for tooltips, calculating integrals, and sampling data. While the documentation does a great job of citing references for which interpolation algorithms are being used, trusting users to implement them on their own introduces a variety of problems, including
One solution is to use
getPointAtLength()
, but this is complicated, recursive, and computationally intensive. Since d3-shape implements these algorithms, why not share them? This could manifest itself in many ways, includingThe text was updated successfully, but these errors were encountered: