NTNUJAVA Virtual Physics Laboratory
Enjoy the fun of physics with simulations!
Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
December 16, 2017, 04:46:07 am *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
 
   Home   Help Search Login Register  
Teaching without words. ...Lao Tzu (570-490 BC)
Google Bookmarks Yahoo My Web MSN Live Netscape Del.icio.us FURL Stumble Upon Delirious Ask FaceBook

Pages: [1]   Go Down
  Print  
Author Topic: 2D collision with multiple balls at the same time  (Read 21920 times)
0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
PL_kolek
Newbie
*
Offline Offline

Posts: 3

«
Embed this message
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

With regards
PL_kolek
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
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.

Embed a running copy of this simulation

Embed a running copy link(show simulation in a popuped window)
Full screen applet or Problem viewing java?Add http://www.phy.ntnu.edu.tw/ to exception site list
Press the Alt key and the left mouse button to drag the applet off the browser and onto the desktop. This work is licensed under a Creative Commons Attribution 2.5 Taiwan License
  • Please feel free to post your ideas about how to use the simulation for better teaching and learning.
  • Post questions to be asked to help students to think, to explore.
  • Upload worksheets as attached files to share with more users.
Let's work together. We can help more users understand physics conceptually and enjoy the fun of learning physics!
Logged
PL_kolek
Newbie
*
Offline Offline

Posts: 3

«
Embed this message
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!
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
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 v_0,
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
 \vec{v_a}=v \hat{x} + v\hat{y} and \vec{v_b}=v \hat{x} - v\hat{y}
 and assume the velocity for the incoming ball after the collision is v'

Conservation of momentum: v_0= 2 v+v'
Conservation of energy: \tfrac{1}{2}mv_0^2= \tfrac{1}{2}m v_a^2+\tfrac{1}{2}m v_b^2+\tfrac{1}{2}m v'^2=2mv^2+\tfrac{1}{2}m v'^2
which imply v_0^2=4 v^2+v'^2
So the result are: v'=0, v_0=2v
which mean that the incoming ball with initial velocity v_0 will be stopped (v'=0) just after the collision, and the other two balls will move with velocity
 \vec{v_a}=\tfrac{1}{2}v_0 \hat{x} + \tfrac{1}{2} v_0\hat{y}
and
 \vec{v_b}=\tfrac{1}{2}v_0 \hat{x} - \tfrac{1}{2}v_0 \hat{y}

However, this kind of situation normally will not happened in real life.
Logged
PL_kolek
Newbie
*
Offline Offline

Posts: 3

«
Embed this message
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!

PL_kolek
Logged
Some1
Newbie
*
Offline Offline

Posts: 2

«
Embed this message
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 » Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
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. ;-)
Logged
Holu Callouse
Newbie
*
Offline Offline

Posts: 3

«
Embed this message
Reply #7 on: November 26, 2012, 02:30:52 pm » posted from:-,-,UNITED STATES

Nice job, it’s a great post. The info is good to know!
Logged
ivwiwba
watchlist
Newbie
*
Offline Offline

Posts: 3

«
Embed this message
Reply #8 on: January 19, 2013, 10:10:03 am » posted from:FUQING,FUJIAN,CHINA

This is all very new to me and this article really opened my eyes.Thanks for sharing with us your wisdom.-*-
Logged
sajidtoor
Newbie
*
Offline Offline

Posts: 4

«
Embed this message
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.
-*-
Logged
Fu-Kwun Hwang
Administrator
Hero Member
*****
Offline Offline

Posts: 3080



WWW
«
Embed this message
Reply #10 on: February 11, 2013, 01:04:50 pm » posted from:,,Satellite Provider

You might want to check out Browian motion where several hundreds particles are collide with each other with any problem.
Logged
tomoisgood0444
watchlist
Newbie
*
Offline Offline

Posts: 1

«
Embed this message
Reply #11 on: April 19, 2013, 03:27:17 pm » posted from:NEW YORK CITY,NEW YORK,UNITED STATES

very good-*-
Logged
Pages: [1]   Go Up
  Print  
Teaching without words. ...Lao Tzu (570-490 BC)
 
Jump to:  


Related Topics
Subject Started by Replies Views Last post
Astroblaster balls (The Multiple Collision Accelerator!)
Kinematics
Fu-Kwun Hwang 2 17290 Last post December 23, 2015, 06:44:38 pm
by lookang
Ejs open source java applet 1D collision carts Elastic and Inelastic Collision « 1 2 3 »
Collaborative Community of EJS
lookang 77 81430 Last post March 26, 2012, 04:05:27 pm
by lookang
Ball line collision and response. multiple collisions at once
Request for physics Simulations
slayer 64 4 13177 Last post November 10, 2010, 08:55:50 pm
by lookang
Astroblaster balls (The Multiple Collision Accelerator!)
kinematics
ahmedelshfie 0 4565 Last post May 27, 2010, 11:54:33 pm
by ahmedelshfie
Ejs open source java applet 1D collision carts with realistic collision
Collaborative Community of EJS
lookang 4 10560 Last post February 19, 2013, 01:05:56 pm
by lookang
Powered by MySQL Powered by PHP Powered by SMF 1.1.13 | SMF © 2006-2011, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 1.084 seconds with 23 queries.since 2011/06/15