ostk.mathematics.geometry.d2.object.Polygon¶
- class Polygon(*args, **kwargs)¶
Bases:
ObjectOverloaded function.
__init__(self: ostk.mathematics.geometry.d2.object.Polygon, outer_ring: list[ostk.mathematics.geometry.d2.object.Point], inner_rings: list[list[ostk.mathematics.geometry.d2.object.Point]]) -> None
Create a polygon with outer ring and inner rings (holes).
- Args:
outer_ring (list[Point]): List of points defining the outer boundary. inner_rings (list[list[Point]]): List of lists of points defining holes.
- Example:
>>> outer = [Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)] >>> inner = [[Point(0.2, 0.2), Point(0.8, 0.2), Point(0.8, 0.8), Point(0.2, 0.8)]] >>> polygon = Polygon(outer, inner)
__init__(self: ostk.mathematics.geometry.d2.object.Polygon, outer_ring: list[ostk.mathematics.geometry.d2.object.Point]) -> None
Create a simple polygon with just an outer ring.
- Args:
outer_ring (list[Point]): List of points defining the polygon boundary.
- Example:
>>> points = [Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)] >>> polygon = Polygon(points)
Methods
Apply a transformation to the polygon in place.
Overloaded function.
Get the difference of the polygon with another polygon.
Get the convex hull of the polygon.
Get the edge at the given index.
Get the number of edges in the polygon.
Get all edges of the polygon.
Get the inner ring at the given index.
Get the number of inner rings in the polygon.
Get the outer ring of the polygon.
Get the vertex at the given index.
Get the total number of vertices in the polygon.
Get all vertices of the polygon.
Get the intersection of the polygon with another polygon.
Check if the polygon intersects another polygon.
Check if the polygon is defined.
Check if this polygon is near another polygon within tolerance.
Get the string representation of the polygon.
Create an undefined polygon.
Get the union of the polygon with another polygon.
- class Format(self: ostk.mathematics.geometry.d2.Object.Format, value: int)¶
Bases:
pybind11_objectMembers:
Undefined
Standard
WKT
- property name¶
- apply_transformation(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- transformation: ostk::mathematics::geometry::d2::Transformation,
Apply a transformation to the polygon in place.
- Parameters:
transformation (Transformation) -- The transformation to apply.
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> transformation = Translation([1.0, 1.0]) >>> polygon.apply_transformation(transformation)
- contains(*args, **kwargs)¶
Overloaded function.
contains(self: ostk.mathematics.geometry.d2.object.Polygon, point: ostk.mathematics.geometry.d2.object.Point) -> bool
Check if the polygon contains a point.
- Args:
point (Point): The point to check.
- Returns:
bool: True if the polygon contains the point, False otherwise.
- Example:
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.contains(Point(0.5, 0.5)) # True
contains(self: ostk.mathematics.geometry.d2.object.Polygon, point_set: ostk.mathematics.geometry.d2.object.PointSet) -> bool
Check if the polygon contains a point set.
- Args:
point_set (PointSet): The point set to check.
- Returns:
bool: True if the polygon contains the point set, False otherwise.
- Example:
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> point_set = PointSet([Point(0.5, 0.5), Point(1.5, 0.5), Point(1.5, 1.5)]) >>> polygon.contains(point_set) # True
- difference_with(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- polygon: ostk.mathematics.geometry.d2.object.Polygon,
Get the difference of the polygon with another polygon.
- Parameters:
polygon (Polygon) -- The polygon to check difference with.
- Returns:
The difference of the polygon with another polygon.
- Return type:
Example
>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)]) >>> polygon2 = Polygon([Point(0.01, 0.01), Point(1.01, 0.01), Point(1.01, 1.01)]) >>> polygon1.difference_with(polygon2) # Intersection
- get_convex_hull( ) ostk.mathematics.geometry.d2.object.Polygon¶
Get the convex hull of the polygon.
- Returns:
The convex hull of the polygon.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_convex_hull()
- get_edge_at(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- index: int,
Get the edge at the given index.
- Parameters:
index (int) -- The index of the edge.
- Returns:
The edge at the given index.
- Return type:
Polygon.Edge
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_edge_at(0)
- get_edge_count(self: ostk.mathematics.geometry.d2.object.Polygon) int¶
Get the number of edges in the polygon.
- Returns:
The number of edges.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_edge_count() # 4
- get_edges( ) list[ostk.mathematics.geometry.d2.object.Segment]¶
Get all edges of the polygon.
- Returns:
List of all edges in the polygon.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_edges()
- get_inner_ring_at(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- arg0: int,
Get the inner ring at the given index.
- Parameters:
index (int) -- The index of the inner ring.
- Returns:
The inner ring at the given index.
- Return type:
Polygon.Ring
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_inner_ring_at(0)
- get_inner_ring_count(self: ostk.mathematics.geometry.d2.object.Polygon) int¶
Get the number of inner rings in the polygon.
- Returns:
The number of inner rings.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_inner_ring_count() # 0
- get_outer_ring( ) ostk.mathematics.geometry.d2.object.LineString¶
Get the outer ring of the polygon.
- Returns:
The outer ring of the polygon.
- Return type:
Polygon.Ring
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_outer_ring()
- get_vertex_at(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- index: int,
Get the vertex at the given index.
- Parameters:
index (int) -- The index of the vertex.
- Returns:
The vertex at the given index.
- Return type:
Polygon.Vertex
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_vertex_at(0)
- get_vertex_count(self: ostk.mathematics.geometry.d2.object.Polygon) int¶
Get the total number of vertices in the polygon.
- Returns:
The number of vertices.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.get_vertex_count() # 4
- get_vertices( ) list[ostk.mathematics.geometry.d2.object.Point]¶
Get all vertices of the polygon.
- Returns:
List of all vertices in the polygon.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)]) >>> vertices = polygon.get_vertices()
- intersection_with(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- polygon: ostk.mathematics.geometry.d2.object.Polygon,
Get the intersection of the polygon with another polygon.
- Parameters:
polygon (Polygon) -- The polygon to check intersection with.
- Returns:
The intersection of the polygon with another polygon.
- Return type:
Example
>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)]) >>> polygon2 = Polygon([Point(0.01, 0.01), Point(1.01, 0.01), Point(1.01, 1.01)]) >>> polygon1.intersection_with(polygon2) # Intersection
- intersects(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- polygon: ostk.mathematics.geometry.d2.object.Polygon,
Check if the polygon intersects another polygon.
- Parameters:
polygon (Polygon) -- The polygon to check intersection with.
- Returns:
True if the polygons intersect, False otherwise.
- Return type:
Example
>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)]) >>> polygon2 = Polygon([Point(0.01, 0.01), Point(1.01, 0.01), Point(1.01, 1.01)]) >>> polygon1.intersects(polygon2) # True
- is_defined(self: ostk.mathematics.geometry.d2.object.Polygon) bool¶
Check if the polygon is defined.
- Returns:
True if the polygon is defined, False otherwise.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)]) >>> polygon.is_defined() # True
- is_near(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- polygon: ostk.mathematics.geometry.d2.object.Polygon,
- tolerance: ostk.core.type.Real,
- polygon: ostk.mathematics.geometry.d2.object.Polygon,
Check if this polygon is near another polygon within tolerance.
- Parameters:
- Returns:
True if polygons are within tolerance, False otherwise.
- Return type:
Example
>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)]) >>> polygon2 = Polygon([Point(0.01, 0.01), Point(1.01, 0.01), Point(1.01, 1.01)]) >>> polygon1.is_near(polygon2, 0.1) # True
- to_string(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
- precision: ostk.core.type.Integer = Undefined,
- format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
Get the string representation of the polygon.
- Parameters:
format (Object.Format, optional) -- The output format. Defaults to Standard.
precision (int, optional) -- The precision for floating point numbers. Defaults to undefined.
- Returns:
String representation of the polygon.
- Return type:
Example
>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon.to_string()
- static undefined() ostk.mathematics.geometry.d2.object.Polygon¶
Create an undefined polygon.
- Returns:
An undefined polygon.
- Return type:
Example
>>> undefined_polygon = Polygon.undefined() >>> undefined_polygon.is_defined() # False
- union_with(
- self: ostk.mathematics.geometry.d2.object.Polygon,
- polygon: ostk.mathematics.geometry.d2.object.Polygon,
Get the union of the polygon with another polygon.
- Parameters:
polygon (Polygon) -- The polygon to union with.
- Returns:
The union of the polygon with another polygon.
- Return type:
Example
>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0), Point(0.0, 1.0)]) >>> polygon2 = Polygon([Point(0.01, 0.01), Point(1.01, 0.01), Point(1.01, 1.01), Point(0.01, 1.01)]) >>> polygon1.union_with(polygon2)