Polygon

class compas.geometry.Polygon[source]

Bases: Geometry

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

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 or skewed.

The polygon does not have a coordinate frame. Its geometry is always defined with respect to the world coordinate system.

Polygons can be constructed parametrically by the number of sides and a radius, but the geometry of the resulting object is defined by a list of explicit point locations.

Parameters:
pointslist[[float, float, float] | compas.geometry.Point]

An ordered list of points.

namestr, optional

The name of the polygon.

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:
pointslist of compas.geometry.Point

The points of the polygon.

lineslist of compas.geometry.Line, read-only

The lines of the polygon.

lengthfloat, read-only

The length of the boundary.

centroidcompas.geometry.Point, read-only

The centroid of the polygon.

normalcompas.geometry.Vector, read-only

The (average) normal of the polygon.

areafloat, read-only

The area of the polygon.

is_convexbool, read-only

True if the polygon is convex.

is_planarbool, read-only

True if the polygon is planar.

Methods

boolean_difference

Compute the boolean difference of this polygon and another polygon.

boolean_intersection

Compute the boolean intersection of this polygon and another polygon.

boolean_symmetric_difference

Compute the boolean symmetric difference of this polygon and another polygon.

boolean_union

Compute the boolean union of this polygon and another polygon.

from_rectangle

Construct a rectangle.

from_sides_and_radius_xy

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

to_brep

Returns a brep representation of the polygon.

to_mesh

Returns a mesh representation of the polygon.

to_vertices_and_faces

Returns a list of vertices and faces.

transform

Transform this polygon.

Inherited Methods

ToString

Converts the instance to a string.

compute_aabb

Compute the axis-aligned bounding box of the geometry.

compute_obb

Compute the oriented bounding box of the geometry.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

rotate

Rotate the geometry.

rotated

Returns a rotated copy of this geometry.

scale

Scale the geometry.

scaled

Returns a scaled copy of this geometry.

sha256

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

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

transformed

Returns a transformed copy of this geometry.

translate

Translate the geometry.

translated

Returns a translated copy of this geometry.

validate_data

Validate the data against the object's data schema.