Calculating new velocities after ball collision

In summary, You are making a physics mini game and you would like your help on calculating new velocities after ball collisions.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 Newtonsian 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.
  • #1
blarp
5
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
  • #2
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.
 
  • #3
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.
 
  • #4
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?
 
  • #5
You have received quite a lot of help already - can you be specific?
 
  • #6
To be more specific, which formulas do I use to calculate the new velocities?
 
  • #7
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.
 
  • #8
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?
 
  • #9
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 ([itex]\vec{v_1}[/itex]) and a vector between the two ball centers ([itex]\vec{N}[/itex]) and an angle between these two vectors ([itex]\alpha[/itex]) then the angle of the new velocity vector will be (measured counter clockwise from the horizontal) [itex] 2\alpha -\vec{v_1} [/itex].
 
  • #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.
 

1. How do you calculate the new velocities after a ball collision?

The new velocities after a ball collision can be calculated using the conservation of momentum and energy equations. The momentum of each ball before and after the collision must be equal, and the sum of kinetic energy before the collision must be equal to the sum of kinetic energy after the collision. Solving these equations will give you the new velocities of the balls.

2. What variables are needed to calculate new velocities after a ball collision?

The variables needed to calculate the new velocities after a ball collision include the masses of the balls, the initial velocities of the balls, and the coefficient of restitution, which represents the elasticity of the collision. The angle of collision may also be needed if the collision is not head-on.

3. Can the new velocities after a ball collision be negative?

Yes, the new velocities after a ball collision can be negative. This means that the ball is moving in the opposite direction compared to its initial velocity. For example, if a ball is moving to the right before the collision with a velocity of +10 m/s and after the collision, it has a new velocity of -5 m/s, it means that the ball is now moving to the left.

4. How does the coefficient of restitution affect the new velocities after a ball collision?

The coefficient of restitution (e) determines the elasticity of the collision. A higher value of e means that the collision is more elastic, and the balls will bounce off each other with greater speed. A lower value of e means that the collision is less elastic, and the balls will stick together after the collision with less speed.

5. Are there any exceptions to using the conservation of momentum and energy equations to calculate new velocities after a ball collision?

Yes, there are some exceptions where the conservation of momentum and energy equations may not be applicable. These include cases where external forces, such as friction or air resistance, are present during the collision. In these cases, more complex equations may need to be used to calculate the new velocities.

Similar threads

Replies
14
Views
1K
  • Mechanics
Replies
10
Views
2K
  • Mechanics
Replies
9
Views
1K
  • Mechanics
2
Replies
53
Views
2K
Replies
9
Views
1K
Replies
5
Views
2K
Replies
4
Views
2K
Replies
1
Views
774
Replies
4
Views
905
Back
Top