ianmackenzie/elm-geometry-prerelease/1.0.1

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:

  • Mirroring across the axis
  • Projecting onto the axis
  • Measuring distance along the axis from the origin point
type alias Axis2d =
Axis2d

Constants

x : Axis2d

The global X axis.

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

The global Y axis.

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

Constructors

through : Point2d -> Direction2d -> Axis2d

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

exampleAxis =
    Axis2d.through (Point2d.fromCoordinates ( 1, 3 ))
        (Direction2d.fromAngle (degrees 30))
withDirection : Direction2d -> Point2d -> Axis2d

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

Properties

originPoint : Axis2d -> Point2d

Get the origin point of an axis.

Axis2d.originPoint exampleAxis
--> Point2d.fromCoordinates ( 1, 3 )
direction : Axis2d -> Direction2d

Get the direction of an axis.

Axis2d.direction exampleAxis
--> Direction2d.fromAngle (degrees 30)

Transformations

reverse : Axis2d -> Axis2d

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

Axis2d.reverse exampleAxis
--> Axis2d.through (Point2d.fromCoordinates ( 1, 3 ))
-->     (Direction2d.fromAngle (degrees -150))
moveTo : Point2d -> Axis2d -> Axis2d

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

newOrigin =
    Point2d.fromCoordinates ( 4, 5 )


Axis2d.moveTo newOrigin exampleAxis
--> Axis2d.through (Point2d.fromCoordinates ( 4, 5 ))
-->     (Direction2d.fromAngle (degrees 30))
rotateAround : Point2d -> Float -> Axis2d -> Axis2d

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.

exampleAxis
    |> Axis2d.rotateAround Point2d.origin (degrees 90)
--> Axis2d.through (Point2d.fromCoordinates ( -3, 1 ))
-->     (Direction2d.fromAngle (degrees 120))
translateBy : Vector2d -> Axis2d -> Axis2d

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

displacement =
    Vector2d.fromComponents ( 2, 3 )


Axis2d.translateBy displacement exampleAxis
--> Axis2d.through (Point2d.fromCoordinates ( 3, 6 ))
-->     (Direction2d.fromAngle (degrees 30))
translateIn : Direction2d -> Float -> Axis2d -> Axis2d

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

Axis2d.translateIn direction distance

is equivalent to

Axis2d.translateBy
    (Vector2d.withLength distance direction)
mirrorAcross : Axis2d -> Axis2d -> Axis2d

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.fromCoordinates ( 1, -3 ))
-->     (Direction2d.fromAngle (degrees -30))

Coordinate conversions

relativeTo : Frame2d -> Axis2d -> Axis2d

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

frame =
    Frame2d.atPoint (Point2d.fromCoordinates ( 2, 3 ))


Axis2d.relativeTo frame exampleAxis
--> Axis2d.through (Point2d.fromCoordinates ( -1, 0 ))
-->     (Direction2d.fromAngle (degrees 30))
placeIn : Frame2d -> Axis2d -> Axis2d

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

frame =
    Frame2d.atPoint (Point2d.fromCoordinates ( 2, 3 ))


Axis2d.placeIn frame exampleAxis
--> Axis2d.through (Point2d.fromCoordinates ( 3, 6 ))
-->     (Direction2d.fromAngle (degrees 30))