Gilbert–Johnson–Keerthi distance algorithm
The Gilbert–Johnson–Keerthi distance algorithm is a method of determining the minimum distance between two convex sets, first published by Elmer G. Gilbert, Daniel W. Johnson, and S. Sathiya Keerthi in 1988. Unlike many other distance algorithms, it does not require that the geometry data be stored in any specific format, but instead relies solely on a support function to iteratively generate closer simplices to the correct answer using the configuration space obstacle of two convex shapes, more commonly known as the Minkowski difference.
"Enhanced GJK" algorithms use edge information to speed up the algorithm by following edges when looking for the next simplex. This improves performance substantially for polytopes with large numbers of vertices.
GJK makes use of Johnson's distance sub algorithm, which computes in the general case the point of a tetrahedron closest to the origin, but is known to suffer from numerical robustness problems. In 2017 Montanari, Petrinic, and Barbieri proposed a new sub algorithm based on signed volumes which avoid the multiplication of potentially small quantities and achieved a speedup of 15% to 30%.
GJK algorithms are often used incrementally in simulation systems and video games. In this mode, the final simplex from a previous solution is used as the initial guess in the next iteration, or "frame". If the positions in the new frame are close to those in the old frame, the algorithm will converge in one or two iterations. This yields collision detection systems which operate in near-constant time.
The algorithm's stability, speed, and small storage footprint make it popular for realtime collision detection, especially in physics engines for video games.
Overview
GJK relies on two functions:- , which returns the point on which has the highest dot product with.
- , which takes a simplex and returns the simplex on closest to the origin, and a direction toward the origin normal to the new simplex. If itself contains the origin, accepts and the two shapes are determined to intersect.
Pseudocode
function GJK_intersection:vector A = Support − Support
simplex s =
vector D = −A
loop:
A = Support − Support
if dot < 0:
reject
s = s ∪
s, D, contains_origin := NearestSimplex
if contains_origin:
accept