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

Finding close point on CubicBezierSegment #877

Open
andrewvarga opened this issue Sep 25, 2023 · 3 comments
Open

Finding close point on CubicBezierSegment #877

andrewvarga opened this issue Sep 25, 2023 · 3 comments
Labels

Comments

@andrewvarga
Copy link

I'm curious what's the best way to find the closest point on a bezier segment given a point. It seems there is no utility function for this currently.
Eg. bezier.js has a method project which does this.

@nical
Copy link
Owner

nical commented Sep 25, 2023

Sounds like a useful addition to lyon_geom. I haven't looked into it yet so I don't have an answer to the question of the best way to do this, but bezier.js appears to do a rather simpler search through the t parameter of the curve.

@nical nical added the feature label Sep 25, 2023
@nical
Copy link
Owner

nical commented Sep 25, 2023

Huh, I just remembered I already implemented something for quadratic bézier segments: https://docs.rs/lyon_geom/latest/lyon_geom/struct.QuadraticBezierSegment.html#method.closest_point

It's actually an analytical solution. Certainly more difficult to solve for a higher degree but it might still be possible to use a similar approach. The insight is that the tangent at the closest point on the curve is necessarily perpendicular to the line going from the reference point to the closest point.

@andrewvarga
Copy link
Author

Huh, I just remembered I already implemented something for quadratic bézier segments: https://docs.rs/lyon_geom/latest/lyon_geom/struct.QuadraticBezierSegment.html#method.closest_point

It's actually an analytical solution. Certainly more difficult to solve for a higher degree but it might still be possible to use a similar approach. The insight is that the tangent at the closest point on the curve is necessarily perpendicular to the line going from the reference point to the closest point.

Thank you, that sounds useful. So maybe I can estimate my cubic with a quadratic and use that, or implement something similar for cubic. At first look just searching through t doesn't seem too bad either, but this is certainly more elegant.

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

No branches or pull requests

2 participants