A Polyline2d
represents a sequence of vertices in 2D connected by line
segments. This module contains a variety of polyline-related functionality, such
as
Geometry.Types.Polyline2d
fromVertices : List Point2d -> Polyline2d
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 )
]
vertices : Polyline2d -> List Point2d
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 )
--> ]
segments : Polyline2d -> List LineSegment2d
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 )
--> )
--> ]
length : Polyline2d -> Basics.Float
Get the overall length of a polyline (the sum of the lengths of its segments).
Polyline2d.length stepShape
--> 3
boundingBox : Polyline2d -> Maybe BoundingBox2d
Get 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.
scaleAbout : Point2d -> Basics.Float -> Polyline2d -> Polyline2d
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 )
--> ]
rotateAround : Point2d -> Basics.Float -> Polyline2d -> Polyline2d
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 )
--> ]
translateBy : Vector2d -> Polyline2d -> Polyline2d
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 )
--> ]
translateIn : Direction2d -> Basics.Float -> Polyline2d -> Polyline2d
Translate a polyline in a given direction by a given distance;
Polyline2d.translateIn direction distance
is equivalent to
Polyline2d.translateBy
(Vector2d.withLength distance direction)
mirrorAcross : Axis2d -> Polyline2d -> Polyline2d
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 )
--> ]
projectOnto : Axis2d -> Polyline2d -> Polyline2d
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 )
--> ]
mapVertices : (Point2d -> Point2d) -> Polyline2d -> Polyline2d
Transform each vertex of a polyline by the given function. All other
transformations can be defined in terms of mapVertices
; for example,
Polyline2d.mirrorAcross axis
is equivalent to
Polyline2d.mapVertices (Point2d.mirrorAcross axis)
relativeTo : Frame2d -> Polyline2d -> Polyline2d
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 )
--> ]
placeIn : Frame2d -> Polyline2d -> Polyline2d
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 )
--> ]