A Spline2d is a Bézier curve
in 2D defined by a list of control points. This module contains functionality
for
In general you will want to use a QuadraticSpline2d or
CubicSpline2d instead, but a Spline2d can be useful if you
need to support arbitrary spline degrees (for example quartic or quintic
splines) or if the spline degree is not known at compile time.
Construct a spline from its control points. In order to guarantee that a spline has at least one control point, you must pass the first and remaining control points separately.
Convert a QuadraticSpline2d to a generic Spline2d.
Convert a CubicSpline2d to a generic Spline2d.
Construct a B-spline from a given polynomial degree (2 for a quadratic spline, 3 for a cubic spline etc.), a list of knot values and a list of control points, and return the individual segments of that B-spline as a list.
The number of knots should be equal to the number of control points plus the
given degree, minus 1; for example, for a cubic spline (degree 3) the number of
knots should be 2 greater than the number of control points. A popular alternate
convention uses two extra 'dummy' knot values at the start and end, so the
number of knots is equal to the given degree plus one. The bSplineSegments
function supports both conventions - if the number of knots is equal to the
degree plus one then the first and last knots will be dropped.
In most cases the first and last knots will be repeated a number of times equal to the spline degree (or the degree plus one, for the alternate convention described above); for example for a quadratic spline the first and last knots will be repeated twice and for a cubic spline they will be repeated three times.
Knot values should be given in ascending order but will be sorted if necessary. If the number of knots does not follow either of the conventions described above, an empty list will be returned.
For a given degree and set of B-spline knots, return the corresponding intervals between knots that correspond to individual spline segments.
Get the control points of a spline as a list.
Get the polynomial degree of a spline; this is equal to the number of control points minus one. A single point has degree 0, a line segment has degree 1, a quadratic spline has degree 2, a cubic spline has degree 3, etc.
Get the start point of a spline.
Get the end point of a spline.
Get the start derivative of a spline.
Get the end derivative of a spline.
Compute a bounding box for a given spline. It is not guaranteed that the result will be the smallest possible bounding box, since for efficiency the bounding box is computed from the spline's control points (which cover a larger volume than the spline itself).
Get a point on a spline at a given parameter value.
Approximate a spline by a given number of line segments. Note that the number of points in the polyline will be one more than the number of segments.
Approximate a spline as a polyline, within a given tolerance. Every point on the returned polyline will be within the given tolerance of the spline.
These transformations generally behave just like the ones in the Point2d
module.
Reverse a spline so that the start point becomes the end point, and vice versa.
Scale a spline about the given center point by the given scale.
Rotate a spline counterclockwise around a given axis by a given angle.
Translate a spline by a given displacement.
Translate a spline in a given direction by a given distance.
Mirror a spline across a plane.
Convert a spline from one units type to another, by providing a conversion factor given as a rate of change of destination units with respect to source units.
Convert a spline from one units type to another, by providing an 'inverse' conversion factor given as a rate of change of source units with respect to destination units.
Take a spline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
Take a spline considered to be defined in local coordinates relative to a given reference frame, and return that spline expressed in global coordinates.
Split a spline into two roughly equal halves. Equivalent to
Spline2d.splitAt 0.5.
Split a spline at a particular parameter value, resulting in two smaller splines.
You are unlikely to need to use these functions directly, but they are useful if you are writing low-level geometric algorithms.
Get the first derivative of a spline at a given parameter value.
Get the second derivative value at a point along a spline.
Get the bounds on the first derivative of a spline.
Get the bounds on the first derivative of a spline.
Find a conservative upper bound on the magnitude of the second derivative of a spline. This can be useful when determining error bounds for various kinds of linear approximations.
Determine the number of linear segments needed to approximate a spline to within a given tolerance.