-
Notifications
You must be signed in to change notification settings - Fork 6
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
Spline from fit_from_points
has discontinuity
#28
Comments
The algorithm can detect corners, so it's not unexpected that sometimes it will produce two curves where the tangent at the end of one does not match the following curve. In this case, you've specified a maximum error for the fit of 1.0, but only provided coordinates that align on integer boundaries, so there are some corners - there probably aren't a sequence of 'smooth' curves that can match these points to that level of accuracy. That looks like this: You can decrease the accuracy of the fit to match the accuracy of your samples. For example, with a maximum error of 3.0, you'll get this: Another approach would be to filter the input to reduce the noise and then use a higher level of fit. For instance, applying a gaussian filter to the input of the fitting function and a maximum error of 0.5 would create a result like this: Averaging together neighboring points would also smooth out the results a bit, but a gaussian filter provides considerably more control over the result. I've put the code I used to generate these examples here: https://github.com/Logicalshift/flo_curves/blob/v0.8/demos/curve_fit/src/main.rs The fitting function isn't really doing anything incorrect in the first case, though: it's meant to detect sudden changes in direction and interpret them as corners, and with a small error your data set has a lot of changes in direction. |
Thanks for the explanation! I really like the Gaussian filter idea. On my end I've been filling the discontinuity by connecting them with a line, but that might not make sense for the library to do internally. As you said, it indicates that my points need some preprocessing anyway. P.S. Thanks for the library. It's the best bezier curve fitter I've found. |
There are sometimes discontinuities in the bezier spline given from
Curve::fit_from_points
. I expect the spline to consist of connecting curves. Since the spline does connect most of the time, I think it must be a bug when it isn't connected.I've attached an example with points that trigger this bug with
flo_curves = "0.7.2"
.The output is:
The text was updated successfully, but these errors were encountered: