Continuous Collision (CCD)
Continuous Collision Detection (CCD & Swept Volumes): In discrete physics simulations, collision detection evaluates positions only at discrete time steps $t$ and $t + \Delta t$. A high-speed projectile (or robotic arm) can move entirely through a thin wall in a single frame without either endpoint overlapping the obstacle—a catastrophic glitch known as tunneling. CCD treats motion as a 4D spatiotemporal swept volume (e.g. a capsule) to compute the exact continuous Time of Impact (TOI).
CCD Swept Volume Principles:
1def solve_ccd_time_of_impact(p0, p1, radius, wall_x):2 """3 Continuous Collision Detection (CCD) for high-speed sphere vs vertical wall.4 Prevents discrete tunneling where object jumps across wall between frames.5 Solves for exact Time of Impact (TOI) in interval [0, 1].6 """7 dx = p1[0] - p0[0]8 if abs(dx) < 1e-6:9 return None # Parallel motion1011 # Hit occurs when center reaches wall_x - radius12 toi = (wall_x - radius - p0[0]) / dx13 if 0.0 <= toi <= 1.0:14 hit_pos = p0 + toi * (p1 - p0)15 return toi, hit_pos16 return None
Speculative Contacts (Constraint-Based Anti-Tunneling): Iterative continuous collision solvers (like conservative advancement) require expensive root-finding loops that drag down simulation framerates. Speculative contacts solve tunneling directly inside the linear velocity constraint solver. By generating a "speculative" contact joint before the bodies actually touch, the velocity solver clamps closing speeds so the object arrives flush against the obstacle without ever piercing it.
Speculative Contact Mechanism:
1def generate_speculative_contact(pos, vel, dt, wall_pos, wall_normal):2 """3 Speculative Contact generation (Erwin Coumans / Bullet Physics).4 If distance to obstacle d is less than incoming velocity component along normal:5 d < (vel . wall_normal) * dt,6 insert a speculative contact constraint with distance offset d.7 Limits normal impulse so body halts exactly at contact plane without penetrating.8 """9 dist = np.dot(wall_pos - pos, wall_normal)10 v_proj = -np.dot(vel, wall_normal)1112 if 0.0 < dist < v_proj * dt:13 # Generate speculative contact constraint before penetration occurs14 max_impulse_v = dist / dt15 return True, max_impulse_v16 return False, 0.0
Related Concepts
GJK algorithm, EPA penetration depth, CCD swept volumes, and speculative contacts.
Interactive geometrical visualization of GJK collision detection and EPA penetration manifolds.
Interactive geometrical visualization of solar shadow envelopes and specular acoustic ray tracing.