A general (closed) Polygon class.
The Polygon is made out of points (vertices of type Point) and edges (Segment). It can be created by passing a list of Point-like objects.
Parameters : | vertices : {list/tuple of point-like} |
---|---|
Raises : | ValueError :
|
Attributes
area | [scalar] Get the (positive) area of this Polygon. |
bbox_height | [scalar] Get self.bounding_box.height. |
bbox_width | [scalar] Get self.bounding_box.width. |
bounding_box | [BoundingBox] Get BoundingBox of self. |
centroid | [Point] Get the centroid (Point) of the Polygon. |
diameter | [scalar] Get the diameter of the Polygon. |
edges | [list of segments] Get the edges, that is the segments. |
vertices | [list of points] Get the vertices. |
width | [scalar] Get the width of the Polygon. |
Methods
__contains__(x) | Searches for x in “itself”. |
__getitem__(idx) | Retreive points (self.vertices) by idx. |
__len__() | The length of the Polygon is defined by the length of the |
_compute_diameter_width() | Compute the diameter and width of the Polygon. |
divide([obj, edge_no, frac, relative_phi, ...]) | Divide the Polygon. |
get_point_on_self([edge_no, frac]) | Return a random Point on the given Segment |
has(point) | Determine if point is inside Polygon based on the winding |
intersection(obj) | Return points of intersection if any. |
rotate(theta[, point, angle]) | Rotate self around pivot point. |
translate(dx, dy) | Translate self by given amounts on x and y. |
Detailed description
A general (closed) Polygon class.
The Polygon is made out of points (vertices of type Point) and edges (Segment). It can be created by passing a list of Point-like objects.
Parameters : | vertices : {list/tuple of point-like} |
---|---|
Raises : | ValueError :
|
Searches for x in “itself”. If we’re talking about a Point or a Vector then this searches within their components (x, y). For everything else it searches within the list of points (vertices).
Parameters : | x : {point, scalar}
|
---|---|
Returns : | out : {True, False}
|
Retreive points (self.vertices) by idx.
Parameters : | idx : scalar
|
---|---|
Returns : | ret : point
|
Compute the diameter and width of the Polygon.
This is meant for internal use only. The diameter is defined by the length of the rectangle of minimum area enclosing the Polygon, and the width of the Polygon is then just the width of the same rectangle of minimum area enclosing the Polygon. It’s calculation is based on [Arnon1983].
[scalar] Get the (positive) area of this Polygon.
Using the standard formula [WPolygon] for the area of a Polygon:
\(A\) can be negative depending on the orientation of the Polygon but this property always returns the positive value.
Notes
This function (property) also sets up self._area if it’s not set. This variable (self._area) is meant to be just for internal use (at least for now).
[BoundingBox] Get BoundingBox of self.
[Point] Get the centroid (Point) of the Polygon.
Defined as [WPolygon]:
where \(A\) is the area using the standard formula for a Polygon [WPolygon] so it can take negative values.
[scalar] Get the diameter of the Polygon.
Refer to _compute_diameter_width for details on how this is calculated.
Divide the Polygon.
Parameters : | obj : line-like, optional
edge_no : int, optional
frac : float, optional
relative_phi : float, optional
drelative_phi : float, optional
|
---|---|
Returns : | ret : tuple of size 2
|
[list of segments] Get the edges, that is the segments.
These are the edges of the Polygon, which are defined by the list of vertices. The Polygon is considered to be closed (ie. the last segment is defined by points pn and p1).
Return a random Point on the given Segment defined by edge_no.
Parameters : | edge_no : int, optional
frac : float, optional
|
---|---|
Returns : | out : point |
Determine if point is inside Polygon based on the winding number.
Parameters : | point : point-like
|
---|---|
Returns : | out : {True, False}
|
Notes
Winding number algorithm (C++ implementation): http://geomalgorithms.com/a03-_inclusion.html
Return points of intersection if any.
This method just calls the intersection method on the other objects that have it implemented.
Parameters : | obj : geometric object
|
---|---|
Returns : | ret : {point, None}
|
Rotate self around pivot point.
Parameters : | theta : scalar
point : {point-like}, optional
angle : {‘degrees’, ‘radians’}, optional
|
---|
Translate self by given amounts on x and y.
Parameters : | dx, dy : scalar
|
---|
[list of points] Get the vertices.
The list of Point-like objects that make up the Polygon. It’s lengths cannot be less than 3.
[scalar] Get the width of the Polygon.
Refer to _compute_diameter_width for details on how this is calculated.
[Arnon1983] | Arnon et al., A Linear Time Algorithm for the Minimum Area Rectangle Enclosing a Convex Polygon” (1983), Computer Science Technical Reports. Paper 382 |
[WPolygon] | (1, 2, 3) http://en.wikipedia.org/wiki/Polygon |