Inferensys

Glossary

Narrowphase

Narrowphase is the second, precise stage in the collision detection pipeline where potentially colliding pairs identified by the broadphase are tested in detail to compute exact contact points, normals, and penetration depth.
DevOps managing AI deployment pipeline on laptop, CI/CD stages visible, automation-focused workspace.
PHYSICS SIMULATION ENGINES

What is Narrowphase?

Narrowphase is the second, precise stage in the collision detection pipeline where potentially colliding pairs identified by the broadphase are tested in detail to compute exact contact points, normals, and penetration depth.

Narrowphase is the detailed collision detection stage that follows the broadphase. It takes the list of potentially intersecting object pairs and performs exact geometric tests to determine if a collision has actually occurred. For convex shapes, algorithms like the Gilbert–Johnson–Keerthi (GJK) algorithm and the Expanding Polytope Algorithm (EPA) are used to compute the penetration depth and contact manifold. This stage outputs precise contact points, surface normals, and penetration data, which are critical inputs for the subsequent constraint solver that resolves the collision forces.

The computational cost of narrowphase is high, as it involves solving complex geometric queries. Its efficiency is paramount for real-time simulations in robotics and gaming. The output—a set of contact constraints—defines how bodies interact, directly influencing the physical realism of rigid body dynamics. In the context of sim-to-real transfer learning, accurate narrowphase collision resolution in a physics engine is essential for training robust robotic policies that can handle precise manipulation and complex environmental interactions before physical deployment.

PHYSICS SIMULATION ENGINES

Core Functions of the Narrowphase

The narrowphase is the precision stage of collision detection. It takes the potentially colliding pairs identified by the broadphase and performs detailed geometric tests to compute exact contact information required for the constraint solver.

01

Exact Contact Point Calculation

The primary function of the narrowphase is to compute the exact points of intersection between two colliding shapes. This is far more precise than the bounding volume approximations used in the broadphase. For convex shapes, algorithms like GJK (Gilbert–Johnson–Keerthi) and EPA (Expanding Polytope Algorithm) are used to find the closest points or penetration depth. The output is a set of one or more contact points in world space, which are passed to the constraint solver to generate appropriate collision responses.

02

Contact Normal and Penetration Depth

Beyond just finding contact points, the narrowphase must calculate the contact normal (a unit vector pointing from one body to the other, defining the direction of separation) and the penetration depth (the scalar distance the shapes overlap). This data is critical for the physics engine's constraint solver (e.g., solving a Linear Complementarity Problem) to apply correct impulses that resolve the collision, prevent interpenetration, and simulate realistic bouncing or sliding with friction.

03

Shape-Specific Geometric Tests

The narrowphase implements specialized, efficient algorithms for different primitive shape pairs. Common tests include:

  • Sphere vs. Sphere: Simple distance check between centers.
  • Box vs. Box: Separating Axis Theorem (SAT) is commonly used.
  • Capsule vs. Mesh: Often involves line segment to triangle tests.
  • Convex vs. Convex: GJK/EPA is the standard.
  • Concave vs. Anything: Typically requires decomposition into convex parts or use of Signed Distance Fields (SDFs). The choice of algorithm directly impacts simulation accuracy and performance.
04

Continuous Collision Detection (CCD)

For fast-moving objects, discrete collision detection (testing at single time steps) can fail, causing tunneling (where an object passes through another). A key advanced function of the narrowphase is Continuous Collision Detection (CCD), which tests the swept volume of an object's path between time steps. This involves more complex continuous geometric queries (e.g., conservative advancement) to compute the time of impact (TOI) and generate speculative contacts, ensuring robust simulation of bullets, thin walls, or rapidly moving robotic parts.

05

Contact Persistence and Caching

To improve stability and performance, the narrowphase often implements contact caching or warm starting. If a contact pair was colliding in the previous simulation step, its contact manifold (set of points) is stored and reused as a starting point for the next step. This persistence reduces jitter, allows the constraint solver to converge faster, and is essential for stable stacking and resting contacts. Managing this cache—adding new contacts, merging, and pruning old ones—is a core narrowphase responsibility.

06

Integration with the Physics Pipeline

The narrowphase does not operate in isolation. It is a critical link between the broadphase and the constraint solver. Its performance dictates the solver's workload. Efficient narrowphase implementations are often parallelized, processing multiple collision pairs simultaneously. The computed contact data (point, normal, depth) is formatted into a contact manifold and passed to the solver (like a Projected Gauss-Seidel solver) which calculates the final forces and torques to apply, completing the collision resolution loop.

PHYSICS SIMULATION PIPELINE

How Narrowphase Detection Works

Narrowphase is the second, precise stage in the collision detection pipeline where potentially colliding pairs identified by the broadphase are tested in detail to compute exact contact points, normals, and penetration depth.

Narrowphase detection is the computational stage where pairs of objects flagged by the broadphase undergo exact geometric intersection tests. For convex shapes, algorithms like the Gilbert–Johnson–Keerthi (GJK) algorithm and the Expanding Polytope Algorithm (EPA) are used to determine collision status and compute penetration depth and contact normal. This stage outputs a precise contact manifold—a set of contact points and associated data—which is passed to the constraint solver to resolve physical interactions.

The narrowphase operates on fundamental shape primitives like spheres, boxes, capsules, and convex hulls. For complex concave shapes, they are often decomposed into convex parts. The generated contact constraints—including position, normal, and friction parameters—are critical for the solver to apply correct impulses, preventing interpenetration and simulating realistic rigid body dynamics. Efficient narrowphase algorithms are essential for the stability and physical accuracy of the overall physics simulation.

ALGORITHM COMPARISON

Common Narrowphase Algorithms

Comparison of core algorithms used in the narrowphase stage to compute exact contact information between convex shapes.

AlgorithmShape SupportPrimary OutputComputational ComplexityTypical Use Case

Gilbert–Johnson–Keerthi (GJK)

Convex Polyhedra

Distance / Collision Boolean

O(n)

General convex collision, distance queries

Expanding Polytope Algorithm (EPA)

Convex Polyhedra

Penetration Depth & Contact Normal

O(n²) worst-case

Computing contact info for penetrating shapes

Separating Axis Theorem (SAT)

Convex Polyhedra (Boxes, Polygons)

Collision Boolean & Minimum Translation Vector

O(n) for boxes

Axis-aligned and oriented bounding boxes (AABBs/OBBs)

Minkowski Portal Refinement (MPR)

Convex Polyhedra

Penetration Depth & Contact Normal

O(n)

Alternative to GJK/EPA, often used in game physics

Sphere-Capsule, Capsule-Capsule

Sphere, Capsule

Exact Contact Points

O(1)

Character controllers, simple swept volumes

V-Clip (Voronoï Clip)

Convex Polyhedra

Distance & Closest Points

O(n)

Maintaining closest features between moving objects

Quickhull-based Intersection

Convex Hulls

Intersection Polyhedron

O(n log n)

Exact intersection volume for complex queries

PHYSICS SIMULATION ENGINES

Why Narrowphase Accuracy Matters for Sim-to-Real

The narrowphase stage is the critical bottleneck for simulation fidelity. Inaccurate contact modeling here creates a 'reality gap' that policies trained in simulation cannot cross, leading to catastrophic failure on real hardware.

01

Contact Point & Normal Precision

The narrowphase calculates the exact point of contact and the surface normal at that point. In robotics, this determines the direction of contact forces. An error of a few millimeters or degrees in simulation leads to incorrect force application in the real world, causing a robot to slip, drop an object, or apply unsafe pressure. For example, a gripper's success in picking up a delicate object is entirely dependent on the precise normal vector computed during contact.

02

Penetration Depth Calculation

This is the measure of how much two shapes overlap. Accurate penetration depth is non-negotiable for the constraint solver, which uses it to calculate the impulse needed to push the objects apart in a single time step.

  • Too shallow: Objects appear to float or make unstable contact.
  • Too deep: The solver applies massive, unrealistic corrective forces, causing 'jitter' or explosive behavior. This inaccuracy directly corrupts the force/torque data a reinforcement learning policy uses to learn stable manipulation.
03

Algorithm Choice Defines Fidelity

Different narrowphase algorithms trade speed for accuracy, directly impacting sim-to-real transfer.

  • GJK/EPA (Gilbert–Johnson–Keerthi/Expanding Polytope Algorithm): The gold standard for convex shapes. Provides exact contact features but is computationally intensive.
  • SAT (Separating Axis Theorem): Efficient for axis-aligned geometries but limited in general cases.
  • Mesh-vs-Mesh: Extremely expensive. Often approximated with primitive decomposition (breaking meshes into spheres, capsules, convex hulls) for real-time performance, introducing fidelity loss. The choice here dictates what contact phenomena can be learned in simulation.
04

The Reality Gap in Friction & Restitution

Narrowphase outputs (contact point, normal, depth) are the primary inputs for friction and restitution (bounciness) models. An error in the contact normal will miscalculate the tangential (friction) force direction. Inaccurate penetration depth affects the normal force magnitude, which in turn scales the friction force (via the Coulomb model). A policy that learns to slide a box in simulation will fail if the simulated friction is 20% off from real-world values due to underlying narrowphase inaccuracies.

05

Impact on Policy Observation Space

In reinforcement learning for robotics, the observation space often includes proprioceptive data (joint torques) and sometimes estimated external contact forces. These signals are derived from the physics engine's resolution of contacts. Noisy or biased narrowphase computations inject erroneous observations into the policy during training. The policy then learns to rely on these simulation artifacts, which vanish on real hardware, causing immediate distributional shift and failure.

06

Benchmark: The Cantilever Snap Test

A canonical test for narrowphase and solver fidelity is simulating a compliant cantilever beam (e.g., a ruler) pressed against a peg until it snaps past. This test stresses:

  • Continuous Collision Detection (CCD): To prevent the beam tip from tunneling through the peg.
  • Accurate contact generation during sliding.
  • Stable constraint resolution under high stress. A physics engine that fails this simple benchmark cannot be trusted to train policies for real-world contact-rich tasks like assembly or cable manipulation.
PHYSICS SIMULATION ENGINES

Frequently Asked Questions

Essential questions about the Narrowphase, the precise computational stage in physics engines responsible for detailed collision analysis.

Narrowphase is the second, precise stage in the collision detection pipeline where potentially colliding pairs, identified by the broadphase, are tested in detail to compute exact contact points, surface normals, and penetration depth. It operates on the reduced set of object pairs that passed the initial broadphase culling, applying exact geometric tests to shapes like convex hulls, spheres, and capsules. The output is a manifold—a data structure containing the precise geometric information of the contact—which is then passed to the constraint solver to calculate appropriate collision responses and forces, ensuring objects do not interpenetrate while obeying physical laws like friction and restitution.

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.