The GJK (Gilbert–Johnson–Keerthi) algorithm is a general-purpose collision-detection algorithm that can determine whether any two convex shapes overlap — without needing to know anything specific about their geometry. Prowl.Vector implements it in theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/ProwlEngine/Prowl.Vector/llms.txt
Use this file to discover all available pages before exploring further.
GJK static class (Prowl.Vector.Geometry namespace). Any pair of types that implement IBoundingShape can be tested with a single call.
How It Works
GJK operates on the Minkowski difference of the two shapes: the set of all pointsA − B where A is any point in shape A and B is any point in shape B. The two shapes overlap if and only if the origin is inside this Minkowski difference.
Rather than computing the full Minkowski difference (which can be extremely complex), GJK iteratively builds a simplex — a point, line, triangle, or tetrahedron — made of support points sampled from the Minkowski difference. At each step it checks whether the current simplex contains the origin. If a support point fails to reach past the origin in the current search direction, the origin cannot be inside the Minkowski difference and no collision exists.
Prowl.Vector’s implementation runs for a maximum of 64 iterations and uses an epsilon of 1e-10f for degenerate-case detection in the simplex handlers.
The IBoundingShape Interface
SupportMap(Float3 direction) is the only method GJK calls. It must return the point on the shape that is farthest in the given direction. The direction does not need to be normalized.
For example, the AABB’s support map simply picks the corner that maximizes the dot product with the direction:
API
GJK.Intersects
true if the two shapes overlap (share at least one point). The method is allocation-free; the internal Simplex structure is a fixed-size value type stored on the stack.
Usage Examples
AABB vs Sphere
AABB vs Cone
Frustum vs Triangle
Implementing a Custom Shape
Any struct or class that implementsIBoundingShape can participate in GJK tests immediately. The only requirement is a correct SupportMap implementation.
Supported Built-in Shapes
The following types inProwl.Vector implement IBoundingShape and can be passed directly to GJK.Intersects:
| Type | Notes |
|---|---|
AABB | Support map picks the maximizing corner per axis. |
Sphere | Support map is Center + normalize(direction) * Radius. |
Cone | Support map chooses between the apex and the base-circle edge. |
Frustum | Support map iterates the 8 corners and returns the best. |
Triangle | Support map returns the vertex with the highest dot product. |
LineSegment | Support map returns the endpoint with the higher dot product. |
Plane and Ray are not convex bodies in the GJK sense and do not implement IBoundingShape. Use the dedicated methods in the Intersection class for plane and ray tests.