The Gilbert–Johnson–Keerthi (GJK) algorithm is an iterative method for computing the minimum distance between two convex shapes and determining if they intersect. It operates by constructing a Minkowski difference of the shapes and iteratively refining a simplex (a point, line segment, or triangle) within this difference to find the point closest to the origin, which corresponds to the separation distance. Its efficiency stems from its support function, which queries the farthest point of a shape in a given direction.
Glossary
Gilbert–Johnson–Keerthi (GJK) Algorithm

What is the Gilbert–Johnson–Keerthi (GJK) Algorithm?
A core algorithm for efficient collision detection and distance computation in physics engines.
GJK is foundational to modern physics engines and rigid body dynamics simulations because it provides a fast, robust, and dimensionally general solution for collision detection. It is often paired with the Expanding Polytope Algorithm (EPA) to calculate penetration depth and contact manifolds when shapes overlap. This makes GJK critical for simulating precise physical interactions in robotics training, video games, and digital twin environments.
Key Features of the GJK Algorithm
The Gilbert–Johnson–Keerthi (GJK) algorithm is an iterative method for computing the distance between two convex shapes and detecting collisions. Its efficiency stems from several core computational features.
Support Function Abstraction
The GJK algorithm operates on shapes not through their explicit geometry, but via a support function. This function, given a direction vector d, returns the point on the shape that is farthest in that direction. This abstraction allows GJK to work with any convex shape (polyhedra, spheres, cones) as long as a support function is defined, making it highly versatile for complex collision geometries in physics engines.
Minkowski Difference & Origin Inclusion
GJK reduces the problem of finding the distance between two convex sets, A and B, to finding the distance between the origin and their Minkowski difference (A - B). A collision occurs if and only if the origin is inside this Minkowski difference set. The algorithm iteratively builds a simplex (a triangle in 3D, a line in 2D) inside this set, trying to enclose the origin.
Iterative Simplex Evolution
The algorithm maintains a simplex—the simplest convex hull of a set of points from the Minkowski difference. Starting with a single point, it iteratively:
- Uses the support function to find a new point in a direction toward the origin.
- Updates the simplex to be the smallest subset that best approximates the origin's vicinity.
- Terminates when the simplex contains the origin (collision) or when the distance to the origin cannot be further reduced (minimum separation found).
Johnson's Distance Subalgorithm
A critical subroutine determines the point on the current simplex closest to the origin and identifies which subset of the simplex's vertices is relevant. For a 3D simplex (a tetrahedron), this involves checking which faces, edges, or vertices are closest to the origin. This efficiently reduces the simplex's dimensionality at each step, guiding the next support function query.
Termination & Convergence
GJK terminates under two conditions:
- Collision Detected: The origin is found to be inside the current simplex.
- Minimum Distance Found: The algorithm converges when the new point found by the support function does not move closer to the origin than the closest point on the current simplex. The distance to this closest point is the separation distance. The algorithm typically converges in a very small number of iterations, often <10, even for complex shapes.
Expanding Polytope Algorithm (EPA) for Penetration Depth
When GJK detects a collision (origin inside the Minkowski difference), the Expanding Polytope Algorithm (EPA) is often used as a post-processing step. While GJK finds that shapes intersect, EPA expands the final simplex from GJK into a full polytope surrounding the origin to calculate the penetration depth and the associated contact normal, which are necessary for collision response in physics engines.
GJK vs. Other Collision Detection Methods
A technical comparison of the Gilbert–Johnson–Keerthi (GJK) algorithm against other common collision detection and distance calculation methods used in physics simulation engines.
| Feature / Metric | Gilbert–Johnson–Keerthi (GJK) | Separating Axis Theorem (SAT) | Bounding Volume Hierarchy (BVH) Traversal | Voxel / Grid-Based |
|---|---|---|---|---|
Primary Function | Distance calculation & collision detection for convex shapes | Collision detection for convex polygons/polyhedra | Broadphase culling & hierarchical collision queries | Spatial partitioning for many simple shapes |
Shape Support | Convex shapes only (via support function) | Convex polygons & polyhedra | Any shape (via bounding volume) | Primitive shapes (spheres, boxes, voxels) |
Output Data | Minimum distance & closest points | Boolean collision & separation vector | List of potentially colliding pairs | List of objects per spatial cell |
Algorithmic Complexity | O(n) iterative, converges quickly | O(n²) in axes to test | O(n log n) for construction, O(log n) for query | O(1) insertion, O(k) query for k neighbors |
Continuous Collision Detection (CCD) Support | ||||
Requires Explicit Geometry | ||||
Best For | Robotic motion planning, precise distance queries | Real-time game physics, simple convex shapes | Large scenes with static/kinematic objects | Particle systems, uniform density environments |
Memory Overhead | Low (stores simplex state) | Medium (stores all face/edge data) | High (tree structure storage) | Medium (grid data structure) |
Frequently Asked Questions
The Gilbert–Johnson–Keerthi (GJK) algorithm is a cornerstone of modern collision detection in physics simulation engines. These questions address its core mechanics, applications, and relationship to other simulation technologies.
The Gilbert–Johnson–Keerthi (GJK) algorithm is an iterative method for computing the minimum distance between two convex shapes and detecting whether they intersect (collide). It works by leveraging the concept of the Minkowski difference. The algorithm constructs a simplex (a point, line segment, or triangle in 3D) within this difference space and iteratively refines it toward the origin. If the origin is contained within the Minkowski difference, the shapes are intersecting. Its power lies in its linear convergence and its reliance solely on a support function—a subroutine that returns the farthest point on a shape in a given direction—making it applicable to any convex geometry.
Key Steps in the GJK Loop:
- Initialization: Choose an arbitrary search direction.
- Support Mapping: Calculate a support point for each shape in the current direction and its opposite, then compute their difference (a point in Minkowski space).
- Simplex Update: Add the new support point to a working simplex (up to 4 points in 3D).
- Origin Check: Determine if the simplex contains the origin. If yes, collision detected.
- Direction Update: If the origin is not contained, compute a new search direction toward the origin from the current simplex and discard any simplex points that don't help the search.
- Iteration: Repeat steps 2-5 until the origin is found (collision) or the distance to the origin stops decreasing (minimum separation found).
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. These related concepts define the environment in which GJK is deployed and the problems it helps solve.
Minkowski Difference
The Minkowski Difference is the foundational geometric operation upon which the GJK algorithm is built. For two convex sets A and B, it is defined as A - B = {a - b | a ∈ A, b ∈ B}. The key insight is that the distance between A and B is the distance from the origin to this Minkowski Difference set. Furthermore, collision occurs if and only if the origin is contained within the Minkowski Difference. GJK efficiently iterates towards this origin by examining vertices of the Minkowski Difference without explicitly constructing the entire set.
Support Function
A Support Function (or support mapping) is a core subroutine used by GJK. For a convex shape and a given direction vector d, the support function returns the point on the shape's boundary that is farthest in that direction (i.e., has the maximum dot product with d).
- For a polygon: the vertex with the highest dot product.
- For a sphere: center + (radius * normalized(d)).
- For a convex hull: a linear-time search over vertices. GJK uses this function on the Minkowski Difference by calculating support_A(d) - support_B(-d), allowing it to sample the combined shape efficiently.
Simplex
A Simplex is the simplest geometric object of a given dimension in space (e.g., 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. It starts with a single point and iteratively adds a new support point in a direction toward the origin. The algorithm then reduces this simplex to the smallest sub-simplex (closest to the origin) and chooses a new search direction. This process continues until the simplex contains the origin (collision) or the distance cannot be improved (minimum distance found).
Expanding Polytope Algorithm (EPA)
The Expanding Polytope Algorithm (EPA) is a companion algorithm often used after GJK detects a collision. While GJK efficiently determines if a collision occurred and provides a separation vector when objects are apart, EPA is used to compute the penetration depth and contact manifold (multiple contact points) when objects are intersecting.
- Process: EPA takes the final simplex from GJK that contains the origin and expands it into a full convex polytope around the origin by iteratively adding support points.
- Output: It returns the closest point on the polytope's boundary to the origin, which corresponds to the minimum translation vector (MTV) needed to separate the shapes.
Separating Axis Theorem (SAT)
The Separating Axis Theorem (SAT) is an alternative collision detection algorithm primarily for convex polygons/polyhedra. It states that two convex shapes are disjoint if and only if there exists an axis onto which their projections do not overlap. SAT tests a set of candidate axes derived from face normals and edge cross products.
- Comparison with GJK: SAT is often very efficient for low-vertex-count polygons but can become complex for curved shapes like ellipsoids. GJK is more general, handling any convex shape with a support function, and is often preferred in 3D for its consistent performance and ease of implementation for complex primitives.
Bounding Volume Hierarchy (BVH)
A Bounding Volume Hierarchy (BVH) is a critical acceleration structure used in large-scale physics simulations and rendering. It is not a replacement for GJK but works in tandem with it.
- Function: A BVH organizes all objects in the scene into a tree, where each node has a simple bounding volume (e.g., an Axis-Aligned Bounding Box - AABB) that contains all its children.
- Pipeline Integration: In the broadphase collision detection stage, the BVH is traversed to quickly cull pairs of objects whose bounding volumes do not overlap. Only the potentially colliding pairs are passed to the narrowphase, where precise algorithms like GJK are executed. This drastically reduces the number of expensive GJK calls.

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