Skip to main content

Crate bsplines

Crate bsplines 

Source
Expand description

bsplines is a library for vectorized, N-dimensional B-spline curves and their derivatives based on nalgebra.

§Features

§Example

use bsplines::{Curve, DataPoints};
use nalgebra::dmatrix;

// Five 2D data points, one column per point.
let data = DataPoints::new(dmatrix![
    -2.0,-1.0, 0.0, 1.0, 2.0; // x
     0.5,-0.5, 1.5,-1.5, 0.5; // y
]);

// Interpolate the data with a cubic curve and evaluate it.
let curve = Curve::interpolate(&data, 3)?;
let point = curve.evaluate(0.5)?;
let velocity = curve.evaluate_derivative(0.5, 1)?;

// Or approximate it with a penalized least-squares fit.
let fitted = Curve::fit(&data, 3).loose_ends().penalized(0.5, 2).build()?;

§What are B-Splines?

B-splines are parametric functions composed of piecewise, polynomial basis functions of degree p > 0. These piecewise polynomials are joined so that the parametric function is p-1 times continuously differentiable. The overall functions are parametrized over finite domains with a so-called knot vector with the co-domain being an N-dimensional vector space, that is defined by control points. They can describe curves, but also surfaces. These characteristics lead to many desirable properties. The piecewise definition makes B-spline functions versatile allowing to interpolate or approximate complex-shaped and high-dimensional data, while maintaining a low polynomial degree. Because of the polynomial nature, all possible derivatives are accessible.

A 2D B-Spline curve.

Still, evaluations or spatial manipulations can be executed fast because only local polynomial segments must be considered and the associated numerical procedures are stable. Lastly, polynomials represent a memory-efficient way of storing spatial information as few polynomial coefficients suffice to describe complex shapes.

§Literature:

Piegl1997Piegl, L., Tiller, W. The NURBS Book. Monographs in Visual Communication. Springer, Berlin, Heidelberg, 2nd ed., 1997.
Eilers1996Eilers, P. H. C., Marx, B. D., Flexible smoothing with B -splines and penalties, Stat. Sci., 11(2) (1996) 89–121.
Tai2003Tai, C.-L., Hu, S.-M., Huang, Q.-X., Approximate merging of B-spline curves via knot adjustment and constrained optimization, Comput. Des., 35(10) (2003) 893–899.

Structs§

Constraints
The parameters at which the points of two merged curves stay fixed.
ControlPoints
The control points P of a curve and of its derivatives; together they form the control polygon.
Curve
A B-spline curve: a parametric function that maps the domain [0, 1] into N-dimensional space.
DataPoints
Input points that a curve is interpolated through or fitted to. Data points are consumed by curve generation; they are not part of the resulting curve.
FitBuilder
Builds a least-squares fit of data points, with fixed or loose ends and an optional penalization; created by Curve::fit.
Knots
The knot vector U of a curve and the knot vectors of its derivatives.
Parameters
The parameter values ū assigned to the data points for interpolation and fitting, one per data point.

Enums§

Error
The error type for all fallible B-spline operations.
KnotMethod
The method generating a clamped knot vector for a curve of degree p with n polygon segments.
ParameterMethod
The method assigning a parameter value ū to every data point.

Traits§

Points
Common accessors for point sets stored as one column per point.

Type Aliases§

Result
Convenience alias for a core::result::Result with the crate-wide Error.