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 and have positions , velocities , radii and masses . Let , , , and
On straight paths, the centres at time differ by . The disks touch exactly when , that is, when for
Lemma 1 (pair prediction). Assume (the disks do not touch or overlap at time 0) and . Then TIME-TO-HIT returns the smallest with , and it returns exactly when no such exists.
Proof. We follow lines L4 to L8.
Case (line L4 returns ). For we have and , so . No contact exists, and is right. This case contains : then and .
Case . Then , so , and line L8 does not divide by 0.
- Subcase (line L7 returns ). The quadratic with has the minimum value . So for each real , no contact exists, and is right.
- Subcase . The roots of are , and both are real. Their product is and their sum is . So both roots are positive. Line L8 returns , the smaller root. Since and has no root in , on by continuity, and . So is the first time of contact. When the two roots are equal and the disks graze.
The second root 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 changes the paths.
Lemma 2 (wall prediction). Assume . Lines L9 to L11 return the smallest at which or , or if there is none.
Proof. If , then never changes. If is strictly between and , 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 , then increases; it reaches at , and it reaches only at . If , the same argument with the roles swapped gives , since the numerator and the denominator are both at most 0. The horizontal walls are the same with and .
Lemma 3 (resolution). Let the disks touch, so , and let , a unit vector. Let be the velocities after lines L14 to L17, and . Then
- (momentum);
- , so , and for each orthogonal to ;
- (kinetic energy);
- among all updates of the form , (equal and opposite impulses along the line of centres), the energy is kept only for and for .
Proof. Lines L14 and L15 give the impulse vector with
using . Lines L16 and L17 set and .
- .
- . Taking the dot product with , and using , gives . For , .
- Let and , the velocity of the centre of mass. Then , since , and in the same way . Expanding,
The same identity holds after the bounce with and . By part 1, . By part 2, is the reflection of in the line orthogonal to , so . So the energy is the same. 4. For a general , the momentum is kept as in part 1, so , and . By the identity of part 3, the energy is kept if and only if , that is, , that is, or .
When the disks approach, , so after the bounce and they separate: a new call of TIME-TO-HIT on the pair has and returns . The root 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 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 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 :
(I) The state at time is the true state of the system. For each disk and each disk (and each wall), if the true next contact of with on the current paths happens at a time limit, then holds a valid event or . Each valid event in is a true future contact on the current paths, at a time .
Initialization. At 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 be the event popped by line L28. If is stale, line L29 drops it, and (I) still holds, since a stale event is not counted by (I). Let be valid, at time . Each valid event is a true future contact, so . Assume that a true contact happens at a time between some disks and (or and a wall). The first such contact is the next contact of and on their current paths, so by (I) a valid event at is in , and EXTRACT-MIN would return it before . So no contact happens in , all disks move on straight lines up to , and line L30 gives the true state at . Line L32 applies the true bounce, by Lemma 3 or the wall rule. Now only the paths of and 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 and with every other disk and with the walls, by Lemmas 1 and 2. So (I) holds at time .
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 events. So the loop pops finitely many events and stops. When is empty, no valid event at a time limit remains, so by (I) no contact happens in , and line L34 moves every disk to its true position at the limit.
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.