ianmackenzie / elm-geometry / Polyline2d

A Polyline2d represents a sequence of vertices in 2D connected by line segments. This module contains a variety of polyline-related functionality, such as


type alias Polyline2d units coordinates =
Geometry.Types.Polyline2d units coordinates

Constructors

fromVertices : List (Point2d units coordinates) -> Polyline2d units coordinates

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
        ]

Properties

vertices : Polyline2d units coordinates -> List (Point2d units coordinates)

Get the vertices of a polyline.

segments : Polyline2d units coordinates -> List (LineSegment2d units coordinates)

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)
--> ]

length : Polyline2d units coordinates -> Quantity Basics.Float units

Get the overall length of a polyline (the sum of the lengths of its segments).

Polyline2d.length stepShape
--> Length.meters 3

boundingBox : Polyline2d units coordinates -> Maybe (BoundingBox2d units coordinates)

Get the minimal bounding box containing a given polyline. Returns Nothing if the polyline has no vertices.

Polyline2d.boundingBox stepShape
--> Just <|
-->     BoundingBox2d.from
-->         (Point2d.meters 0 0)
-->         (Point2d.meters 2 1)

centroid : Polyline2d units coordinates -> Maybe (Point2d units coordinates)

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)

Transformations

These transformations generally behave just like the ones in the Point2d module.

scaleAbout : Point2d units coordinates -> Basics.Float -> Polyline2d units coordinates -> Polyline2d units coordinates

Scale a polyline about a given center point by a given scale.

rotateAround : Point2d units coordinates -> Angle -> Polyline2d units coordinates -> Polyline2d units coordinates

Rotate a polyline around the given center point counterclockwise by the given angle.

translateBy : Vector2d units coordinates -> Polyline2d units coordinates -> Polyline2d units coordinates

Translate a polyline by the given displacement.

translateIn : Direction2d coordinates -> Quantity Basics.Float units -> Polyline2d units coordinates -> Polyline2d units coordinates

Translate a polyline in a given direction by a given distance.

mirrorAcross : Axis2d units coordinates -> Polyline2d units coordinates -> Polyline2d units coordinates

Mirror a polyline across the given axis.

projectOnto : Axis2d units coordinates -> Polyline2d units coordinates -> Polyline2d units coordinates

Project (flatten) a polyline onto the given axis.

mapVertices : (Point2d units1 coordinates1 -> Point2d units2 coordinates2) -> Polyline2d units1 coordinates1 -> Polyline2d units2 coordinates2

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)

Unit conversions

at : Quantity Basics.Float (Quantity.Rate units2 units1) -> Polyline2d units1 coordinates -> Polyline2d units2 coordinates

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.

at_ : Quantity Basics.Float (Quantity.Rate units1 units2) -> Polyline2d units1 coordinates -> Polyline2d units2 coordinates

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.

Coordinate conversions

relativeTo : Frame2d units globalCoordinates { defines : localCoordinates } -> Polyline2d units globalCoordinates -> Polyline2d units localCoordinates

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

placeIn : Frame2d units globalCoordinates { defines : localCoordinates } -> Polyline2d units localCoordinates -> Polyline2d units globalCoordinates

Take a polyline considered to be defined in local coordinates relative to a given reference frame, and return that polyline expressed in global coordinates.