Calculating new velocities after ball collision

  • Thread starter Thread starter blarp
  • Start date Start date
  • Tags Tags
    Ball Collision
AI Thread Summary
To calculate new velocities after ball collisions in a 3D physics mini-game, the law of conservation of momentum is essential. The discussion emphasizes starting with elastic collisions to understand the basic principles before progressing to inelastic collisions, where energy is not conserved. It is suggested to use vector mathematics to determine the angle of impact and the resulting velocities, considering both linear and angular momentum. The implementation of "soft spheres" that deform during collisions adds complexity, but initial simulations can simplify this by using fixed parameters. Understanding the physics through research and testing with known outcomes is crucial for achieving realistic results.
blarp
Messages
5
Reaction score
0
Hello all, I am making a physics mini game and I would like your help on calculating new velocities after ball collisions. I want the balls to bounce realistically off each other (3 dimensions by the way).

So once I detect a ball collision, these are the variables I have to work with

their x, y, and z velocities

their mass

I could probably calculate a unit vector which points from one ball to the other ball at collision. (Or i could get the 2 angles, yaw and pitch angles, but I think it would be best to keep this in vectors? i don't know)

their positions

their radius

And that's it I think, well, any ideas? I know u have to use the law of conservation of momentum but I am clueless on how to start.
 
Physics news on Phys.org
Welcome to PF.
You start by looking at how other programmers have solved the same problem and doing what they did. There are libraries for collisions.

For conservation of momentum, you are solving the two-body problem - which is doable in Newtonian mechanics. Look it up. You need to decide how inelastic your collisions will be.
 
Hi!
Start with something very simple and then increase the complexity. Write a test program with a known outcome to test intermediate results.

Start with elastic collisions in 1D or 2D:
http://en.wikipedia.org/wiki/Elastic_collision
Basically, you are solving conservation of momentum and energy. There is even a code example there.
The extension to 2D or 3D is rather straightforward.
Then continue with inelastic collisions where energy is not conserved:
http://en.wikipedia.org/wiki/Inelastic_collision

To take into account change in rotation, you also need to solve the conservation of angular momentum. This will be important for off-center collisions.

The implementation of 'soft spheres' that deform during collision is more difficult. In games, usually only the bump maps are changed, not the actual mesh.
 
Would I use the formula for new velocities on this page?

http://http://en.wikipedia.org/wiki/Inelastic_collision

Would I just use this formula for each dimension? Will this work for every case? What if a ball does not hit another ball head on, but it hits it at its side. Don't I need a formula that takes into account angle of impact?
 
You have received quite a lot of help already - can you be specific?
 
To be more specific, which formulas do I use to calculate the new velocities?
 
Depends on the specifics of the collision - in general you need the conservation of energy and momentum and angular momentum formulas and some geometry.

Sorry, this is not one of those things where there is a standard formula you plug numbers into. That's why you've been given all those links to look at.
 
I just want it to look realistic... I don't know what to do...

edit: I guess... an inelastic collision is realistic... so, let's go with that?
 
I'm going to help you out by turning this into a simpler problem; I did a very simple program back in the 8th grade, before I ever had any formal physics, that involved a little ball bouncing around a room under the influence of gravity.

I started with the understanding that, in the ideal case, the ball would bounce off a wall the same way light appears to bounce off of a mirror. All I had to do was take the angle of incidence and flip it across the normal of the wall. My implementation was even simpler than that; because all of my walls were either horizontal or vertical, I simply had to invert either the X or Y velocities. When I wanted to make it so that the ball slowed down, I simply reduced the final velocity by about 3% every time a collision occurred. It was a fairly convincing simulation.

Your case is slightly more difficult, but it still shouldn't be too hard to figure something out. You will, however, need to add a few more parameters to your simulation.

The problem is that, as long as total momentum before and after the collision is the same, and the total energy in the system post collision is less than or equal to the total energy before hand, then any solution to the velocity of the balls after the collision is equally valid. In other words, we need to know more about how they collide in order to determine the resulting velocities.

My initial solution, without doing any research, is to start with a change in axises; there would be some component velocity along the line between the two object's center of masses, and some component normal to that. Next, say that the radius of each ball is not fixed, but rather acts as a (spherical) spring. As the two balls collided, the ball would act like a spring as per hook's law, applying a force proportional to the change in radius, and storing some of the kinetic energy of the balls as potential energy in the springs. The springs would dissipate some of the energy that was stored in them (for example as heat). Because the springs would return less than %100(over that would result in a "Flubber" like material) of the energy stored in them, you would ensure conservation of energy, and as long as you ensured that the force acting on the balls was equal and opposite, momentum would be conserved as well. I'm sure there are easier ways out there, but this one should work.
 
  • #10
Your first step is figuring out the angles the two balls bounce off at. If at the collision you can take the velocity vector of one ball (\vec{v_1}) and a vector between the two ball centers (\vec{N}) and an angle between these two vectors (\alpha) then the angle of the new velocity vector will be (measured counter clockwise from the horizontal) 2\alpha -\vec{v_1}.
 
  • #11
I'd say, if you are not comfortable with the math and have trouble knowing how to use the information you are getting - go find a physics lib package and another program that does something like what you want. i.e. find out how other programmers did it.
 
  • #12
blarp said:
I just want it to look realistic... I don't know what to do...

edit: I guess... an inelastic collision is realistic... so, let's go with that?

My advice is to first understand the physics. Read the wiki pages. Understand what is going on. Draw pictures of colliding balls, with the old and the new vectors. Calculate for an elastic collision of two balls the velocity vectors after collision, given the velocity vectors before collision. Then reproduce the answer in your program. If you don't have an 'exact' solution, there is no way to tell if your program is correct or not.

Worry about inelastic collisions and off-center collisions in a later step.

I think the wiki pages already provide you all the information you need. The links given on the wiki page can also be helpful.
 
  • #13
What u can do is after detection of collisions, reverse the velocities. I've also seen one instance of swapping the two balls velocities... so that the faster balls velocity gets transferred over and vice versa.
 
  • #14
relion65 said:
What u can do is after detection of collisions, reverse the velocities. I've also seen one instance of swapping the two balls velocities... so that the faster balls velocity gets transferred over and vice versa.

This only works when the collisions can be considered one dimensional.
 

Similar threads

Replies
10
Views
3K
Replies
9
Views
1K
Replies
53
Views
4K
Replies
4
Views
2K
Replies
3
Views
720
Replies
32
Views
5K
Replies
9
Views
2K
Back
Top