Impl ParamCurve, ParamCurveArclen for Arc#378
Impl ParamCurve, ParamCurveArclen for Arc#378waywardmonkeys wants to merge 1 commit intolinebender:mainfrom
ParamCurve, ParamCurveArclen for Arc#378Conversation
|
|
||
| impl ParamCurveArclen for Arc { | ||
| fn arclen(&self, accuracy: f64) -> f64 { | ||
| self.path_segments(0.1).perimeter(accuracy) |
There was a problem hiding this comment.
The 0.1 is arbitrary here - I think accuracy for both is reasonable, though of course the "right" way to do this is careful numeric analysis.
It is true that arc length of an ellipse is tricky, I believe it involves the incomplete elliptic integral of the second kind. It might also make sense to do Gauss-Legendre integration of the norm of first derivative, which is pretty simple and is likely more "bang for the buck" than going to Bézier.
I'm also wondering whether it might make sense to special case the circular case, as I think it's pretty common and also the math is much easier (especially for inverse arc length). But I'm not going to insist on that, as prefer prioritizing making the general case good rather than having a bunch of special cases.
There was a problem hiding this comment.
I was using the same math being used for the perimeter function ... I do think we should improve upon this and also either have this call the perimeter function or have that one call this one.
There was a problem hiding this comment.
I'm proposing a numerical approximation in #381 (on top of @waywardmonkeys's PR). It needs some more work as the error bounds are not yet as I would've expected, but you can take a look already.
This uses an approximation of the arc length using beziers as the analytic solution is quite involved.
060d631 to
e0a54eb
Compare
| center: self.center, | ||
| radii: self.radii, | ||
| start_angle: self.start_angle + (self.sweep_angle * range.start), | ||
| sweep_angle: self.sweep_angle - (self.sweep_angle * (range.end - range.start)), |
There was a problem hiding this comment.
I believe this is not right, I think it should be
sweep_angle: self.sweep_angle * (range.end - range.start),For example, in the case where the range is 0.0..1.0 the subsegment should return the original arc.
This uses an approximation of the arc length using beziers as the analytic solution is quite involved.