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

Attributes

DATASCHEMA

The schema of the data of this object.

JSONSCHEMANAME

area

The area of the polygon.

centroid

The centroid of the polygon.

data

The data dictionary that represents the polygon.

length

The length of the boundary.

lines

The lines of the polygon.

normal

The (average) normal of the polygon.

points

The points of the polygon.

Inherited Attributes

JSONSCHEMA

The schema of the JSON representation of the data of this object.

dtype

The type of the object in the form of a '2-level' import and a class name.

guid

The globally unique identifier of the object.

jsondefinitions

Reusable schema definitions.

jsonstring

The representation of the object data in JSON format.

jsonvalidator

JSON schema validator for draft 7.

name

The name of the object.

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 (self.DATASCHEMA).

validate_json

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