Inferensys

Glossary

Gilbert-Johnson-Keerthi (GJK) Algorithm

An iterative algorithm that efficiently computes the minimum distance between two convex shapes, serving as the foundational narrow-phase collision detection routine in robotics.
MLOps engineer reviewing model serving infrastructure on laptop, container orchestration visible, technical workspace.
NARROW-PHASE COLLISION DETECTION

What is Gilbert-Johnson-Keerthi (GJK) Algorithm?

The Gilbert-Johnson-Keerthi algorithm is a foundational computational geometry method for efficiently determining the minimum distance and intersection status between two convex sets.

The Gilbert-Johnson-Keerthi (GJK) algorithm is an iterative method that computes the Euclidean distance between two convex shapes by operating on their Minkowski difference. It relies on the geometric property that two convex sets intersect if and only if their Minkowski difference contains the origin. GJK efficiently searches for the point in this difference set closest to the origin using support mapping functions, which return the most extreme point of a shape in a given direction, avoiding the need to explicitly construct the complex Minkowski difference volume.

In industrial robotics path planning, GJK serves as the primary narrow-phase collision detection routine, executed millions of times per second to verify that robotic manipulators and automated guided vehicles (AGVs) do not penetrate obstacles. Its computational efficiency makes it ideal for real-time trajectory optimization and model predictive control (MPC) loops. The algorithm is often paired with broad-phase culling methods like bounding volume hierarchies and is a core component of physics engines and motion planning libraries such as Bullet and Open Motion Planning Library (OMPL).

NARROW-PHASE COLLISION DETECTION

Key Characteristics of the GJK Algorithm

The Gilbert-Johnson-Keerthi algorithm is the workhorse of modern physics engines and robotic path planning. It efficiently determines the minimum distance and separation vector between any two convex shapes by iteratively refining a simplex in Minkowski configuration space.

01

Minkowski Difference Core

The algorithm's mathematical foundation is the Minkowski difference (B - A). GJK does not operate on the original shapes directly. Instead, it searches for the point in this difference set closest to the origin. If the origin lies inside the Minkowski difference, the original shapes intersect. This elegant transformation reduces the complex problem of checking two arbitrary convex sets to the simpler problem of checking if a single convex set contains the origin.

02

Iterative Simplex Refinement

GJK is an iterative algorithm that builds and refines a simplex—a generalized triangle (point, line, triangle, or tetrahedron) in 2D or 3D—inside the Minkowski difference. Each iteration uses a support function to map a search direction to the furthest point in the Minkowski difference. The algorithm then uses this new vertex to evolve the simplex closer to the origin, terminating when the simplex either contains the origin (collision) or proves the origin is unreachable (separation).

03

Support Function Mapping

The support function S(d) is the only geometry-specific operation GJK requires, making it extremely general. For a convex shape, S(d) returns the vertex furthest in a given direction d. For compound shapes, the support function of the Minkowski difference is simply S_A(d) - S_B(-d). This abstraction allows GJK to handle any convex primitive—spheres, boxes, capsules, convex hulls—without modification, as long as a support function is defined.

04

Distance Sub-Algorithm (Johnson)

When shapes are separated, GJK transitions to the Johnson distance sub-algorithm to compute the exact minimum distance. Once the main loop determines the origin is outside the Minkowski difference, it identifies the closest feature (vertex, edge, or face) of the current simplex to the origin. This yields not only the separation distance but also the witness points on each original shape, which are critical for computing collision normals and penetration depth in physics simulations.

05

Expanding Polytope Algorithm (EPA) Companion

GJK alone only provides a boolean intersection test and separation distance. To compute penetration depth—how far two objects are interpenetrating—the Expanding Polytope Algorithm (EPA) is invoked after GJK detects a collision. EPA starts with the simplex that contains the origin and iteratively expands it by adding support points until it approximates the Minkowski difference surface, returning the minimum translation vector required to separate the objects.

06

Numerical Robustness Challenges

In floating-point implementations, GJK is notoriously sensitive to numerical precision. Degenerate cases like nearly co-planar faces or very thin simplexes can cause the algorithm to cycle or return incorrect results. Production-grade implementations employ safeguards:

  • Tolerance thresholds for zero-distance checks
  • Backup exact arithmetic for critical steps
  • Simplex degeneration detection to reset the search
  • Maximum iteration limits to prevent infinite loops
GJK ALGORITHM DEEP DIVE

Frequently Asked Questions

Clear, technically precise answers to the most common questions about the Gilbert-Johnson-Keerthi algorithm, the foundational narrow-phase collision detection routine in modern robotics and physics simulation.

The Gilbert-Johnson-Keerthi (GJK) algorithm is an iterative method that efficiently computes the minimum Euclidean distance between two convex sets. It works by operating on the Minkowski difference of the two shapes—a single convex set that contains the origin if and only if the original shapes intersect. GJK iteratively builds a simplex (a point, line segment, triangle, or tetrahedron) inside the Minkowski difference, using support mapping functions to sample the boundary in promising directions. At each iteration, the algorithm checks whether the current simplex contains the origin; if it does, the shapes intersect. If not, GJK refines the simplex to get closer to the origin, converging to the exact minimum distance within a small number of iterations. This geometric approach avoids the computational expense of explicitly computing the Minkowski difference or performing exhaustive vertex-vertex checks, making it the dominant narrow-phase collision detection routine in robotics, video games, and physics engines like Bullet and Box2D.

Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.