shapes.polyline#

shapes.polyline(points, div=None, closed=False, elsize=None)#

Create a polyline.

A polyline is a connected sequence of straight line segments defined by a list of vertices.

Parameters#

points: coords_like

An (npts,3) shaped array with the coordinates of the subsequent vertices of the polyline, or any other data accepted by the Coords initialization.

divint or list of int, optional

Subdivision specification along the segments:

  • If int: all segments are equally subdivided into div parts.

  • If list of int: specifies the number of subdivisions for each segment between consecutive points. The length of the list must match the number of segments.

elsizefloat or list of float, optional

Target element size specification (mutually exclusive with div):

  • If float: uniform element size along all segments.

  • If list of float: one value per segment, specifying a constant element size for each segment. Length must match number of segments.

closedbool, optional

If True, the polyline is closed by connecting the last vertex back to the first. The closed polyline then has npts segments. Default is False, leaving the curve open with npts - 1 segments.

Returns#

Mesh

A line mesh (eltype="line2") representing the polyline.

Examples#

>>> pts = [[0.0, 0.0, 0.0], [3.0, 0.0, 0.0], [7.0, 4.0, 0.0]]
>>> M1 = polyline(pts, div=[1, 2, 3], closed=True)
>>> print(M1)
Mesh: n_nodes: 6, n_elems: 6, plexitude: 2, level: 1, eltype: line2
  BBox: [0. 0. 0.], [7. 4. 0.]
  Size: [7. 4. 0.]
  Length: 16.72
>>> M2 = polyline(pts, div=2, closed=False)
>>> print(M2)
Mesh: n_nodes: 5, n_elems: 4, plexitude: 2, level: 1, eltype: line2
  BBox: [0. 0. 0.], [7. 4. 0.]
  Size: [7. 4. 0.]
  Length: 8.657

Using per-segment element sizes:

>>> M3 = polyline(pts, elsize=[1.5, 2.0], closed=False)
>>> print(M3.lengths())
[1.5    1.5    1.8856 1.8856 1.8856]