Progress is impossible without change; and those who cannot change their minds cannot change anything.
..."George Bernard Shaw(1865-1950, Irish dramatist, essayist and critic, Nobel Prize for Literature 1925)"

on: June 13, 2010, 05:42:29 am » posted from:Zlotow,Wielkopolskie,Poland

Hi! I come from Poland, but I found this website (I don't remember how), and I used the applet with explanation about 2D collision to understand this situation. The problem is, I cannot figure what happens and how to calculate the velocities of more colliding balls when they hit each other at the same time. I could predict, what would happen, but is not exact calculation, but my guess. Moreover, google didn't help me in finding information about that. I am trying to write my own simple billiard game, and the most difficult task to understand is the physics.

So could you please explain me (or at least post some links to such explanation) what happens when many balls collide?

Every ball has its mass (m), velocity (Vx, Vy), coordinates (x,y). The radius is constant, identical for every ball. Example for such situation: 3 balls with radius 10: -x=0, y=100, Vx=20, Vy=0, m=1 -x=100, y=90, Vx=0, Vy=0, m=1 -x=100, y=110, Vx=0, Vy=0, m=1

Reply #1 on: June 13, 2010, 09:34:38 am » posted from:Taipei,T\'ai-pei,Taiwan

The way to solve it depends on what is the purpose of your simulation.

For the case you provided above: Yes. in theory (mathematically), the first ball will collide with the other two ball at the same time. If you really need such precission: The above problem can be solve analytically.

However, in real case, there is always a small error. The first ball wil hit one of them first, then collide with the second one. You can check out Collision 2D to find out how to calculate collision between two balls. The same technique was used to calculate collision between many particles: Browian motion. or particle model of liquid in a container (microscopic)

If you need a better time precission, EJS has build in EVENT GUI interface to help you.

Select one of the experiment (other than the default: Random) Click Pause to hold the simulation, then drag one of the ball a very small amount and click play again. You can modify value of g to add gravity or change k for inelastic collision. You will find it really calculate all the collisions between particles.

Reply #2 on: June 14, 2010, 05:46:57 am » posted from:Warsaw,Warszawa,Poland

I have read on this site about 2D collision with 2 balls and I understand taht, thanks to you. I had the same thoughts about the problem - calculating every collision differently, one after another. So I must have made mistake in my code or my algorithm, because it doesn't work as it should.

Let me analyze the situation mentioned before (2 sticked balls, and a third one hitting them in the middle, at the same time): -I detect collision with one of the balls (let's say the upper one) -I have to move the moving ball back not to overlap staying one -I calculate velocities -I move the time forward, putting these two balls in new positions The effect is - Upper ball moved, moving ball bounced back, but there is no collision now with the last ball, and there won't be, as balls go further away from it. Whole my simulation doesn't work, because it gives wrong results. Where is the mistake? If it is not clear enough, I can upload pictures which will show what I mean. Thank you for your reply, now I know I was on a good way!

Reply #3 on: June 14, 2010, 08:58:08 am » posted from:Taipei,T\'ai-pei,Taiwan

Code:

The effect is - Upper ball moved, moving ball bounced back

Yes. There is something wrong with your code. If the incoming ball just collide with the upper one, it should move into the direction to collide with the second ball. (The incoming ball should not bounced back???).

In real life,usually, the incoming ball will hit one of the ball first then collide with the second one. If you want to simulate the incomng ball collide with the other two balls at the same time: Assume the incoming ball with initial valocity , Since the size of the balls are the same, and they all have the same mass. If the incoming ball hit the other two balls at the same time, the interactive force between incoming ball and any one of the ball are in the direction connect two center of the ball. So the direction is 45 degree or -45 degree. It means that the force is the same in x direction and in y direction. So the momentum change in x/y diretion are the same. So the velocity for the other two balls just after the collision are and and assume the velocity for the incoming ball after the collision is

Conservation of momentum: Conservation of energy: which imply So the result are: which mean that the incoming ball with initial velocity will be stopped () just after the collision, and the other two balls will move with velocity

and

However, this kind of situation normally will not happened in real life.

Reply #4 on: June 15, 2010, 05:12:02 am » posted from:Warsaw,Warszawa,Poland

I adapted your 2D collision applet to check what happens, when just two balls collide like in the case I provided (one of the staying balls missing). Now I see, that my balls act differently (does it sound weird?). I must have made a mistake in my calculations (for better understanding I made my own calculations to get your result, and in one place I didn't get your way in calculating the velocities), or putting them into the code. So I will try to fix it (In the worst case I will just copy your code, am i allowed to?), and if it still give no result, I will come back with more questions.

Thank you for your efforts to help me. Now I see I can't calculate it this way (too many possible situation without just one general algorithm), but simulating single collision should work. It is amazing, that I couldn't find help anywhere, and here I got answers quickly, with clear explanation to my problem. After learning a bit physics it gets more interesting than it looked. Thank you very much!

Reply #5 on: July 25, 2012, 10:04:22 am » posted from:Bucharest,Bucuresti,Romania

Hello!

My name is Alex and I am from Romania. Firstly I cannot thank you enough for providing these examples and explanations. It has helped me a lot. I am working on a 2D modable pool game and the 2D collision program was a lifesaver. It is better than any of my previous attempts and although I was never very good at mathematics and especially physics, I finally understand things in a bit more depth.

I have managed to create a little test frame for multiple ball collisions using a 0.1 of a pixel iteration for each ball (int)Math.ceil((10000/UPDATE_RATE)/0.1); //number of tests per frame with an iteration that is ALWAYS below 0.1 of a pixel and dividing the speeds accordingly to match the iteration.

This method actually works, but I am realizing that it is extremely inefficient and there is always a loss(which I may be able to accept though) since the balls have to always overlap(worst case possible 0.2 in between two balls) and then pull back r1+r2+0.01 across the segment that connects their centers so that they do not collide anymore when it happens. (0.01 is something to ignore the double variable imprecision). At more than 30-40 balls lag can inevitably be felt.

I haven't used EJS before. I will try this program. Also is there any way you could kindly provide the .java code file for the .jar file provided? It would help me immensely and I would like to ask if it is ok to use fragments of code from your applets into personal projects. I will give credit if necessary once the application is done!

Thank you again!

« Last Edit: July 25, 2012, 10:07:32 am by Some1 »

Reply #6 on: July 25, 2012, 07:06:27 pm » posted from:,,Satellite Provider

You are welcomed to check out Browian motion. You will find several hundreds particles collide with each other without any problem.

It was created with ejs. And it is much easier to create simulation with EJS. You are welcomed to download the jar file, run it and click right mouse button to open it in EJS. (You need to install EJS) Then , you will find out all the code in EJS environment. Good luck to your work. You are welcomed to share your code when you finish your work. ;-)

Reply #9 on: February 08, 2013, 05:01:34 pm » posted from:Sialkot,Punjab,Pakistan

This method actually works, but I am realizing that it is extremely inefficient and there is always a loss(which I may be able to accept though) since the balls have to always overlap(worst case possible 0.2 in between two balls) and then pull back r1+r2+0.01 across the segment that connects their centers so that they do not collide anymore when it happens. (0.01 is something to ignore the double variable imprecision). At more than 30-40 balls lag can inevitably be felt. -*-

Progress is impossible without change; and those who cannot change their minds cannot change anything.
..."George Bernard Shaw(1865-1950, Irish dramatist, essayist and critic, Nobel Prize for Literature 1925)"