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 )
]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 ) )
]Get the overall length of a polyline (the sum of the lengths of its segments).
Polyline2d.length stepShape ==
3Transforming a polyline is equivalent to transforming each of its vertices.
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 )
]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 )
]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 )
]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 )
]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 )
]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) stepShapeTake 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 )
]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 )
]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 )
]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
}
)
Get the vertices of a polyline.