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] | compas.geometry.Point]) – An ordered list of points.

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

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

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

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

  • normal (compas.geometry.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

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.

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.