How to handle a simultaneous collision so that the processing order does not matter?

Suppose there are three balls colliding at the same time. I find that the order in which I resolve the collisions matters in the final result, which of course does not make sense.

To explain and keep things simple, consider 3 balls in 1D, all the same masses, elastic collision. The numbers at the top are the speeds, and the arrows are the direction. Suppose now they all touch each other, i.e. in a collision

-->2 -->1 <---3 OOO ABC 

This shows ball A hitting ball B from behind, and ball B and C collide face to face.

Now, if we first allow the collision of A with B, and then allow the collision of B with C, but using the new speed B, this should give the same result if instead we allowed the collision of B with C, followed by the resolution of A with B ( using the new speed B).

But this is not so.

first case: A with B followed by B with C

A with B gives

  -->1 -->2 OOAB 

and B with C gives (but using the new speed B 2 is higher, not the initial speed 1)

  <--3 -->2 OOBC 

Therefore, the final result

  -->1 <--3 ---->2 OOO ABC 

second case: B with C followed by A with B

B with C gives

  <--3 --->1 OOBC 

A with B (but using the new speed B of 3 higher than the original 1)

 <--3 -->2 OOAB 

Therefore, the final result

  <--3 -->2 ---->1 OOO ABC 

You can see that the final state is different.

What am I doing wrong? and more importantly, what is the right method for this?

For simulations with a large number of balls, as well as collisions with walls, this case is very possible. (for example, a ball hitting a wall and simultaneously being hit by another ball will give the same problem as above, the order gives different results).

I am currently using a loop to iterate over all objects and resolve conflicts between every 2 at a time. Therefore, the order I use is arbitrary (the order is just the index of the ball in the array).

+5
source share
1 answer

You are not doing anything wrong, but your response to the collision is not yet complete. In the first, ABs still collide, and in the second, B and C are still colliding. Therefore, you must resolve these clashes.

And if you come across, you will get the same answer A <--3 , B-->1, C-->2

Although in your simulation you may encounter objects at the same time, in reality they will never be. There will always be little time between collisions (maybe very little). Therefore, for simplicity, physical engines allow collisions in pairs. But they must do this until all the pairs are separated. And this requires several iterations. And the number of iterations can become very high if you are trying to simulate styling bodies such as configuration.

you can check

how to sort objects for guendelman sound propagation?

for more information to reduce iterations.

+3
source

All Articles