# How to handle simultaneous particles collision in simulation?

• nsNas
In summary, the order in which collisions are resolved can affect the final result in a simulation involving multiple colliding objects. It is important to properly handle all collisions, even if they occur simultaneously, in order to achieve accurate results. This can be done by iterating over each object and resolving its collisions with all others before updating the simulation.

#### nsNas

Suppose there are 3 balls colliding at the same time. I find that the order in which I resolve collisions makes a difference in the final result, which ofcourse makes no sense.

To explain and keep things simple, consider 3 balls in 1D, all same mass, elastic collision. The numbers at the top are the speeds and the arrows is the direction. Assume they are currently all touching each others, i.e. in collision

Code:
 -->2   -->1 <---3
O     O       O
A     B       C

This shows ball A hitting ball B from the back and ball B and C are colliding face on.

Now if we resolve collision A with B first, followed by resolving collision B with C, but using the new speed of B, this should give the same result if we instead have resolved collision of B with C, followed by resolving A with B (using the new speed of B).

But it does not.

first case: A with B, followed by B with C

A with B gives

Code:
 -->1   -->2
O     O
A     B

and B with C gives (but using new B speed of 2 above, not the original speed of 1)

Code:
 <--3   -->2
O     O
B     C

Hence the final result is

Code:
-->1   <--3  ---->2
O     O       O
A     B       C

second case: B with C, followed by A with B

B with C gives

Code:
 <--3   --->1
O     O
B     C
A with B (but using new speed of B of 3 above, not original 1)

Code:
<--3    -->2
O     O
A     B

Hence final result is

Code:
 <--3  -->2   ---->1
O     O       O
A     B       C

You can see the final state is different.

What Am I doing wrong? and more importantly, what is the correct method to handle this?

For simulation with many balls and also collision with walls, this case is very possible. (for example, ball hitting a wall and being hit by another ball at the same time, would give same problem as above, the order gives different results).

Currently I use a loop to iterate over all objects and resolve collisions between each 2 at a time. Hence the order I use is arbitrary (order is just the index of the ball in an array).

You're on the right track, but the problem is, you have not worked it through. Let me show this for one of the cases.

nsNas said:
first case: A with B, followed by B with C

A with B gives

Code:
 -->1   -->2
O     O
A     B

and B with C gives (but using new B speed of 2 above, not the original speed of 1)

Code:
 <--3   -->2
O     O
B     C

Hence the final result is

Code:
-->1   <--3  ---->2
O     O       O
A     B       C

Is that the final configuration? Can A really go to the right with speed 1 when B is going to the left with speed 3?

Is that the final configuration? Can A really go to the right with speed 1 when B is going to the left with speed 3?

Of course not, but this will cause collision between A and B in the next time step.

What else do you suggest doing? In all collision detections I've seen, one goes over each particle at a time, resolves its collisions with all others, and then update the simulation one time step (i.e. move all particles using their new speeds), and repeat.

How else should one handle this otherwise?

nsNas said:
Of course not, but this will cause collision between A and B in the next time step.

What else do you suggest doing? In all collision detections I've seen, one goes over each particle at a time, resolves its collisions with all others, and then update the simulation one time step (i.e. move all particles using their new speeds), and repeat.

How else should one handle this otherwise?

I think this is the right way to handle it. But do the next time step! Your original question said your "final result" is different in the two cases. The final result is when ALL collisions that could happen, have happened.

As a scientist, it is important to understand the principles behind the phenomenon in question and not just rely on trial and error to find a solution. In this case, it seems like the issue lies in the order in which you are resolving collisions. Let's break down the problem and come up with a systematic approach to handle simultaneous particle collisions in simulations.

First, it is important to understand the concept of momentum and how it is conserved in collisions. In an elastic collision, the total momentum of the system before and after the collision remains the same. This means that the sum of the individual momentums of each particle involved in the collision should be the same before and after the collision.

Now, let's consider the case of three particles colliding simultaneously. In this scenario, we have three equations for momentum conservation:

1. Momentum before collision: p1 + p2 + p3 = m1v1 + m2v2 + m3v3
2. Momentum after collision: p'1 + p'2 + p'3 = m1v'1 + m2v'2 + m3v'3
3. Conservation of total momentum: p1 + p2 + p3 = p'1 + p'2 + p'3

Using these equations, we can solve for the final velocities of each particle after the collision. This will ensure that the total momentum is conserved.

Now, let's consider the case where we resolve collisions in a specific order. In your example, you are resolving collision A with B first, followed by resolving collision B with C. This means that you are using the final velocity of B from the first collision to calculate the second collision. This can lead to incorrect results because the final velocity of B may change after the first collision.

To handle this issue, it is important to first calculate the final velocities of all three particles before resolving any collisions. This can be done by solving the three equations for momentum conservation simultaneously. Once you have the final velocities, you can then resolve the collisions in any order without affecting the final result.

In summary, the correct method to handle simultaneous particle collisions in simulations is to first calculate the final velocities of all particles before resolving any collisions. This ensures that the total momentum is conserved and the final result is accurate regardless of the order in which the collisions are resolved.

## 1. How do I determine the initial positions and velocities of the particles in a collision simulation?

In order to accurately simulate the collision of multiple particles, you will need to know their initial positions and velocities. This information can be obtained through experimental data or by using mathematical models to predict their movements.

## 2. What equations or algorithms can be used to simulate the collision of particles?

There are various equations and algorithms that can be used to simulate the collision of particles, such as Newton's laws of motion, the impulse-momentum theorem, and the coefficient of restitution. It is important to choose the appropriate equation or algorithm based on the specific scenario and the type of particles involved.

## 3. Is it possible to accurately simulate the collision of particles in a vacuum?

Yes, it is possible to accurately simulate the collision of particles in a vacuum. In fact, simulating particles in a vacuum can eliminate the effects of external forces, such as air resistance, and provide a more precise result.

## 4. How do I handle collisions between particles of different sizes or masses?

When simulating the collision of particles with different sizes or masses, it is important to consider the conservation of momentum and energy. The larger or more massive particle will have a greater effect on the collision, so adjustments may need to be made in the calculations to account for this difference.

## 5. Can I use a computer program to handle simultaneous particle collisions in a simulation?

Yes, computer programs can be used to handle simultaneous particle collisions in a simulation. These programs can take into account various factors, such as the initial conditions, equations, and algorithms, to accurately simulate the collision and provide visual representations of the results.