Skip to content

Gilbert–Johnson–Keerthi Algorithm¤

compas_model.geometry.gjk2 ¤

Functions:¤

is_collision_poly_poly_xy ¤

is_collision_poly_poly_xy(A: Polygon, B: Polygon) -> bool

Determine whether two convex polygons collide in the XY plane using the GJK algorithm.

Parameters:

  • A (Polygon) –

    The first polygon.

  • B (Polygon) –

    The second polygon.

Returns:

  • bool –

    True if the polygons collide. False otherwise.

Raises:

  • RuntimeError –

    If the GJK algorithm doesn't converge after 100 iterations.

Warnings

Only works for convex polygons in the XY plane.

Examples:

>>> from compas.geometry import Polygon
>>> from compas_model.geometry import is_collision_poly_poly_xy

Construct two polygons in the XY plane.

>>> A = Polygon.from_rectangle([0, 0, 0], 2, 1)
>>> B = Polygon.from_rectangle([1.5, 0.5, 0], 1, 1)

Check if the polygons collide.

>>> is_collision_poly_poly_xy(A, B)
True

support_poly ¤

support_poly(
    points: Polygon | Sequence[Point | Vector], direction: Vector
) -> Point | Vector

Find the point in a list of points that is farthest away from the origin in a given direction.

Parameters:

Returns:

  • Point –

    The farthest point in the support direction.

support_poly_poly ¤

support_poly_poly(
    A: Polygon | Sequence[Point | Vector],
    B: Polygon | Sequence[Point | Vector],
    direction: Vector,
) -> Vector

Compute a support point on the Minkowski sum of A and -B in the given direction.

Parameters:

Returns:

  • Vector –

    The support point.

triplecross ¤

triplecross(u: Vector, v: Point | Vector) -> Vector

Compute the vector perpendicular to u in the plane uxv and in the same directio as v.

Parameters:

Returns:

  • Vector –

    The perpendicular vector.