A QuadraticSpline3d is a quadratic Bézier curve
in 3D defined by three control points. This module contains functionality for
Construct a spline from its three control points:
exampleSpline =
QuadraticSpline3d.fromControlPoints
( Point3d.fromCoordinates ( 1, 1, 1 )
, Point3d.fromCoordinates ( 3, 2, 1 )
, Point3d.fromCoordinates ( 3, 3, 3 )
)Construct a 3D spline lying on a sketch plane by providing a 2D spline specified in XY coordinates within the sketch plane.
QuadraticSpline3d.on SketchPlane3d.xz <|
QuadraticSpline2d.fromControlPoints
( Point2d.fromCoordinates ( 1, 1 )
, Point2d.fromCoordinates ( 3, 4 )
, Point2d.fromCoordinates ( 5, 1 )
)
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 1, 0, 1 )
--> , Point3d.fromCoordinates ( 3, 0, 4 )
--> , Point3d.fromCoordinates ( 5, 0, 1 )
--> )Get the control points of a spline as a tuple.
( p1, p2, p3 ) =
QuadraticSpline3d.controlPoints exampleSpline
--> p1 = Point3d.fromCoordinates ( 1, 1, 1 )
--> p2 = Point3d.fromCoordinates ( 3, 2, 1 )
--> p3 = Point3d.fromCoordinates ( 3, 3, 3 )Get the start point of a spline. This is equal to the spline's first control point.
QuadraticSpline3d.startPoint exampleSpline
--> Point3d.fromCoordinates ( 1, 1, 1 )Get the end point of a spline. This is equal to the spline's last control point.
QuadraticSpline3d.endPoint exampleSpline
--> Point3d.fromCoordinates ( 3, 3, 3 )Get the start derivative of a spline. This is equal to twice the vector from the spline's first control point to its second.
QuadraticSpline3d.startDerivative exampleSpline
--> Vector3d.fromComponents ( 4, 2, 0 )Get the end derivative of a spline. This is equal to twice the vector from the spline's second control point to its third.
QuadraticSpline3d.endDerivative exampleSpline
--> Vector3d.fromComponents ( 0, 2, 4 )Get a point along a spline, based on a parameter that ranges from 0 to 1. A parameter value of 0 corresponds to the start point of the spline and a value of 1 corresponds to the end point.
QuadraticSpline3d.pointOn exampleSpline 0
--> Point3d.fromCoordinates ( 1, 1, 1 )
QuadraticSpline3d.pointOn exampleSpline 0.5
--> Point3d.fromCoordinates ( 2.5, 2, 1.5 )
QuadraticSpline3d.pointOn exampleSpline 1
--> Point3d.fromCoordinates ( 3, 3, 3 )Get the deriative value at a point along a spline, based on a parameter that ranges from 0 to 1. A parameter value of 0 corresponds to the start derivative of the spline and a value of 1 corresponds to the end derivative.
QuadraticSpline3d.derivative exampleSpline 0
--> Vector3d.fromComponents ( 4, 2, 0 )
QuadraticSpline3d.derivative exampleSpline 0.5
--> Vector3d.fromComponents ( 2, 2, 2 )
QuadraticSpline3d.derivative exampleSpline 1
--> Vector3d.fromComponents ( 0, 2, 4 )Note that the derivative interpolates linearly from end to end.
Evaluate a spline at a given parameter value, returning the point on the spline at that parameter value and the derivative with respect to that parameter value;
QuadraticSpline3d.evaluate spline tis equivalent to
( QuadraticSpline3d.pointOn spline t
, QuadraticSpline3d.derivative spline t
)but is more efficient.
Reverse a spline so that the start point becomes the end point, and vice versa.
QuadraticSpline3d.reverse exampleSpline
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 3, 3, 3 )
--> , Point3d.fromCoordinates ( 3, 2, 1 )
--> , Point3d.fromCoordinates ( 1, 1, 1 )
--> )Scale a spline about the given center point by the given scale.
exampleSpline
|> QuadraticSpline3d.scaleAbout Point3d.origin 2
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 2, 2, 2 )
--> , Point3d.fromCoordinates ( 6, 4, 2 )
--> , Point3d.fromCoordinates ( 6, 6, 6 )
--> )Rotate a spline counterclockwise around a given axis by a given angle (in radians).
exampleSpline
|> QuadraticSpline3d.rotateAround Axis3d.z
(degrees 90)
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( -1, 1, 1 )
--> , Point3d.fromCoordinates ( -2, 3, 1 )
--> , Point3d.fromCoordinates ( -3, 3, 3 )
--> )Translate a spline by a given displacement.
displacement =
Vector3d.fromComponents ( 2, 3, 1 )
exampleSpline
|> QuadraticSpline3d.translateBy displacement
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 3, 4, 2 )
--> , Point3d.fromCoordinates ( 5, 5, 2 )
--> , Point3d.fromCoordinates ( 5, 6, 4 )
--> )Mirror a spline across a plane.
QuadraticSpline3d.mirrorAcross Plane3d.xy exampleSpline
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 1, 1, -1 )
--> , Point3d.fromCoordinates ( 3, 2, -1 )
--> , Point3d.fromCoordinates ( 3, 3, -3 )
--> )Find the orthographic projection of a spline onto a plane.
QuadraticSpline3d.projectOnto Plane3d.xy exampleSpline
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 1, 1, 0 )
--> , Point3d.fromCoordinates ( 3, 2, 0 )
--> , Point3d.fromCoordinates ( 3, 3, 0 )
--> )Take a spline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame3d.atPoint
(Point3d.fromCoordinates ( 1, 2, 3 ))
QuadraticSpline3d.relativeTo localFrame exampleSpline
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 0, -1, -2 )
--> , Point3d.fromCoordinates ( 2, 0, -2 )
--> , Point3d.fromCoordinates ( 2, 1, 0 )
--> )Take a spline considered to be defined in local coordinates relative to a given reference frame, and return that spline expressed in global coordinates.
localFrame =
Frame3d.atPoint
(Point3d.fromCoordinates ( 1, 2, 3 ))
QuadraticSpline3d.placeIn localFrame exampleSpline
--> QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 2, 3, 4 )
--> , Point3d.fromCoordinates ( 4, 4, 4 )
--> , Point3d.fromCoordinates ( 4, 5, 6 )
--> )Project a spline into a given sketch plane. Conceptually, finds the orthographic projection of the spline onto the plane and then expresses the projected spline in 2D sketch coordinates.
exampleSpline
|> QuadraticSpline3d.projectInto SketchPlane3d.yz
--> QuadraticSpline2d.fromControlPoints
--> ( Point2d.fromCoordinates ( 1, 1 )
--> , Point2d.fromCoordinates ( 2, 1 )
--> , Point2d.fromCoordinates ( 3, 3 )
--> )Split a spline into two roughly equal halves. Equivalent to splitAt 0.5.
QuadraticSpline3d.bisect exampleSpline
--> ( QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 1, 1, 1 )
--> , Point3d.fromCoordinates ( 2, 2.5 )
--> , Point3d.fromCoordinates ( 3, 2.5 )
--> )
--> , QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 3, 2.5 )
--> , Point3d.fromCoordinates ( 4, 2.5 )
--> , Point3d.fromCoordinates ( 3, 3, 3 )
--> )
--> )Split a spline at a particular parameter value (in the range 0 to 1), resulting in two smaller splines.
QuadraticSpline3d.splitAt 0.75 exampleSpline
--> ( QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 1, 1, 1 )
--> , Point3d.fromCoordinates ( 2, 1.5, 1 )
--> , Point3d.fromCoordinates ( 2.5, 2, 1.5 )
--> )
--> , QuadraticSpline3d.fromControlPoints
--> ( Point3d.fromCoordinates ( 2.5, 2, 1.5 )
--> , Point3d.fromCoordinates ( 3, 2.5, 2 )
--> , Point3d.fromCoordinates ( 3, 3, 3 )
--> )
--> )A spline that has been parameterized by arc length.
Build an arc length parameterization of the given spline, within
a given tolerance. Generally speaking, all operations on the resulting
ArcLengthParameterized value will be accurate to within the given arc length
tolerance.
tolerance =
1.0e-4
parameterizedSpline =
QuadraticSpline3d.arcLengthParameterized
tolerance
exampleSplineFind the total arc length of a spline. This will be accurate to within the
tolerance given when calling arcLengthParameterized.
arcLength : Float
arcLength =
QuadraticSpline3d.arcLength parameterizedSpline
arcLength
--> 3.8175Try to get the point along a spline at a given arc length. For example, to
get the point a quarter of the way along exampleSpline:
QuadraticSpline3d.pointAlong parameterizedSpline
(arcLength / 4)
--> Just <|
--> Point3d.fromCoordinates
--> ( 1.8227, 1.4655, 1.1083 )Note that this is not the same as evaulating at a parameter value of 1/4:
QuadraticSpline3d.pointOn exampleSpline 0.25
--> Point3d.fromCoordinates ( 1.875, 1.5, 1.125 )If the given arc length is less than zero or greater than the arc length of the
spline, Nothing is returned.
Try to get the tangent direction along a spline at a given arc length. To
get the tangent direction a quarter of the way along exampleSpline:
QuadraticSpline3d.tangentAlong parameterizedSpline
(arcLength / 4)
--> Just <|
--> Direction3d.with
--> { azimuth = degrees 33.091
--> , elevation = degrees 14.260
--> }If the given arc length is less than zero or greater than the arc length of the
spline (or if the derivative of the spline happens to be exactly zero at the
given arc length), Nothing is returned.
Try to get the parameter value along a spline at a given arc length. If the
given arc length is less than zero or greater than the arc length of the spline,
returns Nothing.
QuadraticSpline3d.arcLengthToParameterValue
parameterizedSpline
(arcLength / 4)
--> Just 0.2328Try to get the arc length along a spline at a given parameter value. If the
given parameter value is less than zero or greater than one, returns Nothing.
QuadraticSpline3d.parameterValueToArcLength
parameterizedSpline
0.25
--> Just 1.0192Low level functionality that you are unlikely to need to use directly.
Find the magnitude of the derivative to a spline at a particular parameter value;
QuadraticSpline3d.derivativeMagnitude spline tis equivalent to
Vector3d.length (QuadraticSpline3d.derivative spline t)but more efficient since it avoids any intermediate Vector3d allocation.
Get the second derivative of a spline (for a quadratic spline, this is a constant).