opensolid/geometry/1.0.2

NOTE: this package is not compatible with Elm 0.19.1

OpenSolid.Polyline2d

Polyline2d

Various functions for creating and working with Polyline2d values. Polylines can be constructed by passing an ordered list of vertices to the Polyline2d constructor, for example

stepShape =
    Polyline2d
        [ Point2d ( 0, 0 )
        , Point2d ( 1, 0 )
        , Point2d ( 1, 1 )
        , Point2d ( 2, 1 )
        ]

Accessors

vertices : Polyline2d -> List Point2d

Get the vertices of a polyline.

Polyline2d.vertices stepShape ==
    [ Point2d ( 0, 0 )
    , Point2d ( 1, 0 )
    , Point2d ( 1, 1 )
    , Point2d ( 2, 1 )
    ]
segments : Polyline2d -> List LineSegment2d

Get the individual segments of a polyline.

Polyline2d.segments stepShape ==
    [ LineSegment2d ( Point2d ( 0, 0 ), Point2d ( 1, 0 ) )
    , LineSegment2d ( Point2d ( 1, 0 ), Point2d ( 1, 1 ) )
    , LineSegment2d ( Point2d ( 1, 1 ), Point2d ( 2, 1 ) )
    ]

Length

length : Polyline2d -> Float

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

Polyline2d.length stepShape ==
    3

Transformations

Transforming a polyline is equivalent to transforming each of its vertices.

scaleAbout : Point2d -> Float -> Polyline2d -> Polyline2d

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

point =
    Point2d ( 1, 0 )


Polyline2d.scaleAbout point 2 stepShape ==
    Polyline2d
        [ Point2d ( -1, 0 )
        , Point2d ( 1, 0 )
        , Point2d ( 1, 2 )
        , Point2d ( 3, 2 )
        ]
rotateAround : Point2d -> Float -> Polyline2d -> Polyline2d

Rotate a polyline around the given center point counterclockwise by the given angle (in radians).

Polyline2d.rotateAround Point2d.origin (degrees 90) stepShape ==
    Polyline2d
        [ Point2d ( 0, 0 )
        , Point2d ( 0, 1 )
        , Point2d ( -1, 1 )
        , Point2d ( -1, 2 )
        ]
translateBy : Vector2d -> Polyline2d -> Polyline2d

Translate a polyline by the given displacement.

displacement =
    Vector2d ( 2, 3 )


Polyline2d.translateBy displacement stepShape ==
    Polyline2d
        [ Point2d ( 2, 3 )
        , Point2d ( 3, 3 )
        , Point2d ( 3, 4 )
        , Point2d ( 4, 4 )
        ]
mirrorAcross : Axis2d -> Polyline2d -> Polyline2d

Mirror a polyline across the given axis.

Polyline2d.mirrorAcross Axis2d.x stepShape ==
    Polyline2d
        [ Point2d ( 0, 0 )
        , Point2d ( 1, 0 )
        , Point2d ( 1, -1 )
        , Point2d ( 2, -1 )
        ]
projectOnto : Axis2d -> Polyline2d -> Polyline2d

Project (flatten) a polyline onto the given axis.

Polyline2d.projectOnto Axis2d.x stepShape ==
    Polyline2d
        [ Point2d ( 0, 0 )
        , Point2d ( 1, 0 )
        , Point2d ( 1, 0 )
        , Point2d ( 2, 0 )
        ]
map : (Point2d -> Point2d) -> Polyline2d -> Polyline2d

Transform each vertex of a polyline by the given function. All other transformations can be defined in terms of map, for example

Polyline2d.mirrorAcross Axis2d.x stepShape ==
    Polyline2d.map (Point2d.mirrorAcross Axis2d.x) stepShape

Coordinate frames

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.at (Point2d ( 1, 2 ))


Polyline2d.relativeTo localFrame stepShape ==
    Polyline2d
        [ Point2d ( -1, -2 )
        , Point2d ( 0, -2 )
        , Point2d ( 0, -1 )
        , Point2d ( 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.at (Point2d ( 1, 2 ))


Polyline2d.placeIn localFrame stepShape ==
    Polyline2d
        [ Point2d ( 1, 2 )
        , Point2d ( 2, 2 )
        , Point2d ( 2, 3 )
        , Point2d ( 3, 3 )
        ]

Sketch planes

placeOnto : SketchPlane3d -> Polyline2d -> Polyline3d

Take a polyline defined in 2D coordinates within a particular sketch plane and return the corresponding polyline in 3D.

Polyline2d.placeOnto SketchPlane3d.yz stepShape ==
    Polyline3d
        [ Point3d ( 0, 0, 0 )
        , Point3d ( 0, 1, 0 )
        , Point3d ( 0, 1, 1 )
        , Point3d ( 0, 2, 1 )
        ]

Bounds

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
            { minX = 0
            , maxX = 2
            , minY = 0
            , maxY = 1
            }
        )