msteinbeck / tinyspline

ANSI C library for NURBS, B-Splines, and Bézier curves with interfaces for C++, C#, D, Go, Java, Javascript, Lua, Octave, PHP, Python, R, and Ruby.
MIT License
1.21k stars 209 forks source link

Evaluate spline with chordal error #227

Closed esuig closed 8 months ago

esuig commented 1 year ago

Hello,

this is not an issue, but a request for info.

I have a tinyspline::BSpline in 3 dimension. Is it possible to evaluate it obtaining points that can generate a polyline that will have a given maximum chordal error respect to the original spline? the image below graphically explains what I mean, hope it is clear (the blue one is the original spline, the red one the polyline obtained connecting all the points obtained from the spline).

error

Thank you very much

msteinbeck commented 1 year ago

Hi @esuig,

you probably want to use the ChordLengths class for this. Given a spline, you can create an instance of ChordLengths with:

BSpline spline = ...
ChordLenghts cls = spline.chordLengths(); // default is 200

cls now allows you to map between arc lengths and knots. The precision of the mapping depends on the number of knots to be evaluated when setting the ChordLenghts instance (the argument passed to the chordLengths() method). 200 is the default. You can set this to 500 if you need a very very very very precise mapping. Once you obtained cls, use the method arcLength to obtain the overall length of the spline and lengthToKnot or tToKnot (where t means relative proportion of arcLength) to map between arc lengths and knots. The knots, in turn, can be evaluated with eval or evalAll. This approach also allows you to create a polyline with equidistant points with respect to the spline.

esuig commented 1 year ago

Hello @msteinbeck,

thank you very much for your exaplanation. I'll try to implement what you're suggesting and I'll let you know what happens. It will take a while, since I need to conclude another project first. If you prefer to close the issue I'll reopen to post the results

msteinbeck commented 1 year ago

Could you solve your issue?

esuig commented 1 year ago

Hello @msteinbeck,

unfortunately I did not step into that yet, I'm still working on other things.

msteinbeck commented 1 year ago

Ok, I keep this issue open.

ng-dm commented 2 weeks ago

Hi, as I understand the proposed way to evaluate as polyline will sample the points at even distances along the spline. However, if you want to limit the maximum error/deviation/chordal distance from spline to sampled polyline, you don't really know how often you need to sample the points. And the required sampling distances may differ depending on the shape of the spline, e. g. straight segments need to be sampled less often.

msteinbeck commented 2 weeks ago

Hi, as I understand the proposed way to evaluate as polyline will sample the points at even distances along the spline. However, if you want to limit the maximum error/deviation/chordal distance from spline to sampled polyline, you don't really know how often you need to sample the points. And the required sampling distances may differ depending on the shape of the spline, e. g. straight segments need to be sampled less often.

Exactly.

ng-dm commented 2 weeks ago

Thanks, so I understand that this library does not have routines to perform what this issue asks for? Do you have plans to implement it or maybe know some resources where it is explained how to achieve this?