A CubicSpline3d is a cubic Bézier curve
in 3D defined by a start point, end point and two control points. This module
contains functionality for
Construct a spline from its four control points:
exampleSpline =
CubicSpline3d.fromControlPoints
(Point3d.meters 1 1 1)
(Point3d.meters 3 1 1)
(Point3d.meters 3 3 1)
(Point3d.meters 3 3 3)Construct a spline from a given start point with a given start derivative, to a given end point with a given end derivative, like so:
For good results, in most cases the length of each derivative vector should be roughly equal to the length of the resulting spline.
Construct a 3D spline lying on a sketch plane by providing a 2D spline specified in XY coordinates within the sketch plane.
CubicSpline3d.on SketchPlane3d.xz <|
CubicSpline2d.fromControlPoints
(Point2d.meters 1 1)
(Point2d.meters 3 4)
(Point2d.meters 5 1)
(Point2d.meters 7 4)
--> CubicSpline3d.fromControlPoints
--> (Point3d.meters 1 0 1)
--> (Point3d.meters 3 0 4)
--> (Point3d.meters 5 0 1)
--> (Point3d.meters 7 0 4)Convert a quadratic spline into the equivalent cubic spline (every quadratic spline can be represented exactly as a cubic spline).
quadraticSpline =
QuadraticSpline3d.fromControlPoints
Point3d.origin
(Point3d.meters 3 0 0)
(Point3d.meters 3 3 0)
CubicSpline3d.fromQuadraticSpline quadraticSpline
--> CubicSpline3d.fromControlPoints
--> Point3d.origin
--> (Point3d.meters 2 0 0)
--> (Point3d.meters 3 1 0)
--> (Point3d.meters 3 3 0)Get the start point of a spline. Equal to
firstControlPoint.
Get the first control point of a spline. Equal to
startPoint.
Get the second control point of a spline.
Get the third control point of a spline.
Get the fourth and last control point of a spline.
Equal to endPoint.
Get the end point of a spline. Equal to
fourthControlPoint.
Get the start derivative of a spline. This is equal to three times the vector from the spline's start point to its start control point.
CubicSpline3d.startDerivative exampleSpline
--> Vector3d.meters 6 0 0Get the end derivative of a spline. This is equal to three times the vector from the spline's end control point to its end point.
CubicSpline3d.endDerivative exampleSpline
--> Vector3d.meters 0 0 6Compute 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.
Represents a nondegenerate spline (one that has finite, non-zero length).
Attempt to construct a nondegenerate spline from a general CubicSpline3d.
If the spline is in fact degenerate (consists of a single point), returns an
Err with that point.
Convert a nondegenerate spline back to a general CubicSpline3d.
Get the tangent direction to a nondegenerate spline at a given parameter value.
Get both the point and tangent direction of a nondegenerate spline at a given parameter value.
Approximate a cubic 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 cubic 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 Point3d
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.
Find the orthographic projection of a spline onto 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.
Project a spline into a given sketch plane.
Split a spline into two roughly equal halves. Equivalent to
CubicSpline3d.splitAt 0.5.
Split a spline at a particular parameter value, resulting in two smaller splines.
A spline that has been parameterized by arc length.
Build an arc length parameterization of the given spline, with a given accuracy.
Find the total arc length of a spline, to within the accuracy specified when constructing the given arc length parameterization.
Get the midpoint of a spline. Note that this is the point half way along the spline by arc length, which is not in general the same as evaluating at a parameter value of 0.5.
For the following evaluation functions, the given arc length will be clamped to the arc length of the spline, so the result will always be on the spline.
Get the point along a spline at a given arc length.
Get the tangent direction along a spline at a given arc length.
Get the point and tangent direction along a spline at a given arc length.
An ArcLengthParameterized value is a combination of an
ArcLengthParameterization and an
underlying CubicSpline3d. If you need to do something fancy, you can extract
these two values separately.
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 third derivative of a spline (for a cubic spline, this is a constant).
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 cubic spline to within a given tolerance.