Polygon

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

Bases: Primitive

A polygon is defined by a sequence of points forming a closed loop.

Parameters

points (list[[float, float, float] | Point]) – An ordered list of points.

Attributes
  • points (list of Point) – The points of the polygon.

  • lines (list of Line, read-only) – The lines of the polygon.

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

  • centroid (Point, read-only) – The centroid of the polygon.

  • normal (Vector, read-only) – The (average) normal of the polygon.

  • area (float, read-only) – The area of the polygon.

Notes

A polygon is defined by a sequence of points connected by line segments forming a closed boundary that separates its interior from the exterior.

In the sequence of points, the first and last element are not the same. The existence of the closing edge is implied. The boundary should not intersect itself.

Polygons are not necessarily planar by construction; they can be warped.

Examples

>>> polygon = Polygon([[0, 0, 0], [1, 0, 0], [1, 1, 0], [0, 1, 0]])
>>> polygon.centroid
Point(0.500, 0.500, 0.000)
>>> polygon.area
1.0

Methods

contains

from_data

Construct a polygon from its data representation.

from_sides_and_radius_xy

Construct a polygon from a number of sides and a radius.

is_convex

Determine if the polygon is convex.

is_planar

Determine if the polygon is planar.

transform

Transform this polygon.

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.