Initializing 3D Canvas...

Continuous Collision (CCD)

2 min read1 page

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:

1. Swept Capsule Primitive: A moving sphere sweeps a 3D capsule volume between $t_0$ and $t_1$. 2. Time of Impact (TOI): Solves root $f(t) = 0$ for the exact fractional timestamp $t \in [0, 1]$ of first contact. 3. Zero Tunneling Guarantee: Fast-moving mechanical parts cannot pass through safety barriers.
python
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 motion
10
11 # Hit occurs when center reaches wall_x - radius
12 toi = (wall_x - radius - p0[0]) / dx
13 if 0.0 <= toi <= 1.0:
14 hit_pos = p0 + toi * (p1 - p0)
15 return toi, hit_pos
16 return None
Projectile Velocity (Step Length)
4.50
2 min read1 page

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:

1. Predictive Distance Filter: Detects impending collision within time step d < v_n Δt. 2. One-Way Impulse Limit: Clamps approaching relative velocity to v_rel ≤ d / Δt. 3. Zero Solver Iteration Overhead: Integrates seamlessly into sequential impulse LCP solvers (e.g. Box2D, Bullet).
python
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)
11
12 if 0.0 < dist < v_proj * dt:
13 # Generate speculative contact constraint before penetration occurs
14 max_impulse_v = dist / dt
15 return True, max_impulse_v
16 return False, 0.0
Approaching Speed v
3.00