Finding close point on CubicBezierSegment
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.
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.
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.
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.