Skip to main content

Module fit

Module fit 

Source
Expand description

Fitting a B-spline to points.

Two jobs that look alike and are not. interpolate makes a curve that passes through every point exactly. approximate makes one that passes near them, with fewer control points than there are points to fit.

§Which one you want

Interpolation is right when the points are exact: corners of a profile, a path a machine must visit. It is wrong for measured data, because it fits the noise as faithfully as the signal, and the wiggles it invents between samples can be large.

Approximation is right when the points are samples of something smoother than they are. It also cannot be told to use as many control points as there are data points; at that ratio the least-squares system is the interpolation system, and calling one function and getting the other is a trap. That case is refused with a message pointing at interpolate.

§Parameterization

Centripetal by default: parameter spacing goes as the square root of the chord, not the chord. Uniform spacing produces visible loops when the points are unevenly spread, and plain chord length overshoots on sharp turns. Centripetal is the standard compromise and is what a CAD user expects a fitted curve to look like.

§Choosing for you

approximate_within is the one that decides: it takes an error target instead of a control-point count, refines its knots where the error concentrates until the target is met, and reports the error it actually reached. The machinery lives in ogeom_geom::fit, where the intersector’s approximation stage shares it.

Enums§

Spacing
How to spread parameters over the points.

Functions§

approximate
Fit a B-spline that passes near the points, with control_count control points.
approximate_within
Fit a B-spline to within a stated error, choosing the knots itself.
interpolate
Fit a B-spline that passes through every point.