ianmackenzie / elm-geometry / QuadraticSpline3d

A QuadraticSpline3d is a quadratic Bézier curve in 3D defined by a start point, control point and end point. This module contains functionality for


type alias QuadraticSpline3d units coordinates =
Geometry.Types.QuadraticSpline3d units coordinates

Constructors

fromControlPoints : Point3d units coordinates -> Point3d units coordinates -> Point3d units coordinates -> QuadraticSpline3d units coordinates

Construct a spline from its start point, inner control point and end point:

exampleSpline =
    QuadraticSpline3d.fromControlPoints
        (Point3d.meters 1 1 1)
        (Point3d.meters 3 2 1)
        (Point3d.meters 3 3 3)

on : SketchPlane3d units coordinates3d { defines : coordinates2d } -> QuadraticSpline2d units coordinates2d -> QuadraticSpline3d units coordinates3d

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.meters 1 1)
        (Point2d.meters 3 4)
        (Point2d.meters 5 1)
--> QuadraticSpline3d.fromControlPoints
-->     (Point3d.meters 1 0 1)
-->     (Point3d.meters 3 0 4)
-->     (Point3d.meters 5 0 1)

B-splines

bSplineSegments : List Basics.Float -> List (Point3d units coordinates) -> List (QuadraticSpline3d units coordinates)

Construct a B-spline 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.

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.

Properties

startPoint : QuadraticSpline3d units coordinates -> Point3d units coordinates

Get the start point of a spline. Equal to firstControlPoint.

firstControlPoint : QuadraticSpline3d units coordinates -> Point3d units coordinates

Get the first control point of a spline. Equal to startPoint.

secondControlPoint : QuadraticSpline3d units coordinates -> Point3d units coordinates

Get the second control point of a spline.

thirdControlPoint : QuadraticSpline3d units coordinates -> Point3d units coordinates

Get the third and last control point of a spline. Equal to endPoint.

endPoint : QuadraticSpline3d units coordinates -> Point3d units coordinates

Get the end point of a spline. Equal to thirdControlPoint.

startDerivative : QuadraticSpline3d units coordinates -> Vector3d units coordinates

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.meters 4 2 0

endDerivative : QuadraticSpline3d units coordinates -> Vector3d units coordinates

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.meters 0 2 4

boundingBox : QuadraticSpline3d units coordinates -> BoundingBox3d 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).

QuadraticSpline3d.boundingBox exampleSpline
--> BoundingBox3d.from
-->     (Point3d.meters 1 1 1)
-->     (Point3d.meters 3 3 3)

Evaluation

pointOn : QuadraticSpline3d units coordinates -> Basics.Float -> Point3d units coordinates

Get the point along a spline at a given parameter value.


type Nondegenerate units coordinates

Represents a nondegenerate spline (one that has finite, non-zero length).

nondegenerate : QuadraticSpline3d units coordinates -> Result (Point3d units coordinates) (Nondegenerate units coordinates)

Attempt to construct a nondegenerate spline from a general QuadraticSpline3d. If the spline is in fact degenerate (consists of a single point), returns an Err with that point.

fromNondegenerate : Nondegenerate units coordinates -> QuadraticSpline3d units coordinates

Convert a nondegenerate spline back to a general QuadraticSpline3d.

tangentDirection : Nondegenerate units coordinates -> Basics.Float -> Direction3d coordinates

Get the tangent direction to a nondegenerate spline at a given parameter value.

sample : Nondegenerate units coordinates -> Basics.Float -> ( Point3d units coordinates, Direction3d coordinates )

Get both the point and tangent direction of a nondegenerate spline at a given parameter value.

Linear approximation

segments : Basics.Int -> QuadraticSpline3d units coordinates -> Polyline3d units coordinates

Approximate a quadratic 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 -> QuadraticSpline3d units coordinates -> Polyline3d units coordinates

Approximate a quadratic spline as a polyline, within a given tolerance. Every point on the returned polyline will be within the given tolerance of the spline.

Transformations

These transformations generally behave just like the ones in the Point3d module.

reverse : QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Reverse a spline so that the start point becomes the end point, and vice versa.

scaleAbout : Point3d units coordinates -> Basics.Float -> QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Scale a spline about the given center point by the given scale.

rotateAround : Axis3d units coordinates -> Angle -> QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Rotate a spline counterclockwise around a given axis by a given angle.

translateBy : Vector3d units coordinates -> QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Translate a spline by a given displacement.

translateIn : Direction3d coordinates -> Quantity Basics.Float units -> QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Translate an arc in a given direction by a given distance.

mirrorAcross : Plane3d units coordinates -> QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Mirror a spline across a plane.

projectOnto : Plane3d units coordinates -> QuadraticSpline3d units coordinates -> QuadraticSpline3d units coordinates

Find the orthographic projection of a spline onto a plane.

Unit conversions

at : Quantity Basics.Float (Quantity.Rate units2 units1) -> QuadraticSpline3d units1 coordinates -> QuadraticSpline3d 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) -> QuadraticSpline3d units1 coordinates -> QuadraticSpline3d 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.

Coordinate conversions

relativeTo : Frame3d units globalCoordinates { defines : localCoordinates } -> QuadraticSpline3d units globalCoordinates -> QuadraticSpline3d units localCoordinates

Take a spline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.

placeIn : Frame3d units globalCoordinates { defines : localCoordinates } -> QuadraticSpline3d units localCoordinates -> QuadraticSpline3d 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.

Sketch planes

projectInto : SketchPlane3d units coordinates3d { defines : coordinates2d } -> QuadraticSpline3d units coordinates3d -> QuadraticSpline2d units coordinates2d

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.

Subdivision

bisect : QuadraticSpline3d units coordinates -> ( QuadraticSpline3d units coordinates, QuadraticSpline3d units coordinates )

Split a spline into two roughly equal halves. Equivalent to QuadraticSpline3d.splitAt 0.5.

splitAt : Basics.Float -> QuadraticSpline3d units coordinates -> ( QuadraticSpline3d units coordinates, QuadraticSpline3d units coordinates )

Split a spline at a particular parameter value, resulting in two smaller splines.

Arc length parameterization


type ArcLengthParameterized units coordinates

A spline that has been parameterized by arc length.

arcLengthParameterized : { maxError : Quantity Basics.Float units } -> Nondegenerate units coordinates -> ArcLengthParameterized units coordinates

Build an arc length parameterization of the given spline, with a given accuracy.

pointAlong : ArcLengthParameterized units coordinates -> Quantity Basics.Float units -> Point3d units coordinates

Get the point along a spline at a given arc length.

midpoint : ArcLengthParameterized units coordinates -> Point3d units coordinates

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.

tangentDirectionAlong : ArcLengthParameterized units coordinates -> Quantity Basics.Float units -> Direction3d coordinates

Get the tangent direction along a spline at a given arc length.

sampleAlong : ArcLengthParameterized units coordinates -> Quantity Basics.Float units -> ( Point3d units coordinates, Direction3d coordinates )

Get the point and tangent direction along a spline at a given arc length.

Low level

An ArcLengthParameterized value is a combination of an ArcLengthParameterization and an underlying QuadraticSpline3d. If you need to do something fancy, you can extract these two values separately.

arcLengthParameterization : ArcLengthParameterized units coordinates -> ArcLength.Parameterization units

fromArcLengthParameterized : ArcLengthParameterized units coordinates -> QuadraticSpline3d units coordinates

Get the original QuadraticSpline3d from which an ArcLengthParameterized value was constructed.

Advanced

You are unlikely to need to use these functions directly, but they are useful if you are writing low-level geometric algorithms.

firstDerivative : QuadraticSpline3d units coordinates -> Basics.Float -> Vector3d units coordinates

Get the first derivative of a spline at a given parameter value. Note that the derivative interpolates linearly from end to end.

secondDerivative : QuadraticSpline3d units coordinates -> Vector3d units coordinates

Get the second derivative of a spline (for a quadratic spline, this is a constant).

firstDerivativeBoundingBox : QuadraticSpline3d units coordinates -> VectorBoundingBox3d units coordinates

Get the bounds on the first deriative of a spline.

numApproximationSegments : Quantity Basics.Float units -> QuadraticSpline3d units coordinates -> Basics.Int

Determine the number of linear segments needed to approximate a quadratic spline to within a given tolerance.