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.
Geometry.Types.Spline2d units coordinates
fromControlPoints : Point2d units coordinates -> List (Point2d units coordinates) -> Spline2d units coordinates
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.
fromQuadraticSpline : QuadraticQuadraticSpline2d units coordinates -> Spline2d units coordinates
Convert a QuadraticSpline2d
to a generic Spline2d
.
fromCubicSpline : CubicCubicSpline2d units coordinates -> Spline2d units coordinates
Convert a CubicSpline2d
to a generic Spline2d
.
bSplineSegments : Basics.Int -> List Basics.Float -> List (Point2d units coordinates) -> List (Spline2d units coordinates)
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.
bSplineIntervals : Basics.Int -> List Basics.Float -> List (Interval Basics.Float)
For a given degree and set of B-spline knots, return the corresponding intervals between knots that correspond to individual spline segments.
controlPoints : Spline2d units coordinates -> List (Point2d units coordinates)
Get the control points of a spline as a list.
degree : Spline2d units coordinates -> Basics.Int
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.
startPoint : Spline2d units coordinates -> Point2d units coordinates
Get the start point of a spline.
endPoint : Spline2d units coordinates -> Point2d units coordinates
Get the end point of a spline.
startDerivative : Spline2d units coordinates -> Vector2d units coordinates
Get the start derivative of a spline.
endDerivative : Spline2d units coordinates -> Vector2d units coordinates
Get the end derivative of a spline.
boundingBox : Spline2d units coordinates -> BoundingBox2d units coordinates
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).
pointOn : Spline2d units coordinates -> Basics.Float -> Point2d units coordinates
Get a point on a spline at a given parameter value.
segments : Basics.Int -> Spline2d units coordinates -> Polyline2d units coordinates
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 : Quantity Basics.Float units -> Spline2d units coordinates -> Polyline2d units coordinates
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 : Spline2d units coordinates -> Spline2d units coordinates
Reverse a spline so that the start point becomes the end point, and vice versa.
scaleAbout : Point2d units coordinates -> Basics.Float -> Spline2d units coordinates -> Spline2d units coordinates
Scale a spline about the given center point by the given scale.
rotateAround : Point2d units coordinates -> Angle -> Spline2d units coordinates -> Spline2d units coordinates
Rotate a spline counterclockwise around a given axis by a given angle.
translateBy : Vector2d units coordinates -> Spline2d units coordinates -> Spline2d units coordinates
Translate a spline by a given displacement.
translateIn : Direction2d coordinates -> Quantity Basics.Float units -> Spline2d units coordinates -> Spline2d units coordinates
Translate a spline in a given direction by a given distance.
mirrorAcross : Axis2d units coordinates -> Spline2d units coordinates -> Spline2d units coordinates
Mirror a spline across a plane.
at : Quantity Basics.Float (Quantity.Rate units2 units1) -> Spline2d units1 coordinates -> Spline2d units2 coordinates
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.
at_ : Quantity Basics.Float (Quantity.Rate units1 units2) -> Spline2d units1 coordinates -> Spline2d units2 coordinates
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.
relativeTo : Frame2d units globalCoordinates { defines : localCoordinates } -> Spline2d units globalCoordinates -> Spline2d units localCoordinates
Take a spline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
placeIn : Frame2d units globalCoordinates { defines : localCoordinates } -> Spline2d units localCoordinates -> Spline2d units globalCoordinates
Take a spline considered to be defined in local coordinates relative to a given reference frame, and return that spline expressed in global coordinates.
bisect : Spline2d units coordinates -> ( Spline2d units coordinates, Spline2d units coordinates )
Split a spline into two roughly equal halves. Equivalent to
Spline2d.splitAt 0.5
.
splitAt : Basics.Float -> Spline2d units coordinates -> ( Spline2d units coordinates, Spline2d units coordinates )
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.
firstDerivative : Spline2d units coordinates -> Basics.Float -> Vector2d units coordinates
Get the first derivative of a spline at a given parameter value.
secondDerivative : Spline2d units coordinates -> Basics.Float -> Vector2d units coordinates
Get the second derivative value at a point along a spline.
firstDerivativeBoundingBox : Spline2d units coordinates -> VectorBoundingBox2d units coordinates
Get the bounds on the first derivative of a spline.
secondDerivativeBoundingBox : Spline2d units coordinates -> VectorBoundingBox2d units coordinates
Get the bounds on the first derivative of a spline.
maxSecondDerivativeMagnitude : Spline2d units coordinates -> Quantity Basics.Float units
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.
numApproximationSegments : Quantity Basics.Float units -> Spline2d units coordinates -> Basics.Int
Determine the number of linear segments needed to approximate a spline to within a given tolerance.