Skip to main content

Module fit

Module fit 

Source
Expand description

Fitting a B-spline to points, to a stated error target.

Interpolation and fixed-count approximation live in ogeom-algo, and both take a control-point count from the caller. This module chooses it: fit, measure where the fit is worst, refine the knots exactly there, and repeat until the error target is met.

A fit that silently picks its own resolution and reports success is the shape of answer that gets trusted. So the result here carries the error actually reached and whether the target was met, and a fit that ran out of room says so rather than rounding “close” up to “done”.

§Where the knots go

Refinement is where the error is, not everywhere. Splitting every span doubles the control points per round and most of them buy nothing. A curve that is straight for most of its length and tight in one corner needs its knots in the corner. Each round measures the error per span and splits only the spans that exceed the target, so the knot density ends up tracking the curvature, which is where it belongs.

§What the error measures

A fit through bare points (fit_points, fit_points_at, fit_surface_grid, fit_surface_scattered and their siblings) has nothing to measure against but the points, and its error is the distance at the points only. Between them the fit runs as close to the sampled shape as a smooth spline through those samples does, which for smooth data shrinks with the sample spacing, but no number here bounds it. A caller holding the true geometry measures there, or fits with fit_curve_sampled or fit_surface_sampled, whose error covers the points between the samples too and is no less than the widest miss.

§Who this is for

The marching intersector, first: a traced branch is a polyline with a stated chord tolerance, and downstream code wants a curve, so the polyline is fitted to the same tolerance and the result is as good as the trace. But nothing here knows about intersections. It fits points, in three dimensions or two, which is also what a digitized profile or an imported polyline needs.

Structs§

Fitted
What a fit produced.
Sampling
Where fit_surface_sampled starts sampling and how far it may refine.
ScatteredFit
What fit_surface_scattered_over produced.
ScatteredOptions
What fit_surface_scattered_over fits with.

Enums§

Ended
Why fit_surface_scattered_over stopped.
Target
How far fit_surface_scattered_over refines its control net.

Constants§

SAMPLED_LOOP_SPANS
The most spans a closed sampled fit refines its samples to. A loop’s join couples its first and last control points, so its least-squares system is solved whole rather than as a band, at a cost that grows with the cube of the samples.
SAMPLED_SPANS
The most spans an open sampled fit refines its samples to (fit_curve_sampled, fit_curve_2d_sampled).

Functions§

fill_boundary
Fill the region bounded by four curves with a fitted patch: the transfinite Coons blend of the boundaries, sampled and fitted, its error reported.
fit_curve_2d_sampled
As fit_curve_sampled, in the plane: a chart image fitted at the parameters of the curve it annotates. The distances are in the trace’s own units.
fit_curve_sampled
Fit a curve to the geometry point traces over its parameter, measured between the samples as well as at them: the curve counterpart of fit_surface_sampled.
fit_points
Fit a spline through 3D points, refining until tolerance is met.
fit_points_2d
Fit a spline through 2D points, refining until tolerance is met.
fit_points_2d_at
Fit a pcurve at fixed parameters: the source curve’s own.
fit_points_2d_at_closed
As fit_points_2d_at, with the loop’s join made C1.
fit_points_at
Fit space points at fixed parameters: the caller’s t values are the curve’s own, which is what keeps a replacement curve same-parameter with every chart already speaking the old one. The error is measured at the given points only; fit_curve_sampled measures between them too.
fit_points_at_closed
As fit_points_at, with the loop’s join made C1: the points close, the last the first again.
fit_points_closed
Fit a smoothly closed loop: as fit_points, with the join C1.
fit_points_faired
Fit a fair curve: least squares over the points, pulled toward minimum bending energy by a smoothing weight.
fit_points_joint
Fit one curve living in three spaces at once: a 3D curve and its two parameter-space images, as a single seven-dimensional fit.
fit_points_joint_closed
As fit_points_joint, with a closed loop’s join made C1.
fit_points_joint_from
As fit_points_joint, at chord-length parameters held fixed, its knots starting at the parameters of the samples stations names.
fit_points_joint_from_held
As fit_points_joint_from, splitting a span only where samples lie strictly inside it on both sides of the new knot.
fit_points_joint_winding
As fit_points_joint_closed, for a loop closed in space whose pcurves may end a whole period from where they began: a section winding once round a periodic surface. The join is C1 in every coordinate, which is right where the chart runs at one speed across its seam, as a periodic surface’s does. A patch that merely meets itself need not.
fit_surface_grid
Fit a rectangular grid of points with a tensor-product B-spline surface.
fit_surface_grid_at
Fit a rectangular grid at fixed parameters: u_params[i] is the surface’s own u at rows[j][i], and v_params[j] its v.
fit_surface_grid_at_with_knots
As fit_surface_grid_at, each direction’s knots starting from the interior knots given for it, (parameter, multiplicity), and keeping them. Where the chart the points come from is only C0 or C1 along a parameter line, a knot there of multiplicity degree or degree - 1 lets the fit turn as the chart does; without one, a fit smoother than its data converges on such a line only as fast as its spans shrink. A multiplicity past the degree counts as the degree, and a knot outside the parameters’ open range is not used.
fit_surface_grid_chordal
As fit_surface_grid, parameterized by chord length instead of the centripetal assignment, the open counterpart of fit_surface_grid_closed_v_chordal, for a marched band that stops at its run-out instead of closing on itself.
fit_surface_grid_closed_v
As fit_surface_grid, with the v direction closed into a smooth loop.
fit_surface_grid_closed_v_chordal
As fit_surface_grid_closed_v, parameterized by chord length instead of the centripetal assignment.
fit_surface_grid_sections
As fit_surface_grid, with the rows placed across v by chord length: sections lofted through, where the spacing between sections is the skin’s own and may change along it. Centripetal parameters squash a change of spacing (a step twice another’s gets a parameter step only about one and a half times as long), and a cubic through sections so placed sags between them. Each row keeps the centripetal assignment along u.
fit_surface_sampled
Fit a surface to the geometry point traces over its parameters, measured between the samples as well as at them.
fit_surface_scattered
Fit a surface to scattered points: no grid required.
fit_surface_scattered_at
Fit a surface to scattered points at parameters the caller chose, over the caller’s knot vectors, faired by the thin-plate energy.
fit_surface_scattered_over
Fit a surface to scattered points, parameterised over a seed surface.
fit_trace_sampled
Fit a curve on a surface and its chart image together to the trace trace gives over its parameter: at each parameter the point in space and its chart position, on_surface the surface the chart belongs to.
grid_parameters
The parameters fit_surface_grid and its chord-length and section variants assign a rectangular grid: one shared assignment per direction, the average of every row’s (u) and every column’s (v), chord length or centripetal as by_chord says per direction.