opensolid/geometry/1.1.0

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.Axis2d

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

Axes can by constructed by passing a record with originPoint and direction fields to the Axis2d constructor, for example:

exampleAxis =
    Axis2d
        { originPoint = Point2d ( 1, 3 )
        , direction = Direction2d ( 0.8, 0.6 )
        }

Predefined axes

x : Axis2d

The global X axis.

Axis2d.x
--> Axis2d
-->     { originPoint = Point2d.origin
-->     , direction = Direction2d.x
-->     }
y : Axis2d

The global Y axis.

Axis2d.y
--> Axis2d
-->     { originPoint = Point2d.origin
-->     , direction = Direction2d.y
-->     }

Accessors

originPoint : Axis2d -> Point2d

Get the origin point of an axis.

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

Get the direction of an axis.

Axis2d.direction exampleAxis
--> Direction2d ( 0.8, 0.6 )

Transformations

flip : Axis2d -> Axis2d

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

Axis2d.flip exampleAxis
--> Axis2d
-->     { originPoint = Point2d ( 1, 3 )
-->     , direction = Direction2d ( -0.8, -0.6 )
-->     }
moveTo : Point2d -> Axis2d -> Axis2d

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

newOrigin =
    Point2d ( 4, 5 )


Axis2d.moveTo newOrigin exampleAxis
--> Axis2d
-->     { originPoint = Point2d ( 4, 5 )
-->     , direction = Direction2d ( 0.8, 0.6 )
-->     }
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.

Axis2d.rotateAround Point2d.origin (degrees 90) exampleAxis
--> Axis2d
-->     { originPoint = Point2d ( -3, 1 )
-->     , direction = Direction2d ( -0.6, 0.8 )
-->     }
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 ( 2, 3 )


Axis2d.translateBy displacement exampleAxis
--> Axis2d
-->     { originPoint = Point2d ( 3, 6 )
-->     , direction = Direction2d ( 0.8, 0.6 )
-->     }
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
-->     { originPoint = Point2d ( 1, -3 )
-->     , direction = Direction2d ( 0.8, -0.6 )
-->     }

Coordinate frames

Functions for transforming axes between local and global coordinates in different coordinate frames.

relativeTo : Frame2d -> Axis2d -> Axis2d

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

originPoint =
    Point2d ( 2, 3 )


Axis2d.relativeTo (Frame2d.at originPoint) exampleAxis
--> Axis2d
-->     { originPoint = Point2d ( -1, 0 )
-->     , direction = Direction2d ( 0.8, 0.6 )
-->     }
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.

originPoint =
    Point2d ( 2, 3 )


Axis2d.placeIn (Frame2d.at originPoint) exampleAxis
--> Axis2d
-->     { originPoint = Point2d ( 3, 6 )
-->     , direction = Direction2d ( 0.8, 0.6 )
-->     }

Sketch planes

placeOnto : SketchPlane3d -> Axis2d -> Axis3d

Take an axis defined in 2D coordinates within a particular sketch plane and return the corresponding axis in 3D.

Axis2d.placeOnto SketchPlane3d.xy exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( 2, 3, 0 )
-->     , direction = Direction3d ( 0.8, 0.6, 0 )
-->     }


Axis2d.placeOnto SketchPlane3d.zx exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( 3, 0, 2 )
-->     , direction = Direction3d ( 0.6, 0, 0.8 )
-->     }