ostk.mathematics.geometry.d2.object.MultiPolygon

class MultiPolygon(
self: ostk.mathematics.geometry.d2.object.MultiPolygon,
polygons: list[ostk.mathematics.geometry.d2.object.Polygon],
)

Bases: Object

Create a multi-polygon from an array of polygons.

Parameters:

polygons (list) -- List of Polygon objects to combine into a multi-polygon.

Example

>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> polygon2 = Polygon([Point(2.0, 2.0), Point(3.0, 2.0), Point(3.0, 3.0)])
>>> multi_polygon = MultiPolygon([polygon1, polygon2])

Methods

apply_transformation

Apply a transformation to all polygons in the multi-polygon in place.

contains

Overloaded function.

get_convex_hull

Compute the convex hull of all polygons in the multi-polygon.

get_polygon_count

Get the number of polygons in the multi-polygon.

get_polygons

Get all polygons contained in the multi-polygon.

intersects

Check if this 2D object intersects with another object.

is_defined

Check if the multi-polygon is defined.

polygon

Create a multi-polygon from a single polygon.

to_string

Convert the multi-polygon to a string representation.

undefined

Create an undefined multi-polygon.

union_with

Compute the union of this multi-polygon with another multi-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.MultiPolygon,
transformation: ostk::mathematics::geometry::d2::Transformation,
) None

Apply a transformation to all polygons in the multi-polygon in place.

Parameters:

transformation (Transformation) -- The 2D transformation to apply.

Example

>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> multi_polygon = MultiPolygon([polygon])
>>> transformation = Translation([1.0, 1.0])
>>> multi_polygon.apply_transformation(transformation)
contains(*args, **kwargs)

Overloaded function.

  1. contains(self: ostk.mathematics.geometry.d2.object.MultiPolygon, point: ostk.mathematics.geometry.d2.object.Point) -> bool

    Check if the multi-polygon contains a point.

    Args:

    point (Point): The point to check for containment.

    Returns:

    bool: True if any polygon in the multi-polygon contains the point, False otherwise.

    Example:
    >>> polygon = Polygon([Point(0.0, 0.0), Point(2.0, 0.0), Point(2.0, 2.0)])
    >>> multi_polygon = MultiPolygon([polygon])
    >>> multi_polygon.contains(Point(1.0, 1.0))  # True
    >>> multi_polygon.contains(Point(3.0, 3.0))  # False
    
  2. contains(self: ostk.mathematics.geometry.d2.object.MultiPolygon, point_set: ostk.mathematics.geometry.d2.object.PointSet) -> bool

    Check if the multi-polygon contains all points in a point set.

    Args:

    point_set (PointSet): The point set to check for containment.

    Returns:

    bool: True if the multi-polygon contains all points in the set, False otherwise.

    Example:
    >>> polygon = Polygon([Point(0.0, 0.0), Point(3.0, 0.0), Point(3.0, 3.0)])
    >>> multi_polygon = MultiPolygon([polygon])
    >>> points = PointSet([Point(1.0, 1.0), Point(2.0, 2.0)])
    >>> multi_polygon.contains(points)  # True
    
get_convex_hull(
self: ostk.mathematics.geometry.d2.object.MultiPolygon,
) ostk.mathematics.geometry.d2.object.Polygon

Compute the convex hull of all polygons in the multi-polygon.

Returns:

A polygon representing the convex hull of all vertices.

Return type:

Polygon

Example

>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> polygon2 = Polygon([Point(2.0, 2.0), Point(3.0, 2.0), Point(3.0, 3.0)])
>>> multi_polygon = MultiPolygon([polygon1, polygon2])
>>> convex_hull = multi_polygon.get_convex_hull()
get_polygon_count(
self: ostk.mathematics.geometry.d2.object.MultiPolygon,
) int

Get the number of polygons in the multi-polygon.

Returns:

The number of polygons contained in the multi-polygon.

Return type:

int

Example

>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> polygon2 = Polygon([Point(2.0, 2.0), Point(3.0, 2.0), Point(3.0, 3.0)])
>>> multi_polygon = MultiPolygon([polygon1, polygon2])
>>> multi_polygon.get_polygon_count()  # 2
get_polygons(
self: ostk.mathematics.geometry.d2.object.MultiPolygon,
) list[ostk.mathematics.geometry.d2.object.Polygon]

Get all polygons contained in the multi-polygon.

Returns:

List of Polygon objects contained in the multi-polygon.

Return type:

list

Example

>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> polygon2 = Polygon([Point(2.0, 2.0), Point(3.0, 2.0), Point(3.0, 3.0)])
>>> multi_polygon = MultiPolygon([polygon1, polygon2])
>>> polygons = multi_polygon.get_polygons()
>>> len(polygons)  # 2
intersects(
self: ostk.mathematics.geometry.d2.Object,
object: ostk.mathematics.geometry.d2.Object,
) bool

Check if this 2D object intersects with another object.

Parameters:

object (Object) -- The object to check intersection with.

Returns:

True if objects intersect, False otherwise.

Return type:

bool

Example

>>> line1 = Line(Point(0.0, 0.0), numpy.array([1.0, 0.0]))
>>> line2 = Line(Point(0.0, -1.0), numpy.array([0.0, 1.0]))
>>> line1.intersects(line2)  # True
is_defined(self: ostk.mathematics.geometry.d2.object.MultiPolygon) bool

Check if the multi-polygon is defined.

Returns:

True if the multi-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)])
>>> multi_polygon = MultiPolygon([polygon])
>>> multi_polygon.is_defined()  # True
static polygon(
polygon: ostk.mathematics.geometry.d2.object.Polygon,
) ostk.mathematics.geometry.d2.object.MultiPolygon

Create a multi-polygon from a single polygon.

Parameters:

polygon (Polygon) -- The polygon to wrap in a multi-polygon.

Returns:

A multi-polygon containing the single polygon.

Return type:

MultiPolygon

Example

>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> multi_polygon = MultiPolygon.polygon(polygon)
>>> multi_polygon.get_polygon_count()  # 1
to_string(
self: ostk.mathematics.geometry.d2.object.MultiPolygon,
format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
precision: ostk.core.type.Integer = Undefined,
) ostk.core.type.String

Convert the multi-polygon to a string representation.

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 multi-polygon.

Return type:

str

Example

>>> polygon = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> multi_polygon = MultiPolygon([polygon])
>>> multi_polygon.to_string()
static undefined() ostk.mathematics.geometry.d2.object.MultiPolygon

Create an undefined multi-polygon.

Returns:

An undefined multi-polygon object.

Return type:

MultiPolygon

Example

>>> undefined_multi_polygon = MultiPolygon.undefined()
>>> undefined_multi_polygon.is_defined()  # False
union_with(
self: ostk.mathematics.geometry.d2.object.MultiPolygon,
multipolygon: ostk.mathematics.geometry.d2.object.MultiPolygon,
) ostk.mathematics.geometry.d2.object.MultiPolygon

Compute the union of this multi-polygon with another multi-polygon.

Parameters:

multipolygon (MultiPolygon) -- The multi-polygon to union with.

Returns:

A new multi-polygon representing the union.

Return type:

MultiPolygon

Example

>>> polygon1 = Polygon([Point(0.0, 0.0), Point(1.0, 0.0), Point(1.0, 1.0)])
>>> polygon2 = Polygon([Point(0.5, 0.5), Point(1.5, 0.5), Point(1.5, 1.5)])
>>> multi1 = MultiPolygon([polygon1])
>>> multi2 = MultiPolygon([polygon2])
>>> union_result = multi1.union_with(multi2)