State of $N$-body system after time $t$ (elastic collision & no gravity) I am creating a gas particle simulator based game. All nodes (green circles) represent gaseous particles and collide elastically.
My algorithm correctly accounts for two-particle collisions, as the final velocity are calculated by directly applying an equation. However, it fails if three or more particles are overlapping (colliding) in the same clock-time (frame).
My question is how can I calculate the final velocities of a collision with more than two particles colliding. Note that if A collides with B and B collides with C, A need not collide with C (B may be in the center).
Is there an algorithm designed specifically for this?
Simulator: https://gravitifydemo1.github.io/
The momentum is incorrect (as of writing). However, the KE graph is changing its value. If the algorithm for two-particle collisions worked correctly, the KE wouldn't change. The graph is constant for most of the time but it goes up and down.
 A: One partial solution would be to use adaptive time steps, i.e., when you detect multiple collisions with the same particle at time $t+\Delta t$, your time step is reduced so that only one collision occurs with that particle, i.e, you compute the positions at $t+\epsilon \Delta t$, with $0 < \epsilon < 1$.
It does not solve all the problems, but it will reduce the likelihood of a multiple collision happening within one time step.

Edit:
Regarding multiple collisions, you may treat them as a sequence of pairwise collisions in the following way.
Let $n$ be the number of particles that collide together in one place. Let $S$ be the set of all $n(n-1)/2$ pairwise possible collisions.
For each $s_j \in S$ selected at random, process the collision between the pair and do the same thing for all pairs.
Problems with this approach:


*

*If many particles collide, you may end up processing collisions that effectively should not occur;

*A better way to do this type of approach would be to start from the outward collisions and "dive" into the interior ones. However, this will also increase the complexity of the code, since you will have to compute the distance to the centre (of mass) of the set of particles and to have an array with the distances sorted.
