NTNUJAVA Virtual Physics LaboratoryEnjoy the fun of physics with simulations! Backup site http://enjoy.phy.ntnu.edu.tw/ntnujava/
November 01, 2020, 08:44:36 am
 Welcome, Guest. Please login or register.Did you miss your activation email? 1 Hour 1 Day 1 Week 1 Month Forever Login with username, password and session length

 Home Help Search Login Register
You cannot always have happiness but you can always give happiness. ..."Mother Teresa(1910-1997, Roman Catholic Missionary, 1979 Nobel Peace Prize)"

 Pages: [1]   Go Down
 Author Topic: multiple collisions with gravity  (Read 13095 times) 0 Members and 1 Guest are viewing this topic. Click to toggle author information(expand message area).
frecka
Newbie

Offline

Posts: 1

 « Embed this message on: December 31, 2008, 03:01:37 pm »

I've recently become interested in programming physics simulations and played around with elastic collisions of balls using java.  A natural extension of this for me was to add gravity and see how the coding for collisions between pairs of balls works with larger numbers of balls.  In particular, I was hoping to get a simulation in which I could throw a bunch of balls together and have them stack up on the ground in a realistic manner.

I have an applet online with what I have so far at:
http://cfb.qqnoobs.com/Balls/

As you can see for yourself by adding enough balls to fill a significant portion of the virtual room (with gravity on), the stacking of balls works to some extent.  But balls eventually get pushed together and stuck overlapping and frozen in space for a while, which is obviously a problem.  My question is if you have any ideas for a good way to implement the collisions of multiple balls during the course of one frame of motion.

The way I handle it right now is just cycling through each pair of balls once per frame to see if each pair collides. If a pair is found to collide, I move the two balls to where they are located the instant before they collide (ie 1 pixel separation) and change the speeds accordingly for the elastic collision of equal masses. In subsequent checks for collisions, I use the new ball speeds and positions. So if a ball collides multiple times in a cycle, it'll end up in the last place it collided, which may very well be overlapping with another ball.

I've experimented with also moving the ball after colliding according to new velocities, which just makes the overlapping problem much worse. I've also tried looping the collision cycle in each frame to run as long as there are still two balls colliding, but then it gets stuck in infinite loops when balls just don't become separated.

I also have one last side question. Right now collisions between two balls are completely elastic, and collisions between a ball and a wall have a coefficient of restitution of 0.8. How would I go about making the balls lose energy when colliding with each other so that they don't constantly bounce around like they're undergoing Brownian motion? Can I just multiply their speeds after collision by a similar coefficient of restitution, or will the directions change because of this? (I tried using a restitution coefficient, which has an annoying effect of making balls get stuck together earlier and frozen in space instead of rolling off each other.)

That's all I have for now, thanks for any suggestions you have!
 Logged
Fu-Kwun Hwang
Administrator
Hero Member

Offline

Posts: 3086

 « Embed this message Reply #1 on: January 24, 2009, 06:06:36 pm »

I think the problem is coming from the way you treat the collision.
Try to treat two balls stick together when the relative speed between two balls is smaller than some minimum value (instead of always treat it as collision!).
 Logged
Femida
Newbie

Offline

Posts: 0

 « Embed this message Reply #2 on: March 04, 2015, 02:33:53 am » posted from:,,Satellite Provider

What necessary phrase... super, remarkable idea
 Logged
 Pages: [1]   Go Up
You cannot always have happiness but you can always give happiness. ..."Mother Teresa(1910-1997, Roman Catholic Missionary, 1979 Nobel Peace Prize)"
Jump to:

 Related Topics Subject Started by Replies Views Last post collisions Questions related to EJS Ka-lolek 3 8769 August 19, 2008, 10:03:44 pm by lookang Ball line collision and response. multiple collisions at once Request for physics Simulations slayer 64 4 15139 November 10, 2010, 08:55:50 pm by lookang Multiple Slit Diffraction optics ahmedelshfie 2 9460 October 06, 2020, 12:17:07 pm by MaryStone How many images (Multiple Reflection from two plane mirrors) optics ahmedelshfie 0 10572 May 20, 2010, 01:25:53 am by ahmedelshfie help for Rigid Body Collisions Request for physics Simulations sandeep1024 5 6500 January 19, 2012, 07:40:51 am by Fu-Kwun Hwang
Page created in 0.051 seconds with 22 queries.since 2011/06/15