A Polyline2d represents a sequence of vertices in 2D connected by line
segments. This module contains a variety of polyline-related functionality, such
as
Construct a polyline from a list of vertices:
stepShape =
Polyline2d.fromVertices
[ Point2d.fromCoordinates ( 0, 0 )
, Point2d.fromCoordinates ( 1, 0 )
, Point2d.fromCoordinates ( 1, 1 )
, Point2d.fromCoordinates ( 2, 1 )
]Get the vertices of a polyline.
Polyline2d.vertices stepShape
--> [ Point2d.fromCoordinates ( 0, 0 )
--> , Point2d.fromCoordinates ( 1, 0 )
--> , Point2d.fromCoordinates ( 1, 1 )
--> , Point2d.fromCoordinates ( 2, 1 )
--> ]Get the individual segments of a polyline.
Polyline2d.segments stepShape
--> [ LineSegment2d.fromEndpoints
--> ( Point2d.fromCoordinates ( 0, 0 )
--> , Point2d.fromCoordinates ( 1, 0 )
--> )
--> , LineSegment2d.fromEndpoints
--> ( Point2d.fromCoordinates ( 1, 0 )
--> , Point2d.fromCoordinates ( 1, 1 )
--> )
--> , LineSegment2d.fromEndpoints
--> ( Point2d.fromCoordinates ( 1, 1 )
--> , Point2d.fromCoordinates ( 2, 1 )
--> )
--> ]Get the overall length of a polyline (the sum of the lengths of its segments).
Polyline2d.length stepShape
--> 3Get the minimal bounding box containing a given polyline. Returns Nothing
if the polyline has no vertices.
Polyline2d.boundingBox stepShape
--> Just
--> (BoundingBox2d.fromExtrema
--> { minX = 0
--> , maxX = 2
--> , minY = 0
--> , maxY = 1
--> }
--> )Transforming a polyline is equivalent to transforming each of its vertices.
Scale a polyline about a given center point by a given scale.
point =
Point2d.fromCoordinates ( 1, 0 )
Polyline2d.scaleAbout point 2 stepShape
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( -1, 0 )
--> , Point2d.fromCoordinates ( 1, 0 )
--> , Point2d.fromCoordinates ( 1, 2 )
--> , Point2d.fromCoordinates ( 3, 2 )
--> ]Rotate a polyline around the given center point counterclockwise by the given angle (in radians).
stepShape
|> Polyline2d.rotateAround Point2d.origin
(degrees 90)
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( 0, 0 )
--> , Point2d.fromCoordinates ( 0, 1 )
--> , Point2d.fromCoordinates ( -1, 1 )
--> , Point2d.fromCoordinates ( -1, 2 )
--> ]Translate a polyline by the given displacement.
displacement =
Vector2d.fromComponents ( 2, 3 )
Polyline2d.translateBy displacement stepShape
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( 2, 3 )
--> , Point2d.fromCoordinates ( 3, 3 )
--> , Point2d.fromCoordinates ( 3, 4 )
--> , Point2d.fromCoordinates ( 4, 4 )
--> ]Translate a polyline in a given direction by a given distance;
Polyline2d.translateIn direction distanceis equivalent to
Polyline2d.translateBy
(Vector2d.withLength distance direction)Mirror a polyline across the given axis.
Polyline2d.mirrorAcross Axis2d.x stepShape
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( 0, 0 )
--> , Point2d.fromCoordinates ( 1, 0 )
--> , Point2d.fromCoordinates ( 1, -1 )
--> , Point2d.fromCoordinates ( 2, -1 )
--> ]Project (flatten) a polyline onto the given axis.
Polyline2d.projectOnto Axis2d.x stepShape
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( 0, 0 )
--> , Point2d.fromCoordinates ( 1, 0 )
--> , Point2d.fromCoordinates ( 1, 0 )
--> , Point2d.fromCoordinates ( 2, 0 )
--> ]Transform each vertex of a polyline by the given function. All other
transformations can be defined in terms of mapVertices; for example,
Polyline2d.mirrorAcross axisis equivalent to
Polyline2d.mapVertices (Point2d.mirrorAcross axis)Take a polyline defined in global coordinates, and return it expressed in local coordinates relative to a given reference frame.
localFrame =
Frame2d.atPoint (Point2d.fromCoordinates ( 1, 2 ))
Polyline2d.relativeTo localFrame stepShape
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( -1, -2 )
--> , Point2d.fromCoordinates ( 0, -2 )
--> , Point2d.fromCoordinates ( 0, -1 )
--> , Point2d.fromCoordinates ( 1, -1 )
--> ]Take a polyline considered to be defined in local coordinates relative to a given reference frame, and return that polyline expressed in global coordinates.
localFrame =
Frame2d.atPoint (Point2d.fromCoordinates ( 1, 2 ))
Polyline2d.placeIn localFrame stepShape
--> Polyline2d.fromVertices
--> [ Point2d.fromCoordinates ( 1, 2 )
--> , Point2d.fromCoordinates ( 2, 2 )
--> , Point2d.fromCoordinates ( 2, 3 )
--> , Point2d.fromCoordinates ( 3, 3 )
--> ]