A RationalCubicSpline2d
is a rational cubic Bézier curve in 2D defined by
four control points and corresponding weights. This module contains
functionality for
Geometry.Types.RationalCubicSpline2d units coordinates
fromControlPoints : ( Point2d units coordinates, Basics.Float ) -> ( Point2d units coordinates, Basics.Float ) -> ( Point2d units coordinates, Basics.Float ) -> ( Point2d units coordinates, Basics.Float ) -> RationalCubicSpline2d units coordinates
Construct a spline from its four control points and associated weights.
exampleSpline =
RationalCubicSpline2d.fromControlPoints
( Point2d.meters 1 1, 1 )
( Point2d.meters 3 4, 2 )
( Point2d.meters 5 1, 2 )
( Point2d.meters 7 4, 1 )
All weights should be greater than zero. If any negative weights are passed, their absolute values will be used. Larger weights will tend to 'pull' the curve towards the corresponding control point.
bSplineSegments : List Basics.Float -> List ( Point2d units coordinates, Basics.Float ) -> List (RationalCubicSpline2d units coordinates)
Construct a non-uniform rational B-spline (also known as a NURBS curve) from 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 two greater than the number of control points; any extra knots or control points will be dropped. In most cases the first and last knots will be repeated three times; for example, the knots
[ 0, 0, 0, 1, 2, 3, 4, 4, 4 ]
could be used along with 7 control points to form 4 spline segments.
Note that a popular alternate convention uses two extra 'dummy' knot values at the start and end, so if you see an example where the number of knots is four greater than the number of control points (especially if you also notice that the first and last knots are repeated four times instead of three!) then you should drop the first and last knot values.
Knot values should be given in ascending order but will be sorted if necessary.
bSplineIntervals : List Basics.Float -> List (Interval Basics.Float)
For a given set of B-spline knots, return the corresponding intervals between knots that correspond to individual spline segments.
startPoint : RationalCubicSpline2d units coordinates -> Point2d units coordinates
Get the start point of a spline. Equal to
firstControlPoint
.
endPoint : RationalCubicSpline2d units coordinates -> Point2d units coordinates
Get the end point of a spline. Equal to
fourthControlPoint
.
startDerivative : RationalCubicSpline2d units coordinates -> Vector2d units coordinates
Get the start derivative of a spline;
RationalCubicSpline2d.startDerivative spline
is equivalent to (but more efficient than)
RationalCubicSpline2d.firstDerivative spline 0
endDerivative : RationalCubicSpline2d units coordinates -> Vector2d units coordinates
Get the end derivative of a spline;
RationalCubicSpline2d.endDerivative spline
is equivalent to (but more efficient than)
RationalCubicSpline2d.firstDerivative spline 1
boundingBox : RationalCubicSpline2d 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 area than the spline itself).
RationalCubicSpline2d.boundingBox exampleSpline
--> BoundingBox2d.from
--> (Point2d.meters 1 1)
--> (Point2d.meters 7 4)
firstControlPoint : RationalCubicSpline2d units coordinates -> Point2d units coordinates
Get the first control point of the spline. Equal to
startPoint
.
secondControlPoint : RationalCubicSpline2d units coordinates -> Point2d units coordinates
Get the second control point of the spline.
thirdControlPoint : RationalCubicSpline2d units coordinates -> Point2d units coordinates
Get the third control point of the spline.
fourthControlPoint : RationalCubicSpline2d units coordinates -> Point2d units coordinates
Get the fourth and last control point of the spline.
Equal to endPoint
.
firstWeight : RationalCubicSpline2d units coordinates -> Basics.Float
Get the weight corresponding to the first control point of the spline.
secondWeight : RationalCubicSpline2d units coordinates -> Basics.Float
Get the weight corresponding to the second control point of the spline.
thirdWeight : RationalCubicSpline2d units coordinates -> Basics.Float
Get the weight corresponding to the third control point of the spline.
fourthWeight : RationalCubicSpline2d units coordinates -> Basics.Float
Get the weight corresponding to the fourth control point of the spline.
pointOn : RationalCubicSpline2d units coordinates -> Basics.Float -> Point2d units coordinates
Get the point along a spline at a given parameter value.
segments : Basics.Int -> RationalCubicSpline2d 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 -> RationalCubicSpline2d 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 : RationalCubicSpline2d units coordinates -> RationalCubicSpline2d units coordinates
Reverse a spline so that the start point becomes the end point, and vice versa.
scaleAbout : Point2d units coordinates -> Basics.Float -> RationalCubicSpline2d units coordinates -> RationalCubicSpline2d units coordinates
Scale a spline about the given center point by the given scale.
rotateAround : Point2d units coordinates -> Angle -> RationalCubicSpline2d units coordinates -> RationalCubicSpline2d units coordinates
Rotate a spline counterclockwise around a given center point by a given angle.
translateBy : Vector2d units coordinates -> RationalCubicSpline2d units coordinates -> RationalCubicSpline2d units coordinates
Translate a spline by a given displacement.
translateIn : Direction2d coordinates -> Quantity Basics.Float units -> RationalCubicSpline2d units coordinates -> RationalCubicSpline2d units coordinates
Translate a spline in a given direction by a given distance.
mirrorAcross : Axis2d units coordinates -> RationalCubicSpline2d units coordinates -> RationalCubicSpline2d units coordinates
Mirror a spline across an axis.
at : Quantity Basics.Float (Quantity.Rate units2 units1) -> RationalCubicSpline2d units1 coordinates -> RationalCubicSpline2d 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) -> RationalCubicSpline2d units1 coordinates -> RationalCubicSpline2d 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 } -> RationalCubicSpline2d units globalCoordinates -> RationalCubicSpline2d 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 } -> RationalCubicSpline2d units localCoordinates -> RationalCubicSpline2d 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 : RationalCubicSpline2d units coordinates -> ( RationalCubicSpline2d units coordinates, RationalCubicSpline2d units coordinates )
Split a spline into two roughly equal halves. Equivalent to
RationalCubicSpline2d.splitAt 0.5
.
splitAt : Basics.Float -> RationalCubicSpline2d units coordinates -> ( RationalCubicSpline2d units coordinates, RationalCubicSpline2d 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.
numApproximationSegments : Quantity Basics.Float units -> RationalCubicSpline2d units coordinates -> Basics.Int
Determine the number of linear segments needed to approximate a cubic spline to within a given tolerance.
firstDerivative : RationalCubicSpline2d units coordinates -> Basics.Float -> Vector2d units coordinates
Get the first derivative of a spline at a given parameter value.
secondDerivative : RationalCubicSpline2d units coordinates -> Basics.Float -> Vector2d units coordinates
Evaluate the second derivative of a spline at a given parameter value.
firstDerivativeBoundingBox : RationalCubicSpline2d units coordinates -> VectorBoundingBox2d units coordinates
Get the bounds on the first derivative of a spline.
secondDerivativeBoundingBox : RationalCubicSpline2d units coordinates -> VectorBoundingBox2d units coordinates
Compute the bounds on the second derivative of a spline.
maxSecondDerivativeMagnitude : RationalCubicSpline2d units coordinates -> Quantity Basics.Float units
Find the maximum magnitude of the second derivative of a spline.