Algorithm Search⌘K

Proofs: Collision prediction and resolution

These are the human proofs of Collision prediction and resolution, at full length.

Prediction finds the first contact, and resolution is an elastic bounce full

This proof shows: correctness.

We use the notation of the page. Disks ii and jj have positions ri,rjr_i, r_j, velocities vi,vjv_i, v_j, radii si,sjs_i, s_j and masses mi,mj>0m_i, m_j > 0. Let Δr=rj−ri\Delta r = r_j - r_i, Δv=vj−vi\Delta v = v_j - v_i, σ=si+sj\sigma = s_i + s_j, and

a=Δv⋅Δv,b=Δv⋅Δr,c=Δr⋅Δr−σ2,d=b2−ac.a = \Delta v \cdot \Delta v, \qquad b = \Delta v \cdot \Delta r, \qquad c = \Delta r \cdot \Delta r - \sigma^2, \qquad d = b^2 - a c.

On straight paths, the centres at time tt differ by Δr+t Δv\Delta r + t\, \Delta v. The disks touch exactly when ∣Δr+t Δv∣=σ|\Delta r + t\, \Delta v| = \sigma, that is, when f(t)=0f(t) = 0 for

f(t)=∣Δr+t Δv∣2−σ2=at2+2bt+c.f(t) = |\Delta r + t\, \Delta v|^2 - \sigma^2 = a t^2 + 2 b t + c.

Lemma 1 (pair prediction). Assume c>0c > 0 (the disks do not touch or overlap at time 0) and i≠ji \ne j. Then TIME-TO-HIT(i,j)(i, j) returns the smallest t≥0t \ge 0 with f(t)=0f(t) = 0, and it returns ∞\infty exactly when no such tt exists.

Proof. We follow lines L4 to L8.

Case b≥0b \ge 0 (line L4 returns ∞\infty). For t≥0t \ge 0 we have at2≥0a t^2 \ge 0 and 2bt≥02 b t \ge 0, so f(t)≥c>0f(t) \ge c > 0. No contact exists, and ∞\infty is right. This case contains a=0a = 0: then Δv=0\Delta v = 0 and b=0b = 0.

Case b<0b < 0. Then Δv≠0\Delta v \ne 0, so a>0a > 0, and line L8 does not divide by 0.

  • Subcase d<0d < 0 (line L7 returns ∞\infty). The quadratic at2+2bt+ca t^2 + 2 b t + c with a>0a > 0 has the minimum value c−b2/a=−d/a>0c - b^2/a = -d/a > 0. So f(t)>0f(t) > 0 for each real tt, no contact exists, and ∞\infty is right.
  • Subcase d≥0d \ge 0. The roots of ff are t±=(−b±d)/at_{\pm} = (-b \pm \sqrt d)/a, and both are real. Their product is c/a>0c/a > 0 and their sum is −2b/a>0-2b/a > 0. So both roots are positive. Line L8 returns t−=−(b+d)/at_- = -(b + \sqrt d)/a, the smaller root. Since f(0)=c>0f(0) = c > 0 and ff has no root in [0,t−)[0, t_-), f>0f > 0 on [0,t−)[0, t_-) by continuity, and f(t−)=0f(t_-) = 0. So t−t_- is the first time of contact. When d=0d = 0 the two roots are equal and the disks graze. □\square

The second root t+t_+ is the time at which the disks would stop overlapping if they passed through each other. It has no physical meaning, because the bounce at t−t_- changes the paths.

Lemma 2 (wall prediction). Assume si≤rx≤1−sis_i \le r_x \le 1 - s_i. Lines L9 to L11 return the smallest t≥0t \ge 0 at which rx+tvx=1−sir_x + t v_x = 1 - s_i or rx+tvx=sir_x + t v_x = s_i, or ∞\infty if there is none.

Proof. If vx=0v_x = 0, then rxr_x never changes. If rxr_x is strictly between sis_i and 1−si1 - s_i, there is no contact; if it is equal to one of them, the disk slides along the wall, which the method treats as no event. If vx>0v_x > 0, then rx+tvxr_x + t v_x increases; it reaches 1−si1 - s_i at t=(1−si−rx)/vx≥0t = (1 - s_i - r_x)/v_x \ge 0, and it reaches sis_i only at t≤0t \le 0. If vx<0v_x < 0, the same argument with the roles swapped gives t=(si−rx)/vx≥0t = (s_i - r_x)/v_x \ge 0, since the numerator and the denominator are both at most 0. The horizontal walls are the same with ryr_y and vyv_y. □\square

Lemma 3 (resolution). Let the disks touch, so ∣Δr∣=σ|\Delta r| = \sigma, and let n=Δr/σn = \Delta r/\sigma, a unit vector. Let vi′,vj′v_i', v_j' be the velocities after lines L14 to L17, and Δv′=vj′−vi′\Delta v' = v_j' - v_i'. Then

  1. mivi′+mjvj′=mivi+mjvjm_i v_i' + m_j v_j' = m_i v_i + m_j v_j (momentum);
  2. Δv′=Δv−2(Δv⋅n) n\Delta v' = \Delta v - 2 (\Delta v \cdot n)\, n, so Δv′⋅n=−Δv⋅n\Delta v' \cdot n = -\Delta v \cdot n, and Δv′⋅w=Δv⋅w\Delta v' \cdot w = \Delta v \cdot w for each ww orthogonal to nn;
  3. mi∣vi′∣2+mj∣vj′∣2=mi∣vi∣2+mj∣vj∣2m_i |v_i'|^2 + m_j |v_j'|^2 = m_i |v_i|^2 + m_j |v_j|^2 (kinetic energy);
  4. among all updates of the form vi′=vi+(λ/mi) nv_i' = v_i + (\lambda/m_i)\, n, vj′=vj−(λ/mj) nv_j' = v_j - (\lambda/m_j)\, n (equal and opposite impulses along the line of centres), the energy is kept only for λ=0\lambda = 0 and for λ=J\lambda = J.

Proof. Lines L14 and L15 give the impulse vector (Jx,Jy)=Jn(J_x, J_y) = J n with

J=2mimj(Δv⋅Δr)σ(mi+mj)=2μ (Δv⋅n),μ=mimjmi+mj,J = \frac{2 m_i m_j (\Delta v \cdot \Delta r)}{\sigma (m_i + m_j)} = 2 \mu\, (\Delta v \cdot n), \qquad \mu = \frac{m_i m_j}{m_i + m_j},

using Δv⋅Δr=σ(Δv⋅n)\Delta v \cdot \Delta r = \sigma (\Delta v \cdot n). Lines L16 and L17 set vi′=vi+(J/mi)nv_i' = v_i + (J/m_i) n and vj′=vj−(J/mj)nv_j' = v_j - (J/m_j) n.

  1. mivi′+mjvj′=mivi+Jn+mjvj−Jn=mivi+mjvjm_i v_i' + m_j v_j' = m_i v_i + J n + m_j v_j - J n = m_i v_i + m_j v_j.
  2. Δv′=Δv−J(1/mi+1/mj) n=Δv−(J/μ) n=Δv−2(Δv⋅n) n\Delta v' = \Delta v - J (1/m_i + 1/m_j)\, n = \Delta v - (J/\mu)\, n = \Delta v - 2 (\Delta v \cdot n)\, n. Taking the dot product with nn, and using n⋅n=1n \cdot n = 1, gives Δv′⋅n=Δv⋅n−2Δv⋅n=−Δv⋅n\Delta v' \cdot n = \Delta v \cdot n - 2 \Delta v \cdot n = -\Delta v \cdot n. For w⊥nw \perp n, Δv′⋅w=Δv⋅w\Delta v' \cdot w = \Delta v \cdot w.
  3. Let M=mi+mjM = m_i + m_j and V=(mivi+mjvj)/MV = (m_i v_i + m_j v_j)/M, the velocity of the centre of mass. Then vi=V−(mj/M)Δvv_i = V - (m_j/M) \Delta v, since V−(mj/M)(vj−vi)=(mivi+mjvj−mjvj+mjvi)/M=viV - (m_j/M)(v_j - v_i) = (m_i v_i + m_j v_j - m_j v_j + m_j v_i)/M = v_i, and in the same way vj=V+(mi/M)Δvv_j = V + (m_i/M) \Delta v. Expanding,
mi∣vi∣2+mj∣vj∣2=M∣V∣2−2 V⋅Δv(mimjM−mjmiM)+(mimj2M2+mjmi2M2)∣Δv∣2=M∣V∣2+μ∣Δv∣2.m_i |v_i|^2 + m_j |v_j|^2 = M |V|^2 - 2\, V \cdot \Delta v \left( \frac{m_i m_j}{M} - \frac{m_j m_i}{M} \right) + \left( \frac{m_i m_j^2}{M^2} + \frac{m_j m_i^2}{M^2} \right) |\Delta v|^2 = M |V|^2 + \mu |\Delta v|^2.

The same identity holds after the bounce with V′V' and Δv′\Delta v'. By part 1, V′=VV' = V. By part 2, Δv′\Delta v' is the reflection of Δv\Delta v in the line orthogonal to nn, so ∣Δv′∣2=∣Δv∣2−4(Δv⋅n)2+4(Δv⋅n)2∣n∣2=∣Δv∣2|\Delta v'|^2 = |\Delta v|^2 - 4 (\Delta v \cdot n)^2 + 4 (\Delta v \cdot n)^2 |n|^2 = |\Delta v|^2. So the energy is the same. 4. For a general λ\lambda, the momentum is kept as in part 1, so V′=VV' = V, and Δv′=Δv−(λ/μ)n\Delta v' = \Delta v - (\lambda/\mu) n. By the identity of part 3, the energy is kept if and only if ∣Δv−(λ/μ)n∣2=∣Δv∣2|\Delta v - (\lambda/\mu) n|^2 = |\Delta v|^2, that is, −2(λ/μ)(Δv⋅n)+λ2/μ2=0-2 (\lambda/\mu)(\Delta v \cdot n) + \lambda^2/\mu^2 = 0, that is, λ=0\lambda = 0 or λ=2μ(Δv⋅n)=J\lambda = 2 \mu (\Delta v \cdot n) = J. □\square

When the disks approach, Δv⋅n<0\Delta v \cdot n < 0, so after the bounce Δv′⋅n>0\Delta v' \cdot n > 0 and they separate: a new call of TIME-TO-HIT on the pair has b>0b > 0 and returns ∞\infty. The root λ=0\lambda = 0 would let the disks pass through each other. A wall bounce (lines L19 and L20) reverses the component normal to the wall and keeps the other one, so it keeps ∣vi∣|v_i| and the kinetic energy.

Theorem (the main loop). Assume the start state is valid and that no two events have the same time. Then SIMULATE processes the collisions of the system in the order of time, each at its true time, with the right velocities after it.

Proof. Call an event in QQ valid when its stored counts equal the current counts of its disks. We prove by induction on the number of iterations that, at the start of each iteration with current time tt:

(I) The state at time tt is the true state of the system. For each disk ii and each disk kk (and each wall), if the true next contact of ii with kk on the current paths happens at a time t′≤t' \le limit, then QQ holds a valid event (t′,i,k)(t', i, k) or (t′,k,i)(t', k, i). Each valid event in QQ is a true future contact on the current paths, at a time ≥t\ge t.

Initialization. At t=0t = 0 the state is the input. Line L26 calls PREDICT for every disk, which by Lemmas 1 and 2 inserts each first contact on the current paths with the current counts.

Maintenance. Let ee be the event popped by line L28. If ee is stale, line L29 drops it, and (I) still holds, since a stale event is not counted by (I). Let ee be valid, at time tet_e. Each valid event is a true future contact, so te≥tt_e \ge t. Assume that a true contact happens at a time t′′<tet'' < t_e between some disks pp and qq (or pp and a wall). The first such contact is the next contact of pp and qq on their current paths, so by (I) a valid event at t′′t'' is in QQ, and EXTRACT-MIN would return it before ee. So no contact happens in (t,te)(t, t_e), all disks move on straight lines up to tet_e, and line L30 gives the true state at tet_e. Line L32 applies the true bounce, by Lemma 3 or the wall rule. Now only the paths of e.ae.a and e.be.b change. Line L18 or lines L19 and L20 raise their counts, so every old event that involves them becomes stale. The events of other pairs keep their counts and remain true, since their paths did not change. Line L33 inserts the new next contacts of e.ae.a and e.be.b with every other disk and with the walls, by Lemmas 1 and 2. So (I) holds at time tet_e.

Termination. We assume, as the hard-disk model does, that only finitely many contacts happen up to the limit (no infinite chain of collisions in a finite time). Each valid event is a distinct contact, so there are finitely many of them. Each stale event was inserted by the start or by a valid event, and each call of PREDICT inserts at most n+2n + 2 events. So the loop pops finitely many events and stops. When QQ is empty, no valid event at a time ≤\le limit remains, so by (I) no contact happens in (t,limit](t, \text{limit}], and line L34 moves every disk to its true position at the limit. ■\blacksquare

When several events have the same time, the order among them is the order of the queue. Then the result is one of the possible outcomes of the simultaneous contacts; a triple contact has no unique physical answer in the hard-disk model.

Back to Collision prediction and resolution