An EllipticalArc2d
is a section of an Ellipse2d
with a start and end
point. This module includes functionality for
The startAngle
and sweptAngle
values referred to below are not actually
proper angles but instead refer to values of the ellipse parameter.
However, in simple cases you don't need to worry about the difference - if
startAngle
and sweptAngle
are both multiples of 90 degrees, then you can
treat them as actual angles and everything will behave as you expect.
Geometry.Types.EllipticalArc2d units coordinates
with : { centerPoint : Point2d units coordinates, xDirection : Direction2d coordinates, xRadius : Quantity Basics.Float units, yRadius : Quantity Basics.Float units, startAngle : Angle, sweptAngle : Angle } -> EllipticalArc2d units coordinates
Construct an elliptical arc from its center point, X direction, X and Y radii, start angle and swept angle. If you pass a negative radius, the absolute value will be used.
For example, to construct a simple 90 degree elliptical arc, you might use
exampleArc =
EllipticalArc2d.with
{ centerPoint = Point2d.origin
, xDirection = Direction2d.x
, xRadius = Length.meters 2
, yRadius = Length.meters 1
, startAngle = Angle.degrees 0
, sweptAngle = Angle.degrees 90
}
To make an inclined 180 degree elliptical arc, you might use
EllipticalArc2d.with
{ centerPoint = Point2d.origin
, xDirection = Direction2d.degrees 30
, xRadius = Length.meters 2
, yRadius = Length.meters 1
, startAngle = Angle.degrees -90
, sweptAngle = Angle.degrees 180
}
fromEndpoints : { startPoint : Point2d units coordinates, endPoint : Point2d units coordinates, xRadius : Quantity Basics.Float units, yRadius : Quantity Basics.Float units, xDirection : Direction2d coordinates, sweptAngle : SweptAngle } -> Maybe (EllipticalArc2d units coordinates)
Attempt to construct an elliptical arc from its endpoints, X direction, and X and Y radii. For any given valid set of these inputs, there are four possible solutions, so you also need to specify which of the four solutions you want - whether the swept angle of the arc should be less than or greater than 180 degrees, and whether the swept angle should be positive (counterclockwise) or negative (clockwise).
This function will return Nothing
if no solution can found. Typically this
means that the two endpoints are too far apart, but could also mean that one of
the specified radii was negative or zero, or the two given points were
coincident.
The behavior of this function is very close to the SVG spec,
but when 'out of range' parameters are given this function will simply return
Nothing
instead of attempting to degrade gracefully (for example, by
increasing X and Y radius slightly if the given endpoints are slightly too far
apart). Note that this means this function is dangerous to use for 180 degree
arcs, since then slight numerical roundoff can mean the difference between a
solution being found and not - for 180 degree arcs it is safer to use
EllipticalArc2d.with
instead.
startAngle : EllipticalArc2d units coordinates -> Angle
The start angle of an elliptical arc is the value of the ellipse parameter at the start point of the arc.
EllipticalArc2d.startAngle exampleArc
--> Angle.degrees 0
sweptAngle : EllipticalArc2d units coordinates -> Angle
The swept angle of an elliptical arc is the difference between values of the ellipse parameter from the start point to the end point of the arc.
EllipticalArc2d.sweptAngle exampleArc
--> Angle.degrees 90
startPoint : EllipticalArc2d units coordinates -> Point2d units coordinates
Get the start point of an elliptical arc.
centerPoint : EllipticalArc2d units coordinates -> Point2d units coordinates
axes : EllipticalArc2d units coordinates -> Frame2d units coordinates defines
xAxis : EllipticalArc2d units coordinates -> Axis2d units coordinates
yAxis : EllipticalArc2d units coordinates -> Axis2d units coordinates
xDirection : EllipticalArc2d units coordinates -> Direction2d coordinates
yDirection : EllipticalArc2d units coordinates -> Direction2d coordinates
xRadius : EllipticalArc2d units coordinates -> Quantity Basics.Float units
yRadius : EllipticalArc2d units coordinates -> Quantity Basics.Float units
boundingBox : EllipticalArc2d units coordinates -> BoundingBox2d units coordinates
Get the bounding box of an elliptical arc.
signedDistanceAlong : Axis2d units coordinates -> EllipticalArc2d units coordinates -> Quantity.Interval.Interval Basics.Float units
Project an elliptical arc onto an axis, returning the range of projected distances along that axis.
pointOn : EllipticalArc2d units coordinates -> Basics.Float -> Point2d units coordinates
Get the point along an elliptical arc at a given parameter value.
Represents a nondegenerate spline (one that has finite, non-zero length).
nondegenerate : EllipticalArc2d units coordinates -> Result (Point2d units coordinates) (Nondegenerate units coordinates)
Attempt to construct a nondegenerate elliptical arc from a general
EllipticalArc2d
. If the arc is in fact degenerate (consists of a single
point), returns an Err
with that point.
fromNondegenerate : Nondegenerate units coordinates -> EllipticalArc2d units coordinates
Convert a nondegenerate elliptical arc back to a general EllipticalArc2d
.
tangentDirection : Nondegenerate units coordinates -> Basics.Float -> Direction2d coordinates
Get the tangent direction to a nondegenerate elliptical arc at a given parameter value.
sample : Nondegenerate units coordinates -> Basics.Float -> ( Point2d units coordinates, Direction2d coordinates )
Get both the point and tangent direction of a nondegenerate elliptical arc at a given parameter value.
segments : Basics.Int -> EllipticalArc2d units coordinates -> Polyline2d units coordinates
Approximate an elliptical arc 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 -> EllipticalArc2d units coordinates -> Polyline2d units coordinates
Approximate an elliptical arc as a polyline, within a given tolerance. Every point on the returned polyline will be within the given tolerance of the elliptical arc.
These transformations generally behave just like the ones in the Point2d
module.
reverse : EllipticalArc2d units coordinates -> EllipticalArc2d units coordinates
Reverse the direction of an elliptical arc, so that the start point becomes the end point and vice versa. Does not change the shape of the arc or any properties of the underlying ellipse.
scaleAbout : Point2d units coordinates -> Basics.Float -> EllipticalArc2d units coordinates -> EllipticalArc2d units coordinates
Scale an elliptical arc about a given point by a given scale.
rotateAround : Point2d units coordinates -> Angle -> EllipticalArc2d units coordinates -> EllipticalArc2d units coordinates
Rotate an elliptical arc around a given point by a given angle.
translateBy : Vector2d units coordinates -> EllipticalArc2d units coordinates -> EllipticalArc2d units coordinates
Translate an elliptical arc by a given displacement.
translateIn : Direction2d coordinates -> Quantity Basics.Float units -> EllipticalArc2d units coordinates -> EllipticalArc2d units coordinates
Translate an elliptical arc in a given direction by a given distance.
mirrorAcross : Axis2d units coordinates -> EllipticalArc2d units coordinates -> EllipticalArc2d units coordinates
Mirror an elliptical arc across a given axis.
at : Quantity Basics.Float (Quantity.Rate units2 units1) -> EllipticalArc2d units1 coordinates -> EllipticalArc2d units2 coordinates
Convert an elliptical arc 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) -> EllipticalArc2d units1 coordinates -> EllipticalArc2d units2 coordinates
Convert an elliptical arc 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.
relativeTo : Frame2d units globalCoordinates { defines : localCoordinates } -> EllipticalArc2d units globalCoordinates -> EllipticalArc2d units localCoordinates
Take an elliptical arc defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
placeIn : Frame2d units globalCoordinates { defines : localCoordinates } -> EllipticalArc2d units localCoordinates -> EllipticalArc2d units globalCoordinates
Take an elliptical arc considered to be defined in local coordinates relative to a given reference frame, and return that arc expressed in global coordinates.
An elliptical arc 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 elliptical arc, with a given accuracy.
pointAlong : ArcLengthParameterized units coordinates -> Quantity Basics.Float units -> Point2d units coordinates
Get the point along an elliptical arc at a given arc length.
midpoint : ArcLengthParameterized units coordinates -> Point2d units coordinates
Get the midpoint of an elliptical arc. Note that this is the point half way along the elliptical arc 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 -> Direction2d coordinates
Get the tangent direction along an elliptical arc at a given arc length.
sampleAlong : ArcLengthParameterized units coordinates -> Quantity Basics.Float units -> ( Point2d units coordinates, Direction2d coordinates )
Get the point and tangent direction along an elliptical arc at a given arc length.
An ArcLengthParameterized
value is a combination of an
ArcLengthParameterization
and an
underlying EllipticalArc2d
. 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 -> EllipticalArc2d units coordinates
You are unlikely to need to use these functions directly, but they are useful if you are writing low-level geometric algorithms.
firstDerivative : EllipticalArc2d units coordinates -> Basics.Float -> Vector2d units coordinates
Get the first derivative of an elliptical arc at a given parameter value.
firstDerivativeBoundingBox : EllipticalArc2d units coordinates -> VectorBoundingBox2d units coordinates
Get the bounds on the first derivative of an elliptical arc.
maxSecondDerivativeMagnitude : EllipticalArc2d units coordinates -> Quantity Basics.Float units
Find a conservative upper bound on the magnitude of the second derivative of an elliptical arc. This can be useful when determining error bounds for various kinds of linear approximations.
numApproximationSegments : Quantity Basics.Float units -> EllipticalArc2d units coordinates -> Basics.Int
Determine the number of linear segments needed to approximate an elliptical arc to within a given tolerance.