Skip to content

Minkowski Operations in 2D¤

compas_model.geometry.minkowski2 ¤

Functions:¤

bottomleft ¤

bottomleft(points: list[Point]) -> int

Identify the point with the smalles y coordinate, and the smallest x coordinate.

Parameters:

Returns:

  • int –

    The index of the point.

det ¤

det(u: Vector, v: Vector) -> float

Compute the determinant of the 2x2 matrix formed by the XY components of the vectors u and v.

Parameters:

  • u (Vector) –

    The first vector.

  • v (Vector) –

    The second vector.

Returns:

  • float –

    The determinant.

minkowski_difference_xy ¤

minkowski_difference_xy(A: Polygon, B: Polygon) -> Polygon

Compute the Minkowski difference of convex polygons A and B in the XY plane.

Parameters:

  • A (Polygon) –

    The first polygon.

  • B (Polygon) –

    The second polygon.

Returns:

  • Polygon –

    The polygon representing the difference as the sum of A and -B.

Warnings

Currently only convex polygons are supported.

See Also
Notes

The Minkwoski "difference" of two polygons A and B, can be formulated as the Minkowski sum of A and inverted B: A + (-B). 1

A useful application of the Minkowski difference of two convex polygons A and B is collision detection. If the origin (0, 0) is contained in the difference polygon A + (-B), then a collision between A and B exists.


  1. https://en.wikipedia.org/wiki/Minkowski_addition ↩

Examples:

>>> from compas.geometry import Polygon
>>> from compas.geometry import is_point_in_convex_polygon_xy
>>> from compas_model.geometry import minkowski_difference_xy
>>> A = Polygon.from_rectangle([1, 0, 0], 1, 1)
>>> B = Polygon.from_sides_and_radius_xy(5, 1).translated([2.5, 1, 0])
>>> C = minkowski_difference_xy(A, B)
>>> is_point_in_convex_polygon_xy([0, 0, 0], C)
True

minkowski_sum_xy ¤

minkowski_sum_xy(A: Polygon, B: Polygon) -> Polygon

Compute the Minkowski sum of two polygons.

Parameters:

  • A (Polygon) –

    The first polygon.

  • B (Polygon) –

    The second polygon.

Returns:

  • Polygon –

    The polygon representing the sum.

Warnings

Currently only convex polygons are supported.

See Also

reorder_bottomleft ¤

reorder_bottomleft(points: list[Point]) -> list[Point]

Reorder the points to start with the one on the bottom left.

Parameters:

Returns:

sort_ccw ¤

sort_ccw(points: list[Point]) -> list[Point]

Sort the points in CCW direction using the polar angle wrt their centroid.

Parameters:

Returns: