Skip to main content
ExplainerPhysics EnginesAlgorithm Explainer· 4 min read· in Gaming & Esports

The GJK and EPA Algorithms: How Minkowski Difference and the Simplex Determine Collision

Modern physics engines rely on the Gilbert-Johnson-Keerthi algorithm to instantly detect overlapping geometry, while the Expanding Polytope Algorithm calculates exactly how to push them apart. Together, they form the mathematical backbone of real-time 3D collision detection.

By Ryder James

Detection Efficiency 50%Physics Resolution 50%
Detection Efficiency
Focuses on GJK's ability to rapidly cull non-colliding objects without generating full geometry.
Physics Resolution
Focuses on EPA's capacity to generate the precise penetration vectors required for physical response.

Perspectives this story doesn't cover

  • Concave Geometry Handlers
  • GPU Compute Shader Advocates
3 to 4
Typical GJK iterations
(0,0,0)
Minkowski space origin
4
Vertices in a 3D simplex
16.6 ms
60 FPS frame time budget

The Separating Axis Theorem (SAT) solves collision by brute force, checking every possible face normal of two objects to find a gap of daylight between them. The Gilbert-Johnson-Keerthi (GJK) algorithm differs in one crucial respect: it completely ignores the faces. Instead of testing dozens of polygons, GJK subtracts one object from the other mathematically to create a single, abstract volume called the Minkowski Difference. If that new volume contains the origin point—the exact center of the universe, coordinate (0,0,0)—the objects are colliding. If it does not, they are not. In the high-stakes environment of a 144-hertz physics simulation, where a game engine has less than seven milliseconds to resolve thousands of overlapping rigid bodies, skipping the polygon-by-polygon check is the difference between a fluid simulation and a frozen frame.[1][3]

The genius of GJK lies in how it navigates this abstract Minkowski space. Generating the entire Minkowski Difference for two complex 3D models would require calculating millions of vertices, instantly bottlenecking the CPU. GJK bypasses this by never actually building the shape. Instead, it uses a "support function"—a mathematical probe that asks, "What is the furthest point in this specific direction?" By firing these probes, GJK builds a "simplex" (a point, line, triangle, or tetrahedron) inside the Minkowski space, actively hunting for the origin.[2][5]

Every time the simplex fails to enclose the origin, GJK discards the useless vertices and fires a new support function toward the origin's location. It is a homing missile for intersection. For typical convex shapes, GJK finds the origin or proves it cannot be reached in just three to four iterations. This drops the algorithmic complexity from a geometric nightmare to a near-constant time operation, allowing modern physics engines to test thousands of objects per frame without dropping below the critical 16.6-millisecond render budget.[3][7]

GJK provides rapid boolean detection, while EPA handles the computationally heavy resolution.

But knowing two objects are colliding is only half the battle. When a player's car slams into a concrete barrier, the engine does not just need a boolean "true" or "false"—it needs to know exactly how deep the car is buried in the wall and which direction to push it out. This is where GJK hits a hard mathematical wall. Because it stops the exact millisecond it traps the origin inside its simplex, it provides zero information about the depth or angle of the penetration.[4]

But knowing two objects are colliding is only half the battle.

Enter the Expanding Polytope Algorithm (EPA). When GJK returns a collision, it hands its final, origin-trapping simplex over to EPA. EPA takes that tetrahedron and begins inflating it like a balloon inside the Minkowski space. It finds the face of the simplex closest to the origin, fires another support function in that direction, and stretches the simplex outward to grab a new vertex on the edge of the Minkowski boundary.[4][6]

The computational cost of EPA scales significantly higher than GJK as the polytope expands.

EPA repeats this expansion, fracturing its own faces into smaller and smaller triangles, until it hits the absolute edge of the Minkowski Difference. The shortest distance from the origin to that final boundary is the exact penetration depth, and the vector pointing there is the collision normal. It is a computationally heavy, iterative process that can consume significant CPU cycles if the objects are highly curved, but it delivers the pixel-perfect resolution data required to calculate bounce, friction, and resting contact.[2]

The pairing of GJK and EPA creates a ruthless filter for physics engines. GJK acts as the lightweight, high-speed vanguard, rapidly clearing the 99 percent of objects that are not colliding. Only when an intersection is absolutely confirmed does the engine pay the heavy computational tax of spinning up EPA to resolve the physics. This division of labor is why a modern competitive shooter can simulate hundreds of grenades, players, and debris fragments simultaneously without melting the server.[5][7]

If the origin falls inside the Minkowski Difference, the original objects are colliding.

The implementation of these algorithms dictates the ceiling of a game's physical complexity. While the foundational reference materials from ACM and dyn4j contain no direct developer quotations, their mathematical proofs establish the hard rules of the virtual world: keep collision hulls convex, keep vertex counts low, and let the simplex do the hunting. Since its adaptation for real-time graphics, detailed extensively in Casey Muratori's landmark 2006 implementation guide, the algorithm has become industry standard. The next frontier lies in parallelizing these support functions across GPU compute shaders, potentially pushing collision checks from the thousands into the millions.[2][3][4]

Viewpoints in depth

GJK (Boolean Detection)

The lightweight, high-speed algorithm that determines if an intersection exists.

For: GJK is exceptionally fast, operating in near-constant time by only sampling extreme vertices via support functions. It completely avoids generating the full Minkowski Difference. Against: It provides zero actionable data for physics resolution; it only returns a binary true/false. Evidence: GJK typically resolves in 3-4 iterations for standard convex shapes, making it ideal for the broad-phase to narrow-phase transition. Verdict: Fits perfectly when rapidly culling non-colliding objects; fails completely when physical response (bounce, slide) is required.

EPA (Penetration Resolution)

The computationally heavy algorithm that calculates exact penetration depth and normals.

For: EPA delivers the exact mathematical vectors required to separate overlapping objects and calculate realistic physics responses. Against: It is highly iterative and computationally expensive, scaling poorly with complex, curved collision hulls. Evidence: EPA must continually expand a polytope, fracturing faces and recalculating distances until it finds the absolute boundary of the Minkowski space. Verdict: Fits perfectly when a confirmed collision requires precise physical resolution; does not fit as a primary detection tool due to its massive CPU overhead.

Sources

Source coverage

8 outlets

2 viewpoints surfaced

Detection Efficiency 50%Physics Resolution 50%
  1. [1]WikipediaDetection Efficiency

    Gilbert–Johnson–Keerthi distance algorithm

    Read on Wikipedia
  2. [2]ACM Transactions on GraphicsDetection Efficiency

    Improving the GJK Algorithm for Faster and More Reliable Distance Queries Between Convex Objects

    Read on ACM Transactions on Graphics
  3. [3]Casey MuratoriPhysics Resolution

    Implementing GJK (2006)

    Read on Casey Muratori
  4. [4]dyn4jPhysics Resolution

    EPA (Expanding Polytope Algorithm)

    Read on dyn4j
  5. [5]GameDev.netDetection Efficiency

    Implementing GJK

    Read on GameDev.net
  6. [6]Observable NotebooksPhysics Resolution

    2D GJK and EPA algorithms

    Read on Observable Notebooks
  7. [7]KumarcodePhysics Resolution

    2D Gilbert-Johnson-Keerthi and Expanding Polytope Algorithm

    Read on Kumarcode
  8. [8]Factlen Editorial Team

    Synthesis by Factlen editorial team

    Read on Factlen Editorial Team

Comments

Stay informed

Every angle. Every day.

Get Gaming & Esports stories with full source coverage and perspective breakdowns delivered to your inbox.