Polygon

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

Bases: compas.geometry.primitives._primitive.Primitive

An object representing an ordered collection of points in space connected by straight line segments forming a closed boundary around the interior space.

A polygon has a closed boundary that separates its interior from the exterior. The boundary does not intersect itself, and is described by an ordered set of of points.

Parameters

points (list of point) – An ordered list of points.

Attributes
  • data (dict) – The data representation of the polygon.

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

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

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

  • normal (compas.geometry.Vector, read-only) – The normal vector of the polygon plane.

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

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

Notes

All Polygon objects are considered closed. Therefore the first and last element in the list of points are not the same. The existence of the closing edge is implied.

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(point)

copy([cls])

Make an independent copy of the data object.

from_data(data)

Construct a polygon from its data representation.

from_json(filepath)

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

from_jsonstring(string)

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

from_sides_and_radius_xy(n, radius)

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.

to_data()

Convert an object to its native data representation.

to_json(filepath[, pretty])

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

to_jsonstring([pretty])

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

transform(T)

Transform this polygon.

transformed(transformation)

Returns a transformed copy of this geometry.

validate_data()

Validate the object's data against its data schema (self.DATASCHEMA).

validate_json()

Validate the object's data against its json schema (self.JSONSCHEMA).