opensolid/geometry/2.1.0

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.QuadraticSpline2d

QuadraticSpline2d

A QuadraticSpline2d is a quadratic Bézier curve in 2D defined by three control points. 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 =
QuadraticSpline2d

Constructors

fromControlPoints : ( Point2d, Point2d, Point2d ) -> QuadraticSpline2d

Construct a spline from its three control points:

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

Properties

controlPoints : QuadraticSpline2d -> ( Point2d, Point2d, Point2d )

Get the control points of a spline as a tuple.

( p1, p2, p3 ) =
    QuadraticSpline2d.controlPoints exampleSpline




--> p1 = Point2d.fromCoordinates ( 1, 1 )
--> p2 = Point2d.fromCoordinates ( 3, 4 )
--> p3 = Point2d.fromCoordinates ( 5, 1 )
startPoint : QuadraticSpline2d -> Point2d

Get the start point of a spline. This is equal to the spline's first control point.

QuadraticSpline2d.startPoint exampleSpline
--> Point2d.fromCoordinates ( 1, 1 )
endPoint : QuadraticSpline2d -> Point2d

Get the end point of a spline. This is equal to the spline's last control point.

QuadraticSpline2d.endPoint exampleSpline
--> Point2d.fromCoordinates ( 5, 1 )
startDerivative : QuadraticSpline2d -> Vector2d

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.fromComponents ( 4, 6 )
endDerivative : QuadraticSpline2d -> Vector2d

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.fromComponents ( 4, -6 )

Evaluation

pointOn : QuadraticSpline2d -> Float -> Point2d

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.

QuadraticSpline2d.pointOn exampleSpline 0
--> Point2d.fromCoordinates ( 1, 1 )


QuadraticSpline2d.pointOn exampleSpline 0.5
--> Point2d.fromCoordinates ( 3, 2.5 )


QuadraticSpline2d.pointOn exampleSpline 1
--> Point2d.fromCoordinates ( 5, 1 )
derivative : QuadraticSpline2d -> Float -> Vector2d

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.

QuadraticSpline2d.derivative exampleSpline 0
--> Vector2d.fromComponents ( 4, 6 )


QuadraticSpline2d.derivative exampleSpline 0.5
--> Vector2d.fromComponents ( 4, 0 )


QuadraticSpline2d.derivative exampleSpline 1
--> Vector2d.fromComponents ( 4, -6 )

Note that the derivative interpolates linearly from end to end.

evaluate : QuadraticSpline2d -> Float -> ( Point2d, Vector2d )

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;

QuadraticSpline2d.evaluate spline t

is equivalent to

( QuadraticSpline2d.pointOn spline t
, QuadraticSpline2d.derivative spline t
)

but is more efficient.

Transformations

reverse : QuadraticSpline2d -> QuadraticSpline2d

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

QuadraticSpline2d.reverse exampleSpline
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 5, 1 )
-->     , Point2d.fromCoordinates ( 3, 4 )
-->     , Point2d.fromCoordinates ( 1, 1 )
-->     )
scaleAbout : Point2d -> Float -> QuadraticSpline2d -> QuadraticSpline2d

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

examplePolyline
    |> QuadraticSpline2d.scaleAbout Point2d.origin 2
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 2, 2 )
-->     , Point2d.fromCoordinates ( 6, 8 )
-->     , Point2d.fromCoordinates ( 10, 2 )
-->     )
rotateAround : Point2d -> Float -> QuadraticSpline2d -> QuadraticSpline2d

Rotate a spline counterclockwise around a given center point by a given angle (in radians).

examplePolyline
    |> QuadraticSpline2d.rotateAround Point2d.origin
        (degrees 90)
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( -1, 1 )
-->     , Point2d.fromCoordinates ( -4, 3 )
-->     , Point2d.fromCoordinates ( -1, 5 )
-->     )
translateBy : Vector2d -> QuadraticSpline2d -> QuadraticSpline2d

Translate a spline by a given displacement.

displacement =
    Vector2d.fromComponents ( 2, 3 )


exampleSpline
    |> QuadraticSpline2d.translateBy displacement
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 3, 4 )
-->     , Point2d.fromCoordinates ( 5, 7 )
-->     , Point2d.fromCoordinates ( 7, 4 )
-->     )
mirrorAcross : Axis2d -> QuadraticSpline2d -> QuadraticSpline2d

Mirror a spline across an axis.

QuadraticSpline2d.mirrorAcross Axis2d.x exampleSpline
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 1, -1 )
-->     , Point2d.fromCoordinates ( 3, -4 )
-->     , Point2d.fromCoordinates ( 5, -1 )
-->     )

Coordinate conversions

relativeTo : Frame2d -> QuadraticSpline2d -> QuadraticSpline2d

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

localFrame =
    Frame2d.atPoint (Point2d.fromCoordinates ( 1, 2 ))


QuadraticSpline2d.relativeTo localFrame exampleSpline
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 0, -1 )
-->     , Point2d.fromCoordinates ( 2, 2 )
-->     , Point2d.fromCoordinates ( 4, -1 )
-->     )
placeIn : Frame2d -> QuadraticSpline2d -> QuadraticSpline2d

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 =
    Frame2d.atPoint (Point2d.fromCoordinates ( 1, 2 ))


QuadraticSpline2d.placeIn localFrame exampleSpline
--> QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 2, 3 )
-->     , Point2d.fromCoordinates ( 4, 6 )
-->     , Point2d.fromCoordinates ( 6, 3 )
-->     )

Subdivision

bisect : QuadraticSpline2d -> ( QuadraticSpline2d, QuadraticSpline2d )

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

QuadraticSpline2d.bisect exampleSpline
--> ( QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 1, 1 )
-->     , Point2d.fromCoordinates ( 2, 2.5 )
-->     , Point2d.fromCoordinates ( 3, 2.5 )
-->     )
--> , QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 3, 2.5 )
-->     , Point2d.fromCoordinates ( 4, 2.5 )
-->     , Point2d.fromCoordinates ( 5, 1 )
-->     )
--> )
Float
-> QuadraticSpline2d
-> ( QuadraticSpline2d, QuadraticSpline2d )

Split a spline at a particular parameter value (in the range 0 to 1), resulting in two smaller splines.

QuadraticSpline2d.splitAt 0.75 exampleSpline
--> ( QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 1, 1 )
-->     , Point2d.fromCoordinates ( 2.5, 3.25 )
-->     , Point2d.fromCoordinates ( 4, 2.125 )
-->     )
--> , QuadraticSpline2d.fromControlPoints
-->     ( Point2d.fromCoordinates ( 4, 2.125 )
-->     , Point2d.fromCoordinates ( 4.5, 1.75 )
-->     , Point2d.fromCoordinates ( 5, 1 )
-->     )
--> )

Arc length parameterization

A spline that has been parameterized by arc length.

arcLengthParameterized : Float -> QuadraticSpline2d -> ArcLengthParameterized

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 =
    QuadraticSpline2d.arcLengthParameterized
        tolerance
        exampleSpline
arcLength : ArcLengthParameterized -> Float

Find the total arc length of a spline. This will be accurate to within the tolerance given when calling arcLengthParameterized.

arcLength : Float
arcLength =
    QuadraticSpline2d.arcLength parameterizedSpline


arcLength
--> 5.1986
pointAlong : ArcLengthParameterized -> Float -> Maybe Point2d

Try 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:

QuadraticSpline2d.pointAlong parameterizedSpline
    (arcLength / 4)
--> Just (Point2d.fromCoordinates ( 1.8350, 1.9911 ))

Note that this is not the same as evaulating at a parameter value of 1/4:

QuadraticSpline2d.pointOn exampleSpline 0.25
--> Point2d.fromCoordinates ( 2, 2.125 )

If the given arc length is less than zero or greater than the arc length of the spline, Nothing is returned.

tangentAlong : ArcLengthParameterized -> Float -> Maybe Direction2d

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:

QuadraticSpline2d.tangentAlong parameterizedSpline
    (arcLength / 4)
--> Just (Direction2d.fromAngle (degrees 41.145))

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.

arcLengthToParameterValue : ArcLengthParameterized -> Float -> Maybe Float

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.

QuadraticSpline2d.arcLengthToParameterValue
    parameterizedSpline
    (arcLength / 4)
--> Just 0.2088
parameterValueToArcLength : ArcLengthParameterized -> Float -> Maybe Float

Try 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.

QuadraticSpline2d.parameterValueToArcLength
    parameterizedSpline
    0.25
--> Just 1.5122

Low level

Low level functionality that you are unlikely to need to use directly.

derivativeMagnitude : QuadraticSpline2d -> Float -> Float

Find the magnitude of the derivative to a spline at a particular parameter value;

QuadraticSpline2d.derivativeMagnitude spline t

is equivalent to

Vector2d.length (QuadraticSpline2d.derivative spline t)

but more efficient since it avoids any intermediate Vector2d allocation.

secondDerivative : QuadraticSpline2d -> Vector2d

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