-
Notifications
You must be signed in to change notification settings - Fork 9
Improve B-spline approximations #67
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
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅ 📢 Thoughts on this report? Let us know! |
|
One tricky thing is getting the curvature of a BSpline offset. Because the underlying BSpline has non-constant curvature, a derivative of that curvature appears in the offset curvature. The current version ignores that term. This calculation is only needed to get the exact curvature of an OffsetSegment, which is only used for choosing discretization points (right now only used to see how often to sample for B-spline approximation). Not to mention that users like to avoid sharp turns, and the default tolerance 1nm is usually overkill anyway. So it seems fine not to be exact. Of course these are just cubic functions, so we can get a third derivative of the spline itself (constant weights between pairs of waypoints!) and just write down the derivative of the curvature. Not sure it's worth it but we've gotten this far. ForwardDiff would be simple but doesn't play well with Unitful. (There's also one other missing term still.) |
dc062c5 to
553f041
Compare
|
BSpline curvature derivative would look like this: This agrees very well with finite differences. But it doesn't seem to make the BSpline offset curvature calculation more accurate, so there may be a mistake in how I tried using it (now commented out). As noted above I don't think this is a practical concern, so I will leave it for now. |
|
A few other things ended up riding along in the course of implementing/testing the change to BSpline approximation:
|
simlapointe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code looks good, nice job! I also tested it on more paths from my clipped designs that used to require a lot of points and it worked well for all of them.
Implements #23.
Using multiple B-splines (and so setting tangents at intermediate points) works much better than creating extra waypoints. Haven't benchmarked time but the goal was to reduce entity counts, and for typical curves this is down to 20 segments from over 100, with typical times around 10ms on my laptop. It's still possible to get very slow (1s) approximations with 50 or 60 segments with tight turns on offsets of long B-splines. That may be because calculations (like approximation error) tend to be easiest and most accurate when the curves are roughly arclength parameterized and have slowly-varying curvature, which isn't so true when the radius of curvature is comparable to the offset.