# 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.

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.

• That isn't a viable solution, because multiple collisions already occurred. I will plan to add more forces in the future, like EM & Gravity. It will be too expensive to calculate future collisions ahead-of-time. – Shukant Pal Mar 30 '19 at 14:45
• My idea was the following: if a collision occurs with 3 or more particles at time $t + \Delta t$ then check if it happens at time $t + \Delta t/2$ and keep dividing in half the interval. I agree that it can be expensive if there are many particles in a small volume. However, the way you're modelling right now may also be inaccurate if you only spot the collision after a large superposition of the particles, i.e., when the collision happens on the beginning of the interval $[t; t + \Delta t]$. I've edited with another idea for multiple collisions. – Ertxiem - reinstate Monica Mar 30 '19 at 15:34
• Note that the suggestion I did for the split of time may be only applied to the pair that collides, i.e., only for that pair you would compute an intermediate time step $t + \epsilon \Delta t$ and then only for that pair you would need to compute another time point at $t + \Delta t$. – Ertxiem - reinstate Monica Mar 30 '19 at 15:53