ianmackenzie/elm-geometry/3.0.0

NOTE: the latest version is 4.0.0

QuadraticSpline2d

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

  • Evaluating points and derivatives along a spline
  • Scaling, rotating, translating or mirroring a spline
  • Converting a spline between local and global coordinates in different reference frames
type alias QuadraticSpline2d units coordinates =
QuadraticSpline2d units coordinates

Constructors

Point2d units coordinates
-> Point2d units coordinates
-> Point2d units coordinates
-> QuadraticSpline2d units coordinates

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

exampleSpline =
    QuadraticSpline2d.fromControlPoints
        (Point2d.meters 1 1)
        (Point2d.meters 3 4)
        (Point2d.meters 5 1)

Properties

startPoint : QuadraticSpline2d units coordinates -> Point2d units coordinates

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

firstControlPoint : QuadraticSpline2d units coordinates -> Point2d units coordinates

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

secondControlPoint : QuadraticSpline2d units coordinates -> Point2d units coordinates

Get the second control point of a spline.

thirdControlPoint : QuadraticSpline2d units coordinates -> Point2d units coordinates

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

endPoint : QuadraticSpline2d units coordinates -> Point2d units coordinates

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

startDerivative : QuadraticSpline2d units coordinates -> Vector2d 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.

QuadraticSpline2d.startDerivative exampleSpline
--> Vector2d.meters 4 6
endDerivative : QuadraticSpline2d units coordinates -> Vector2d 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.

QuadraticSpline2d.endDerivative exampleSpline
--> Vector2d.meters 4 -6
QuadraticSpline2d 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).

QuadraticSpline2d.boundingBox exampleSpline
--> BoundingBox2d.from
-->     (Point2d.meters 1 1)
-->     (Point2d.meters 5 4)

Evaluation

QuadraticSpline2d units coordinates
-> Float
-> Point2d 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).

QuadraticSpline2d units coordinates
-> Result
(Point2d units coordinates)
(Nondegenerate units coordinates)

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

Nondegenerate units coordinates
-> QuadraticSpline2d units coordinates

Convert a nondegenerate spline back to a general QuadraticSpline2d.

tangentDirection : Nondegenerate units coordinates -> Float -> Direction2d coordinates

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

Nondegenerate units coordinates
-> Float
-> ( Point2d units coordinates, Direction2d coordinates )

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

Transformations

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

QuadraticSpline2d units coordinates
-> QuadraticSpline2d units coordinates

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

Point2d units coordinates
-> Float
-> QuadraticSpline2d units coordinates
-> QuadraticSpline2d units coordinates

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

Point2d units coordinates
-> Angle
-> QuadraticSpline2d units coordinates
-> QuadraticSpline2d units coordinates

Rotate a spline counterclockwise around a given center point by a given angle.

Vector2d units coordinates
-> QuadraticSpline2d units coordinates
-> QuadraticSpline2d units coordinates

Translate a spline by a given displacement.

Direction2d coordinates
-> Quantity Float units
-> QuadraticSpline2d units coordinates
-> QuadraticSpline2d units coordinates

Translate a spline in a given direction by a given distance.

Axis2d units coordinates
-> QuadraticSpline2d units coordinates
-> QuadraticSpline2d units coordinates

Mirror a spline across an axis.

Unit conversions

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

Frame2d units globalCoordinates { defines : localCoordinates }
-> QuadraticSpline2d units globalCoordinates
-> QuadraticSpline2d units localCoordinates

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

Frame2d units globalCoordinates { defines : localCoordinates }
-> QuadraticSpline2d units localCoordinates
-> QuadraticSpline2d 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.

Subdivision

QuadraticSpline2d units coordinates
-> ( QuadraticSpline2d units coordinates
, QuadraticSpline2d units coordinates
)

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

Float
-> QuadraticSpline2d units coordinates
-> ( QuadraticSpline2d units coordinates
, QuadraticSpline2d 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.

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

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

arcLength : ArcLengthParameterized units coordinates -> Quantity Float units

Find the total arc length of a spline, to within the accuracy specified when calling arcLengthParameterized.

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.

ArcLengthParameterized units coordinates
-> Quantity Float units
-> Point2d units coordinates

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

ArcLengthParameterized units coordinates
-> Point2d 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.

ArcLengthParameterized units coordinates
-> Quantity Float units
-> Direction2d coordinates

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

ArcLengthParameterized units coordinates
-> Quantity Float units
-> ( Point2d units coordinates, Direction2d 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 QuadraticSpline2d. If you need to do something fancy, you can extract these two values separately.

ArcLengthParameterized units coordinates
-> QuadraticSpline2d units coordinates

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

Differentiation

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

QuadraticSpline2d units coordinates
-> Float
-> Vector2d 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 : QuadraticSpline2d units coordinates -> Vector2d units coordinates

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