Documentation
¶
Overview ¶
Package gjk implements the Gilbert-Johnson-Keerthi (GJK) algorithm for collision detection.
GJK detects whether two convex shapes overlap by testing if their Minkowski difference contains the origin. The algorithm builds a simplex incrementally, converging toward the origin in typically 3-6 iterations.
For detailed algorithm explanation with pseudocode and visual examples, see: ALGORITHMS.md - "GJK Algorithm" section
References:
- Gilbert, Johnson, Keerthi: "A Fast Procedure for Computing the Distance Between Complex Objects in Three-Dimensional Space" (1988)
- Van den Bergen: "Collision Detection in Interactive 3D Environments" (2003)
Index ¶
Constants ¶
This section is empty.
Variables ¶
var SimplexPool = sync.Pool{ New: func() interface{} { return &Simplex{} }, }
Functions ¶
func GJK ¶
GJK performs collision detection between two convex rigid bodies.
Algorithm overview:
- Start with initial search direction (toward B from A)
- Get first support point in Minkowski difference
- Iteratively refine simplex toward origin
- If origin is contained → collision
- If can't reach origin → no collision
Typical convergence: 3-6 iterations for most shapes.
Returns:
- bool: true if collision detected, false otherwise
The simplex is modified in place and contains 1-4 points. For collisions, it's always a tetrahedron (4 points) containing the origin, which EPA uses as its initial polytope.
func MinkowskiSupport ¶
MinkowskiSupport computes a support point in the Minkowski difference (A - B).
The Minkowski difference A - B is the set of all vectors (a - b) where a ∈ A and b ∈ B. For collision detection, we only need the extreme points (support points) in any direction.
Parameters:
- a, b: The two rigid bodies to test
- direction: The direction to find the furthest point
Returns:
Support point: furthestPoint(A, direction) - furthestPoint(B, -direction)
This is the fundamental query that makes GJK work for any convex shape - shapes only need to implement a Support() function, not expose their full geometry.