A RationalQuadraticSpline2d is a rational quadratic Bézier curve in 2D
defined by three control points and corresponding weights. This module contains
functionality for
Construct a spline from its four control points and associated weights.
exampleSpline =
RationalQuadraticSpline2d.fromControlPoints
( Point2d.meters 1 1, 1 )
( Point2d.meters 3 4, 2 )
( Point2d.meters 5 1, 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.
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 one 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 two times; for example, the knots
[ 0, 0, 1, 2, 3, 4, 4 ]could be used along with 6 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 three greater than the number of control points (especially if you also notice that the first and last knots are repeated three times instead of two!) then you should drop the first and last knot values.
Knot values should be given in ascending order but will be sorted if necessary.
For a given set of B-spline knots, return the corresponding intervals between knots that correspond to individual spline segments.
Get the start point of a spline. Equal to
firstControlPoint.
Get the end point of a spline. Equal to
thirdControlPoint.
Get the start derivative of a spline;
RationalQuadraticSpline2d.startDerivative splineis equivalent to (but more efficient than)
RationalQuadraticSpline2d.firstDerivative spline 0Get the end derivative of a spline;
RationalQuadraticSpline2d.endDerivative splineis equivalent to (but more efficient than)
RationalQuadraticSpline2d.firstDerivative spline 1Compute 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).
RationalQuadraticSpline2d.boundingBox exampleSpline
--> BoundingBox2d.from
--> (Point2d.meters 1 1)
--> (Point2d.meters 5 4)Get the first control point of the spline. Equal to
startPoint.
Get the second control point of the spline.
Get the third and last control point of the spline. Equal to endPoint.
Get the weight corresponding to the first control point of the spline.
Get the weight corresponding to the second control point of the spline.
Get the weight corresponding to the third control point of the spline.
Get the point along 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 center point 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 an axis.
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
RationalQuadraticSpline2d.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.
Determine the number of linear segments needed to approximate a quadratic spline to within a given tolerance.
Get the first derivative of a spline at a given parameter value.
Evaluate the second derivative of a spline at a given parameter value.
Get the bounds on the first derivative of a spline.
Compute the bounds on the second derivative of a spline.