A LineSegment3d is a line between two points in 3D. This module contains
functionality such as:
Line segments can be constructed by passing a tuple of start and end points to
the LineSegment3d constructor, for example
exampleLineSegment =
LineSegment3d
( Point3d ( 1, 2, 3 )
, Point3d ( 4, 5, 6 )
)Get the start point of a line segment.
LineSegment3d.startPoint exampleLineSegment
-- Point3d ( 1, 2, 3 )Get the end point of a line segment.
LineSegment3d.endPoint exampleLineSegment
-- Point3d ( 4, 5, 6 )Get the endpoints of a line segment as a tuple.
( p1, p2 ) =
LineSegment3d.endpoints lineSegmentReverse a line segment, swapping its start and end points.
LineSegment3d.reverse exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 4, 5, 6 )
-- , Point3d ( 1, 2, 3 )
-- )Get the midpoint of a line segment.
LineSegment3d.midpoint exampleLineSegment
-- Point3d ( 2.5, 3.5, 4.5 )Interpolate a line segment between its start and end points; a value of 0.0 corresponds to the start point of the line segment, a value of 0.5 corresponds to its midpoint and a value of 1.0 corresponds to its end point. Negative values or values greater than 1 can be used to extrapolate.
LineSegment3d.interpolate exampleLineSegment (1 / 3)
-- Point3d ( 2, 4, 5 )
LineSegment3d.interpolate exampleLineSegment (-1 / 3)
-- Point3d ( 0, 1, 2 )Get the length of a line segment.
LineSegment3d.length exampleLineSegment
-- 5.1962Get the squared length of a line segment. Slightly more efficient than
length since it avoids a square root.
LineSegment3d.squaredLength exampleLineSegment
-- 27Get the direction from a line segment's start point to its end point. If the
line segment has zero length (the start and end points are the same), returns
Nothing.
LineSegment3d.direction exampleLineSegment
-- Just (Direction3d ( 0.5774, 0.5774, 0.5774 ))Get an arbitrary direction perpendicular to a line segment. If the line
segment has zero length, returns Nothing.
LineSegment3d.normalDirection exampleLineSegment
-- Just (Direction3d ( 0, -0.7071, 0.7071 ))Get the vector from a line segment's start point to its end point.
LineSegment3d.vector exampleLineSegment
-- Vector3d ( 2, 2, 2 )Transforming a line segment is equivalent to transforming its start and end points and forming a new line segment between the resulting points.
Scale a line segment about the given center point by the given scale.
point =
Point3d ( 1, 1, 1 )
LineSegment3d.scaleAbout point 2 exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 1, 3, 5 )
-- , Point3d ( 7, 9, 11 )
-- )Rotate around a given axis by a given angle (in radians).
LineSegment3d.rotateAround Axis3d.z (degrees 90) exampleLineSegment
-- LineSegment3d
-- ( Point3d ( -2, 1, 3 )
-- , Point3d ( -5, 4, 6 )
-- )Translate a line segment by a given displacement.
displacement =
Vector3d ( 1, 2, 3 )
LineSegment3d.translateBy displacement exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 2, 4, 6 )
-- , Point3d ( 5, 7, 9 )
-- )Mirror a line segment across a plane.
LineSegment3d.mirrorAcross Plane3d.xy exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 1, 2, -3 )
-- , Point3d ( 4, 5, -6 )
-- )Project a line segment onto a plane.
LineSegment3d.projectOnto Plane3d.yz exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 0, 2, 3 )
-- , Point3d ( 0, 5, 6 )
-- )Transform the start and end points of a line segment by a given function
and create a new line segment from the resulting points. Most other
transformation functions can be defined in terms of map; for example,
LineSegment3d.projectOnto Plane3d.xyis equivalent to
LineSegment3d.map (Point3d.projectOnto Plane3d.xy)Functions for transforming line segments between local and global coordinates in different coordinate frames.
Take a line segment defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame3d.at (Point3d ( 1, 2, 3 ))
LineSegment3d.relativeTo localFrame exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 0, 0, 0 )
-- , Point3d ( 3, 3, 3 )
-- )Take a line segment considered to be defined in local coordinates relative to a given reference frame, and return that line segment expressed in global coordinates.
localFrame =
Frame3d.at (Point3d ( 1, 2, 3 ))
LineSegment3d.placeIn localFrame exampleLineSegment
-- LineSegment3d
-- ( Point3d ( 2, 4, 6 )
-- , Point3d ( 5, 7, 9 )
-- )Project a line segment into a given sketch plane. Conceptually, this projects the line segment onto the plane and then expresses the projected line segment in 2D sketch coordinates.
LineSegment3d.projectInto SketchPlane3d.xy exampleLineSegment
-- LineSegment2d
-- ( Point2d ( 1, 2 )
-- , Point2d ( 4, 5 )
-- )
LineSegment3d.projectInto SketchPlane3d.yz exampleLineSegment
-- LineSegment2d
-- ( Point2d ( 2, 3 )
-- , Point2d ( 5, 6 )
-- )
LineSegment3d.projectInto SketchPlane3d.zx exampleLineSegment
-- LineSegment2d
-- ( Point2d ( 3, 1 )
-- , Point2d ( 6, 4 )
-- )Get the minimal bounding box containing a line segment.
LineSegment3d.boundingBox exampleLineSegment
-- BoundingBox3d
-- { minX = 1
-- , maxX = 4
-- , minY = 2
-- , maxY = 5
-- , minZ = 3
-- , maxZ = 6
-- }
Construct a line segment collinear with the given axis, with its endpoints at the given distances from the axis' origin point.