pub struct BSpline<P, const K: usize, const C: usize, const D: usize>where
P: Point,{ /* private fields */ }
Expand description
General Implementation of a BSpline with choosable degree, control points and knots.
Generic parameters:
P: const generic points array ‘P’ as defined by the Point trait
F: Any float value used for the knots and interpolation (usually the same as the internal generic parameter within P
Implementations§
source§impl<P, const K: usize, const C: usize, const D: usize> BSpline<P, { K }, { C }, { D }>where
P: Point,
impl<P, const K: usize, const C: usize, const D: usize> BSpline<P, { K }, { C }, { D }>where P: Point,
sourcepub fn new(
knots: [P::Scalar; K],
control_points: [P; C]
) -> Result<BSpline<P, { K }, { C }, { D }>, BSplineError>
pub fn new( knots: [P::Scalar; K], control_points: [P; C] ) -> Result<BSpline<P, { K }, { C }, { D }>, BSplineError>
Create a new B-spline curve that interpolates
the control_points
using a piecewise polynomial of degree
within intervals specified by the knots
.
The knots must be sorted in non-decreasing order, the constructor enforces this which may yield undesired results.
The degree is defined as curve_order - 1
.
Desired curve must have a valid number of control points and knots in relation to its degree or the constructor will return None.
A B-Spline curve requires at least one more control point than the degree (control_points.len() > degree
) and the number of knots should be equal to control_points.len() + degree + 1
.
sourcepub fn eval(&self, t: P::Scalar) -> Result<P, BSplineError>where
[(); { _ }]: Sized,
pub fn eval(&self, t: P::Scalar) -> Result<P, BSplineError>where [(); { _ }]: Sized,
Compute a point on the curve at t
using iterative de boor algorithm.
The parameter must be in the inclusive range of values returned
by knot_domain()
. If t
is out of bounds a KnotDomainViolation error is returned.
sourcepub fn control_points(&self) -> Iter<'_, P>
pub fn control_points(&self) -> Iter<'_, P>
Returns an iterator over the control points.
sourcepub fn knot_domain(&self) -> (P::Scalar, P::Scalar)
pub fn knot_domain(&self) -> (P::Scalar, P::Scalar)
Returns the knot domain of the B-Spline. The knot domain is the range of values over which the B-Spline is defined. The knot domain is defined as the minimum and maximum knot values. For a clamped B-Spline the first and last knot has multiplicity D+1. For an unclamped B-Spline the first and last knot has multiplicity 1.
sourcepub fn distance_to_point(&self, point: P) -> P::Scalar
pub fn distance_to_point(&self, point: P) -> P::Scalar
Calculates the minimum distance between given ‘point’ and the curve. Uses two passes with the same amount of steps in t:
- coarse search over the whole curve
- fine search around the minimum yielded by the coarse search
sourcepub fn arclen(&self, nsteps: usize) -> P::Scalarwhere
[(); { _ }]: Sized,
pub fn arclen(&self, nsteps: usize) -> P::Scalarwhere [(); { _ }]: Sized,
Approximates the arc length of the curve by flattening it with straight line segments. This approximation is unfeasable if desired accuracy is greater than ~2 decimal places
sourcepub fn derivative(&self) -> BSpline<P, K, { _ }, { _ }>
pub fn derivative(&self) -> BSpline<P, K, { _ }, { _ }>
Returns the derivative curve of self which has N-1 control points. The derivative of an nth degree B-Spline curve is an (n-1)th degree (d) B-Spline curve, with the same knot vector, and new control points Q0…Qn-1 derived from the original control points Pi as: d Qi = —————– (P[i+1]-P[i]) k[i+d+1] - k[i+1]. with degree = curve_order - 1 TODO test & verify!