Polygon
-
class
compas.geometry.
Polygon
(points)[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)from_data
(data)Construct a polygon from its data representation.
from_sides_and_radius_xy
(n, radius)Construct a polygon from a number of sides and a radius.
Determine if the polygon is convex.
Determine if the polygon is planar.
transform
(T)Transform this polygon.
Inherited Methods
copy
()Makes a copy of this primitive.
from_json
(filepath)Construct a primitive from structured data contained in a json file.
to_data
()Returns the data dictionary that represents the primitive.
to_json
(filepath)Serialise the structured data representing the primitive to json.
transformed
(transformation)Returns a transformed copy of this primitive.
Validate the data of this object against its data schema (self.DATASCHEMA).
Validate the data loaded from a JSON representation of the data of this object against its data schema (self.DATASCHEMA).