ianmackenzie / elm-geometry / Axis2d

An Axis2d represents an infinitely long straight line in 2D and is defined by an origin point and direction. Axes have several uses, such as:


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

Constants

x : Axis2d units coordinates

The global X axis.

Axis2d.x
--> Axis2d.through Point2d.origin Direction2d.x

y : Axis2d units coordinates

The global Y axis.

Axis2d.y
--> Axis2d.through Point2d.origin Direction2d.y

Constructors

through : Point2d units coordinates -> Direction2d coordinates -> Axis2d units coordinates

Construct an axis through the given origin point with the given direction.

exampleAxis =
    Axis2d.through (Point2d.meters 1 3)
        (Direction2d.degrees 30)

withDirection : Direction2d coordinates -> Point2d units coordinates -> Axis2d units coordinates

Construct an axis with the given direction, through the given origin point. Flipped version of through. Having both versions allow you to do different things with partial application:

-- A list of axes in different directions all passing
-- through the same origin point
List.map (Axis2d.through point) directions

-- A list of parallel axes (all having the same
-- direction) through different points
List.map (Axis2d.withDirection direction) points

throughPoints : Point2d units coordinates -> Point2d units coordinates -> Maybe (Axis2d units coordinates)

Attempt to construct an axis through the two given points;

Axis2d.throughPoints p1 p2

is equivalent to

Maybe.map (Axis2d.through firstPoint)
    (Direction2d.from firstPoint secondPoint)

Properties

originPoint : Axis2d units coordinates -> Point2d units coordinates

Get the origin point of an axis.

Axis2d.originPoint exampleAxis
--> Point2d.meters 1 3

direction : Axis2d units coordinates -> Direction2d coordinates

Get the direction of an axis.

Axis2d.direction exampleAxis
--> Direction2d.degrees 30

Intersection

intersectionPoint : Axis2d units coordinates -> Axis2d units coordinates -> Maybe (Point2d units coordinates)

Find the intersection point between two axes. If none exists (the axes are parallel) then Nothing is returned.

Transformations

reverse : Axis2d units coordinates -> Axis2d units coordinates

Reverse the direction of an axis while keeping the same origin point.

moveTo : Point2d units coordinates -> Axis2d units coordinates -> Axis2d units coordinates

Move an axis so that it has the given origin point but unchanged direction.

rotateAround : Point2d units coordinates -> Angle -> Axis2d units coordinates -> Axis2d units coordinates

Rotate an axis around a given center point by a given angle. Rotates the axis' origin point around the given point by the given angle and the axis' direction by the given angle.

rotateBy : Angle -> Axis2d units coordinates -> Axis2d units coordinates

Rotate an axis around its own origin point by the given angle.

translateBy : Vector2d units coordinates -> Axis2d units coordinates -> Axis2d units coordinates

Translate an axis by a given displacement. Applies the given displacement to the axis' origin point and leaves the direction unchanged.

translateIn : Direction2d coordinates -> Quantity Basics.Float units -> Axis2d units coordinates -> Axis2d units coordinates

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

mirrorAcross : Axis2d units coordinates -> Axis2d units coordinates -> Axis2d units coordinates

Mirror one axis across another. The axis to mirror across is given first and the axis to mirror is given second.

Axis2d.mirrorAcross Axis2d.x exampleAxis
--> Axis2d.through (Point2d.meters 1 -3)
-->     (Direction2d.degrees -30)

Unit conversions

at : Quantity Basics.Float (Quantity.Rate units2 units1) -> Axis2d units1 coordinates -> Axis2d units2 coordinates

Convert an axis 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) -> Axis2d units1 coordinates -> Axis2d units2 coordinates

Convert an axis 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 : Geometry.Types.Frame2d units globalCoordinates { defines : localCoordinates } -> Axis2d units globalCoordinates -> Axis2d units localCoordinates

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

placeIn : Geometry.Types.Frame2d units globalCoordinates { defines : localCoordinates } -> Axis2d units localCoordinates -> Axis2d units globalCoordinates

Take an axis defined in local coordinates relative to a given reference frame, and return that axis expressed in global coordinates.