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.meters 0 0
, Point2d.meters 1 0
, Point2d.meters 1 1
, Point2d.meters 2 1
]Get the vertices of a polyline.
Polyline2d.vertices stepShape
--> [ Point2d.meters 0 0
--> , Point2d.meters 1 0
--> , Point2d.meters 1 1
--> , Point2d.meters 2 1
--> ]Get the individual segments of a polyline.
Polyline2d.segments stepShape
--> [ LineSegment2d.from
--> (Point2d.meters 0 0)
--> (Point2d.meters 1 0)
--> , LineSegment2d.from
--> (Point2d.meters 1 0)
--> (Point2d.meters 1 1)
--> , LineSegment2d.from
--> (Point2d.meters 1 1)
--> (Point2d.meters 2 1)
--> ]Get the overall length of a polyline (the sum of the lengths of its segments).
Polyline2d.length stepShape
--> Length.meters 3Get the minimal bounding box containing a given polyline. Returns Nothing
if the polyline has no vertices.
Polyline2d.boundingBox stepShape
--> Just <|
--> BoundingBox2d.fromExtrema
--> { minX = Length.meters 0
--> , maxX = Length.meters 2
--> , minY = Length.meters 0
--> , maxY = Length.meters 1
--> }Find the centroid (center of mass) of a polyline. This is the
length-weighted average of the edges of the polyline, not the centroid of its
vertices. Returns Nothing if the polyline is empty (has no vertices).
Polyline2d.centroid stepShape
--> Just (Point2d.meters 1.0 0.5)Convert a polyline from one units type to another, by providing a conversion factor given as a rate of change of destination units with respect to source units.
Convert a polyline from one units type to another, by providing an 'inverse' conversion factor given as a rate of change of source units with respect to destination units.
These transformations generally behave just like the ones in the Point2d
module.
Scale a polyline about a given center point by a given scale.
Rotate a polyline around the given center point counterclockwise by the given angle.
Translate a polyline by the given displacement.
Translate a polyline in a given direction by a given distance.
Mirror a polyline across the given axis.
Project (flatten) a polyline onto the given axis.
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.
Take a polyline considered to be defined in local coordinates relative to a given reference frame, and return that polyline expressed in global coordinates.