opensolid/geometry/1.0.3

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.Axis3d

Axis3d

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

  • Rotating around 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 Axis3d constructor, for example:

exampleAxis =
    Axis3d
        { originPoint = Point3d ( -2, 1, 3 )
        , direction = Direction3d ( 0, 0.8, -0.6 )
        }

Predefined axes

x : Axis3d

The global X axis.

Axis3d.x
--> Axis3d
-->     { originPoint = Point3d.origin
-->     , direction = Direction3d.x
-->     }
y : Axis3d

The global Y axis.

Axis3d.y
--> Axis3d
-->     { originPoint = Point3d.origin
-->     , direction = Direction3d.y
-->     }
z : Axis3d

The global Z axis.

Axis3d.z
--> Axis3d
-->     { originPoint = Point3d.origin
-->     , direction = Direction3d.z
-->     }

Accessors

originPoint : Axis3d -> Point3d

Get the origin point of an axis.

Axis3d.originPoint exampleAxis
--> Point3d ( -2, 1, 3 )
direction : Axis3d -> Direction3d

Get the direction of an axis.

Axis3d.direction exampleAxis
--> Direction3d ( 0, 0.8, -0.6 )

Transformations

flip : Axis3d -> Axis3d

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

Axis3d.flip exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( -2, 1, 3 )
-->     , direction = Direction3d ( 0, -0.8, 0.6 )
-->     }
moveTo : Point3d -> Axis3d -> Axis3d

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

newOrigin =
    Point3d ( 3, 4, 5 )


Axis3d.moveTo newOrigin exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( 3, 4, 5 ),
-->     , direction = Direction3d ( 0, 0.8, -0.6 )
-->     }
rotateAround : Axis3d -> Float -> Axis3d -> Axis3d

Rotate an axis around another axis by a given angle. The axis to rotate around is given first and the axis to rotate is given last.

Axis3d.rotateAround Axis3d.z (degrees 90) exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( -1, -2, 3 )
-->     , direction = Direction3d ( -0.8, 0, -0.6 )
-->     }
translateBy : Vector3d -> Axis3d -> Axis3d

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

displacement =
    Vector3d ( 3, 3, 3 )


Axis3d.translateBy displacement exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( 1, 4, 6 )
-->     , direction = Direction3d ( 0, 0.8, -0.6 )
-->     }
mirrorAcross : Plane3d -> Axis3d -> Axis3d

Mirror an axis across a plane.

Axis3d.mirrorAcross Plane3d.xy exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( -2, 1, -3 )
-->     , direction = Direction3d ( 0, 0.6, 0.8 )
-->     }
projectOnto : Plane3d -> Axis3d -> Maybe Axis3d

Project an axis onto a plane, returning the axis that is the 'shadow' of the given axis on the given plane. If the given axis is exactly perpendicular to the given plane, returns Nothing.

Axis3d.projectOnto Plane3d.xy exampleAxis
--> Just
-->     (Axis3d
-->         { originPoint = Point3d ( -2, 1, 0 )
-->         , direction = Direction3d ( 0, 1, 0 )
-->         }
-->     )


Axis3d.projectOnto Plane3d.xy Axis3d.z
--> Nothing

Coordinate frames

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

relativeTo : Frame3d -> Axis3d -> Axis3d

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

originPoint =
    Point3d ( 3, 3, 3 )


Axis3d.relativeTo (Frame3d.at originPoint) exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( -5, -2, 0 )
-->     , direction = Direction3d ( 0, 0.8, -0.6 )
-->     }
placeIn : Frame3d -> Axis3d -> Axis3d

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

originPoint =
    Point3d ( 3, 3, 3 )


Axis3d.placeIn (Frame3d.at originPoint) exampleAxis
--> Axis3d
-->     { originPoint = Point3d ( 1, 4, 6 )
-->     , direction = Direction3d ( 0, 0.8, -0.6 )
-->     }

Sketch planes

projectInto : SketchPlane3d -> Axis3d -> Maybe Axis2d

Project an axis into a given sketch plane. Conceptually, this projects the axis onto the plane and then expresses the projected axis in 2D sketch coordinates.

This is only possible if the axis is not perpendicular to the sketch plane; if it is perpendicular, Nothing is returned.

Axis3d.projectInto SketchPlane3d.yz exampleAxis
--> Just
-->     (Axis2d
-->         { originPoint = Point2d ( 1, 3 )
-->         , direction = Direction2d ( 0.8, -0.6 )
-->         }
-->     )


Axis3d.projectInto SketchPlane3d.xy exampleAxis
--> Just
-->     (Axis2d
-->         { originPoint = Point2d ( -2, 1 )
-->         , direction = Direction3d ( 0, 1 )
-->         }
-->     )


Axis3d.projectInto SketchPlane3d.xy Axis3d.z
--> Nothing