The GJK algorithm is a collision detection and distance calculation method for convex shapes. It operates by iteratively constructing a simplex (a point, line segment, triangle, or tetrahedron) within the Minkowski difference of the two shapes. The algorithm's core insight is that the origin is contained within this Minkowski difference if and only if the shapes intersect. For non-intersecting shapes, the algorithm converges to the point on the Minkowski difference closest to the origin, yielding the separation distance and direction.
Glossary
GJK Algorithm (Gilbert-Johnson-Keerthi)

What is GJK Algorithm (Gilbert-Johnson-Keerthi)?
The GJK algorithm is a fast, iterative method for computing the distance between two convex shapes and detecting collision by examining the Minkowski difference between them.
GJK is exceptionally efficient due to its support function mechanism, which queries the farthest point in a given direction for each shape. This iterative search avoids explicit computation of the full Minkowski difference. In physics engines for robotics simulation, GJK is the standard narrow-phase algorithm, often paired with the EPA algorithm to calculate penetration depth when a collision is detected. Its speed and numerical stability make it foundational for real-time rigid body dynamics.
Key Features of the GJK Algorithm
The Gilbert-Johnson-Keerthi (GJK) algorithm is a cornerstone of real-time physics simulation, providing a fast, iterative method for collision detection and distance calculation between convex shapes. Its efficiency stems from several core computational features.
Minkowski Difference as the Core Abstraction
The GJK algorithm does not operate directly on the two shapes. Instead, it transforms the problem by computing the Minkowski difference between them. For shapes A and B, this is defined as A ⊖ B = {a - b | a ∈ A, b ∈ B}. The critical insight is that the two original shapes intersect if and only if the Minkowski difference contains the origin. Furthermore, the distance between the shapes is the distance from the origin to this new set. This abstraction reduces collision and distance queries to a single problem: finding the closest point on a convex set to the origin.
The Support Function for Convex Shapes
GJK never explicitly constructs the full Minkowski difference, which would be computationally prohibitive. Instead, it queries the shape via a support function. For a given direction vector d, the support function for a convex shape returns the point on that shape's boundary that is farthest in the direction of d. For the Minkowski difference, the support point is easily computed as: s_A⊖B(d) = s_A(d) - s_B(-d), where s_A and s_B are the support functions for the individual shapes. This allows GJK to sample the Minkowski difference on-demand using only the geometry of the original objects.
Iterative Simplex Construction and Refinement
GJK is an iterative method that builds a sequence of increasingly accurate approximations, called simplices, inside the Minkowski difference. A simplex is the convex hull of a small set of points (e.g., a point, line segment, triangle, or tetrahedron).
- Initialization: The algorithm starts with an arbitrary direction and adds a support point to form the initial simplex.
- Iteration: Each iteration uses the current simplex to find the closest point on it to the origin. The direction from this closest point toward the origin is used to query a new support point.
- Termination: If the new support point is not farther in this direction than the current closest point, the algorithm has converged. If the simplex contains the origin, a collision is detected.
Johnson's Distance Subalgorithm
A critical sub-step within each GJK iteration is finding the point on the current simplex closest to the origin. This is efficiently solved using Johnson's distance algorithm. It works by representing the closest point as a convex combination of the simplex vertices and using a series of geometric tests (e.g., Voronoi region checks) to determine which sub-simplex (a face, edge, or vertex) contains the closest point. This subalgorithm is what enables GJK to quickly refine its search direction each iteration without solving a general quadratic program.
Fast Convergence and Termination Criteria
GJK is prized for its rapid convergence, typically requiring only a few iterations (often 2-10) for standard convex shapes. This speed is due to:
- Geometric progression: Each iteration moves the simplex closer to the origin.
- Robust termination: The algorithm terminates with a collision if the simplex contains the origin. It terminates with a minimum distance when a new support point fails to advance the simplex closer to the origin than the current closest point, within a numerical tolerance.
- Caching: Support points and directions can be cached between frames for objects with small relative motion, a technique known as warm starting, which drastically reduces iteration count.
Pairing with EPA for Penetration Depth
While GJK excels at detecting collision and finding distance, it only provides a yes/no answer and a separation vector for non-colliding objects. When shapes are interpenetrating, the Expanding Polytope Algorithm (EPA) is used as a post-processor. EPA takes the final simplex from GJK that contains the origin and expands it outward by iteratively adding support points until it reconstructs the full Minkowski difference near the origin. This allows EPA to calculate the penetration depth—the minimum translation vector required to separate the objects—and the corresponding contact normal. The GJK-EPA pipeline is standard in physics engines for generating full contact manifolds.
How the GJK Algorithm Works
The Gilbert-Johnson-Keerthi (GJK) algorithm is a fast, iterative method for computing the distance between two convex shapes and detecting collisions by examining the Minkowski difference between them.
The algorithm operates by iteratively constructing a simplex—a triangle in 2D or a tetrahedron in 3D—within the Minkowski difference of the two shapes. This difference represents the set of all vectors from one shape to the other. The core insight is that if this Minkowski difference contains the origin, the original shapes are intersecting. GJK uses support functions to find the farthest point in a given direction for each shape, which are subtracted to build the simplex efficiently.
The algorithm's power lies in its use of Johnson's distance subalgorithm to determine if the origin is inside the current simplex and to iteratively refine it. If the origin is outside, the simplex is updated towards the origin using a new support point, and the process repeats. For non-intersecting shapes, GJK converges to a separation vector representing the minimum translation distance. For penetration, it is often paired with the Expanding Polytope Algorithm (EPA) to compute penetration depth.
GJK vs. Other Collision Detection Methods
A feature comparison of the GJK algorithm against other common narrow-phase collision detection techniques used in physics simulation and robotics.
| Feature / Metric | GJK Algorithm | Separating Axis Theorem (SAT) | Bounding Volume Intersection | Voxel/Pixel-Based |
|---|---|---|---|---|
Primary Purpose | Distance calculation & collision detection for convex shapes | Collision detection & contact manifold generation for convex polytopes | Fast overlap test for simple volumes (AABB, Sphere, OBB) | Collision detection for arbitrary, non-convex, or deformable shapes |
Shape Support | Convex shapes only | Convex polytopes only | Any shape (via bounding volume approximation) | Any shape (discretized) |
Output Data | Minimum distance & closest points; penetration via EPA | Boolean collision, separation vector, contact manifold (faces/edges) | Boolean overlap result | Boolean collision; approximate contact surface |
Performance Complexity (Typical) | O(n) iterative, sub-linear convergence | O(n²) in worst case for polytopes | O(1) for pairwise tests | O(n³) for volume resolution, memory intensive |
Penetration Depth Resolution | Requires separate EPA algorithm | Built-in via MTV (Minimum Translation Vector) | None | Approximate, resolution-dependent |
Continuous Collision Detection (CCD) Support | Yes (via raycast on Minkowski difference) | Limited, computationally expensive | No (discrete only) | Yes (via swept volume testing) |
Memory Overhead | Low (stores simplex of 4 points max) | Moderate (stores face/edge projections) | Very Low (stores volume parameters only) | Very High (stores full 3D grid) |
Implementation Complexity | High (requires careful numerical robustness) | Moderate to High (handling edge/face cases) | Very Low | Low (conceptually), but high for optimization |
Best Used For | General convex shapes in motion, distance queries | Static convex polyhedra, need full contact data | Broad-phase culling, simple shapes, hierarchical tests | Complex non-convex shapes, medical imaging, voxel worlds |
Common Applications and Examples
The Gilbert-Johnson-Keerthi (GJK) algorithm is a cornerstone of real-time physics simulation, prized for its speed and iterative nature. Its primary function is to compute the distance between two convex shapes and detect collisions by examining their Minkowski difference.
Robotic Motion Planning & Manipulation
In robotics, GJK is critical for collision avoidance and path planning. It enables:
- Configuration Space (C-Space) checking: Determining if a robot's proposed pose intersects with obstacles.
- Grasp planning: Verifying that a robotic gripper's geometry does not collide with non-target objects during manipulation.
- Safe trajectory validation: Ensuring every incremental motion between waypoints is collision-free. Its efficiency allows for real-time re-planning in dynamic environments.
Proximity Queries for Convex Hulls
Beyond simple collision yes/no detection, GJK's core output is the minimum distance between two convex sets. This is essential for:
- Separation distance monitoring in safety systems.
- Computing the penetration vector when used with the Expanding Polytope Algorithm (EPA).
- Support function optimization: The algorithm iteratively calls a support function for each shape, which finds the farthest point in a given direction. This makes it highly efficient for complex convex shapes represented by their hulls.
The Minkowski Difference & Simplex
GJK operates on a powerful geometric concept: the Minkowski difference between shapes A and B (A ⊖ B).
- Key Insight: The distance between A and B is the distance from the origin to this Minkowski difference. If the origin is inside A ⊖ B, the shapes intersect.
- Simplex Evolution: The algorithm constructs a simplex (a point, line segment, triangle, or tetrahedron) inside A ⊖ B that iteratively moves closer to the origin.
- Termination: It converges when the simplex contains the origin (collision) or when the distance to the origin is minimized (closest points found).
Comparison to Other Methods
GJK excels where other methods falter:
- Vs. SAT (Separating Axis Theorem): GJK is generally faster for complex convex polyhedra, as SAT performance depends on the number of face/edge axes to test.
- Vs. Spatial Partitioning Alone: While grids or trees excel at broad-phase culling, GJK provides the exact narrow-phase result for convex pairs.
- Limitation: It is designed for convex shapes. For concave objects, they must first be decomposed into convex parts (convex decomposition), and GJK is run on each part pair.
Integration with Constraint Solvers
A collision detection algorithm like GJK is only the first step in a physics pipeline. Its outputs feed the constraint solver:
- Output Data: For colliding pairs, GJK (with EPA) provides the penetration depth and contact normal.
- Solver Input: This data formulates non-penetration constraints and, with Coulomb friction models, friction constraints.
- Resolution: The solver (e.g., solving an LCP) computes the impulses or forces to resolve the collision, applying Newton-Euler equations to update body velocities and positions.
Frequently Asked Questions
The Gilbert-Johnson-Keerthi (GJK) algorithm is a cornerstone of real-time physics simulation, providing a fast, iterative method for collision detection and distance calculation between convex shapes. These questions address its core mechanics, applications, and relationship to other critical algorithms in robotics and simulation.
The GJK algorithm is an iterative method for computing the minimum distance between two convex sets and detecting collision by examining the Minkowski difference between them. It works by constructing a simplex (a point, line segment, triangle, or tetrahedron) within the Minkowski difference and iteratively refining this simplex towards the origin. If the origin is contained within the Minkowski difference, the shapes are colliding; otherwise, the algorithm returns the minimum distance and the closest points. Its efficiency stems from using support functions, which return the farthest point in a given direction for a shape, allowing it to operate without pre-computing or storing the full Minkowski difference geometry.
Key Steps:
- Initialize: Start with an arbitrary search direction.
- Support Mapping: Calculate the support point for each shape in the current direction and its opposite.
- Minkowski Difference: Subtract the support points to get a vertex of the Minkowski difference.
- Simplex Update: Add the new vertex to the current simplex (a subset of points).
- Check for Origin: Determine if the simplex contains the origin (collision) or find the new closest simplex to the origin.
- New Direction: Calculate a new search direction from the simplex towards the origin.
- Iterate: Repeat from step 2 until the distance converges or the origin is included.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
The GJK algorithm operates within a broader ecosystem of computational geometry and physics simulation concepts. These related terms define the mathematical and algorithmic context for efficient collision and distance queries.
Minkowski Difference
The Minkowski difference between two convex sets A and B, denoted A ⊖ B, is the foundational geometric operation used by the GJK algorithm. It is defined as the set of all vector differences between points in A and points in B. The key property is that the distance between A and B is the distance from the origin to this Minkowski difference set. If the sets intersect, the origin is contained within A ⊖ B. GJK efficiently samples this set without computing it explicitly.
- Core Property: Distance(A, B) = Distance(origin, A ⊖ B).
- Collision Test: Intersection occurs if origin ∈ (A ⊖ B).
- Algorithmic Role: GJK iteratively builds a simplex (a triangle in 2D, a tetrahedron in 3D) inside A ⊖ B to test for origin containment.
EPA Algorithm
The Expanding Polytope Algorithm (EPA) is the natural companion to GJK for calculating penetration depth. When GJK detects a collision (origin inside the Minkowski difference), EPA takes over. It starts with the final simplex from GJK that contains the origin and iteratively expands it into a full convex polytope around the origin. By finding the closest face of this polytope to the origin, EPA calculates the minimum translation vector (MTV)—the direction and magnitude needed to separate the two intersecting shapes.
- Primary Function: Computes penetration depth and contact manifold.
- Input: The simplex from GJK where a collision was detected.
- Output: A contact normal and penetration depth for collision response.
Support Function
A support function (or support mapping) is the critical subroutine used by GJK. For a convex shape and a given direction vector d, the support function returns the point on the shape that is farthest in that direction. Mathematically, S_A(d) = argmax_{v ∈ A} (v · d). GJK's efficiency stems from using this function to sample the Minkowski difference: S_{A⊖B}(d) = S_A(d) - S_B(-d). The algorithm only requires this mapping, not the full geometry.
- Key Feature: Enables GJK to work on any convex shape with a defined support mapping.
- Performance: The cost of GJK is largely the cost of evaluating the support function.
- Examples: For a sphere, it's center + radius * normalize(d). For a convex hull, it's a linear search over vertices.
Simplex
In the context of GJK, a simplex is the simplest convex shape that can be formed in a given dimension: a point (0-simplex), line segment (1-simplex), triangle (2-simplex), or tetrahedron (3-simplex). GJK is an iterative algorithm that builds and updates a simplex within the Minkowski difference. Each iteration, it uses the support function to add a new point and then reduces the simplex to the smallest sub-simplex that still contains the closest point to the origin. This process converges quickly to the origin for collision or to the closest point for distance.
- Evolution: Starts as a single point, grows, and is reduced each step.
- Termination: The algorithm terminates when the simplex contains the origin (collision) or when the new support point does not move closer to the origin (distance found).
Gilbert-Johnson-Keerthi Distance Algorithm
This is the full name of the GJK algorithm, specifically highlighting its primary function as a distance algorithm. While famously used for collision detection (a boolean yes/no test), its core mathematical output is the minimum distance between two convex sets. The collision check is a special case where that distance is zero. The algorithm's elegance lies in its iterative use of support functions and simplex reduction to converge on the closest points of the Minkowski difference to the origin, from which the inter-shape distance is directly derived.
- Original Purpose: Computing Euclidean distance between convex sets.
- Output: Can return the closest points on each shape in addition to the distance.
- Foundation: More general than a simple collision test; collision is a distance query where result ≤ 0.
Convex Hull
A convex hull of a set of points is the smallest convex set that contains all the points. The GJK algorithm requires its input shapes to be convex. Many complex collision shapes in physics engines are represented as convex hulls of their vertices. The support function for a convex hull is computed by iterating over its vertices to find the one with the maximum dot product with the search direction. This is a common and efficient representation for polyhedral objects in simulations.
- Prerequisite for GJK: Input geometry must be convex; convex hulls are a standard way to ensure this.
- Support Calculation: Involves a linear scan or, for performance, a precomputed hill-climbing data structure.
- Use Case: Representing arbitrary rigid bodies for collision detection.

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.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us