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 a transformation to all polygons in the multi-polygon in place.
Overloaded function.
Compute the convex hull of all polygons in the multi-polygon.
Get the number of polygons in the multi-polygon.
Get all polygons contained in the multi-polygon.
Check if this 2D object intersects with another object.
Check if the multi-polygon is defined.
Create a multi-polygon from a single polygon.
Convert the multi-polygon to a string representation.
Create an undefined multi-polygon.
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,
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.
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
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( ) 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:
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( ) int ¶
Get the number of polygons in the multi-polygon.
- Returns:
The number of polygons contained in the multi-polygon.
- Return type:
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( ) 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:
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( ) 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:
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:
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( ) 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:
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,
- format: ostk.mathematics.geometry.d2.Object.Format = <Format.Standard: 1>,
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:
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:
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,
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:
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)