Polyline

class compas.geometry.Polyline(points, **kwargs)[source]

Bases: Primitive

A polyline is defined by a sequence of points connected by line segments.

Parameters

points (list[[float, float, float] | Point]) – An ordered list of points. Each consecutive pair of points forms a segment of the polyline.

Attributes
  • points (list[Point]) – The points of the polyline.

  • lines (list[Line], read-only) – The lines of the polyline.

  • length (float, read-only) – The length of the polyline.

Notes

A polyline is a piecewise linear element. It does not have an interior. It can be open or closed. It can be self-intersecting.

Examples

>>> polyline = Polyline([[0,0,0], [1,0,0], [2,0,0], [3,0,0]])
>>> polyline.length
3.0
>>> type(polyline.points[0]) == Point
True
>>> polyline.points[0].x
0.0
>>> type(polyline.lines[0]) == Line
True
>>> polyline.lines[0].length
1.0

Methods

divide

Divide a polyline in equal segments.

divide_by_length

Splits a polyline in segments of a given length.

divide_polyline

Divide a polyline in equal segments.

divide_polyline_by_length

Splits a polyline in segments of a given length.

extend

Extends a polyline by a given length, by modifying the first and/or last point tangentially.

extended

Returns a copy of this polyline extended by a given length.

from_data

Construct a polyline from a data dict.

is_closed

Determine if the polyline is closed.

is_selfintersecting

Determine if the polyline is self-intersecting.

point

Point on the polyline at a specific normalized parameter.

shorten

Shortens a polyline by a given length.

shortened

Returns a copy of this polyline shortened by a given length.

split_at_corners

Splits a polyline at corners larger than the given angle_threshold

tangent_at

Calculates the tangent vector of a point on a polyline

tangent_at_point_on_polyline

Calculates the tangent vector of a point on a polyline

transform

Transform this polyline.

Inherited Methods

ToString

Converts the instance to a string.

copy

Make an independent copy of the data object.

from_json

Construct an object from serialized data contained in a JSON file.

from_jsonstring

Construct an object from serialized data contained in a JSON string.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_data

Convert an object to its native data representation.

to_json

Serialize the data representation of an object to a JSON file.

to_jsonstring

Serialize the data representation of an object to a JSON string.

transformed

Returns a transformed copy of this geometry.

validate_data

Validate the object's data against its data schema.

validate_json

Validate the object's data against its json schema.