ostk.mathematics.geometry.d2.object.Polygon

class Polygon(*args, **kwargs)

Bases: Object

Overloaded function.

  1. __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)
    
  2. __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_transformation

Apply a transformation to the polygon in place.

contains

Overloaded function.

difference_with

Get the difference of the polygon with another polygon.

get_convex_hull

Get the convex hull of the polygon.

get_edge_at

Get the edge at the given index.

get_edge_count

Get the number of edges in the polygon.

get_edges

Get all edges of the polygon.

get_inner_ring_at

Get the inner ring at the given index.

get_inner_ring_count

Get the number of inner rings in the polygon.

get_outer_ring

Get the outer ring of the polygon.

get_vertex_at

Get the vertex at the given index.

get_vertex_count

Get the total number of vertices in the polygon.

get_vertices

Get all vertices of the polygon.

intersection_with

Get the intersection of the polygon with another polygon.

intersects

Check if the polygon intersects another polygon.

is_defined

Check if the polygon is defined.

is_near

Check if this polygon is near another polygon within tolerance.

to_string

Get the string representation of the polygon.

undefined

Create an undefined polygon.

union_with

Get the union of the polygon with another polygon.

class Format(self: ostk.mathematics.geometry.d2.Object.Format, value: int)

Bases: pybind11_object

Members:

Undefined

Standard

WKT

property name
apply_transformation(
self: ostk.mathematics.geometry.d2.object.Polygon,
transformation: ostk::mathematics::geometry::d2::Transformation,
) None

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.

  1. 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
    
  2. 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,
) ostk::mathematics::geometry::d2::Intersection

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:

Intersection

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(
self: ostk.mathematics.geometry.d2.object.Polygon,
) ostk.mathematics.geometry.d2.object.Polygon

Get the convex hull of the polygon.

Returns:

The convex hull of the polygon.

Return type:

Polygon

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,
) ostk.mathematics.geometry.d2.object.Segment

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:

int

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(
self: ostk.mathematics.geometry.d2.object.Polygon,
) list[ostk.mathematics.geometry.d2.object.Segment]

Get all edges of the polygon.

Returns:

List of all edges in the polygon.

Return type:

list

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,
) ostk.mathematics.geometry.d2.object.LineString

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:

int

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(
self: ostk.mathematics.geometry.d2.object.Polygon,
) 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,
) ostk.mathematics.geometry.d2.object.Point

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:

int

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(
self: ostk.mathematics.geometry.d2.object.Polygon,
) list[ostk.mathematics.geometry.d2.object.Point]

Get all vertices of the polygon.

Returns:

List of all vertices in the polygon.

Return type:

list

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,
) ostk::mathematics::geometry::d2::Intersection

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:

Intersection

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,
) bool

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:

bool

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:

bool

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,
) bool

Check if this polygon is near another polygon within tolerance.

Parameters:
  • polygon (Polygon) -- The polygon to compare with.

  • tolerance (float) -- The tolerance for comparison.

Returns:

True if polygons are within tolerance, False otherwise.

Return type:

bool

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,
) ostk.core.type.String

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:

str

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:

Polygon

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,
) ostk::mathematics::geometry::d2::object::MultiPolygon

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:

Polygon

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)