Colliding balls.

Started by
12 comments, last by marinka 22 years ago
Two ideal balls move atop of an ideal horizontal plane. Their weights are m1 and m2, and velocities are V1x, V1y, and V2x, V2y. When they collide, the coordinates of their centers are X1, Y1, and X2, Y2. What are their velocities (Vx and Vy) after the elastic collision? I am making a game where balls move. And I want to set their Vx and Vy correctly after they collide, so a player gets the feeling of a real movement. I never thought in high school I would ever need physics in my life. Oh, how wrong was that thought.. Now I am trying to recall how we had this solved, and all what comes to my mind is the need to apply the momentum conservation law for both axises X and Y, and the kinetic energy conservation law. This gives me three equations, but I can't find four unknowns from these three equations only. So I guess I need aditional equation which probably uses coordinates of the balls' centers. Or maybe there is a more simple way ? Thanks for any help. ------------------------------ msn: pamelinka@hotmail.com icq: 115592659 [edited by - marinka on April 17, 2002 10:35:55 AM]
Advertisement
I think you will also need the radii of the balls.
[ PGD - The Home of Pascal Game Development! ] [ Help GameDev.net fight cancer ]
Well, I am not sure I need radii of the balls because the direction of the collision goes through the centers of the balls, and I can calculate this direction without any info about the radii.
These radii are always available and accessible to me though, so if you can help me using them, it''s ok, and I will appriciate that very much

Thank you for replying to my question.
In 1D, without friction, this is a classic collision problem. You have

p = mv (p is a vector)
pA'' + pB'' = pA + pB

For elastic collisions,
1/2 (mA * vA'' ^ 2 + mB * vB'' ^ 2) = 1/2 (mA * vA ^ 2 + mB * vB ^ 2)

For perfectly inelastic collisions,
vA'' = vB'' (again, vA and vB are vectors)

You have only two unknowns, so you can solve this system in 1D. If you need solutions for 2D or 3D, ask again (without pressing enter after every line ).

Cédric
Look at Pool hall lessons at Gamasutra (signup is free), which probably will inspire you...

edit: fixed that link... sheesh.


2D when? 2D!Now

[edited by - llyod on April 16, 2002 10:16:37 PM]
Hi, Cédric. Thank you for giving me the solution for my problem in one dimension.
I wish my game were in 1D, so everything would be that simple.
Unfortunately, in 2D or 3D the problem is a bit more complicated.
Let''s take 2D for example. We have 4 unknowns which are the velocities of two balls after the collision (ball1: Vx and Vy, and ball2: Vx and Vy).
But I have already said that using only the impulse conservation law for X and Y
X: (pA'' + pB'' = pA + pB)
Y: (pA'' + pB'' = pA + pB)
and the kinetic energy conservation law for elastic collision
1/2 (mA * vA'' ^ 2 + mB * vB'' ^ 2) = 1/2 (mA * vA ^ 2 + mB * vB ^ 2)
gives us a system of only three equations which is not enough to find four unknowns.
That''s why I thought I would need one more equation that probably uses the coordinates of centers of the balls.

Well, the question stays open, and it is now without "Enters" after every line.
Well, my physics teacher told me that the solution is not well-defined when you have 2 or 3 dimensions. The approximation I'm proposing looks convincing enough, and I know someone said the same thing in another thread a while ago. Basically, the idea is to modify the linear momentum p along the normal of the impact plane. It's more or less similar to Gamasutra's feature Pool Hall Lessons.

P is the point of impact
CA and CB are the centers of the spheres
N is the normal of the impact plane
dp is the variation of linear momentum (scalar)

All equations are vectorial

For spheres,
N = Normalize(P - CA) = Normalize(-(P - CB))

pA' = pA + dp * N
pB' = pB - dp * N
Note that linear momentum is preserved.

Now, the only real unknown is dp, which is a scalar, so you can solve by adding another constraint. We can use the same ones we used for 1D collisions, although we have to extend them a little bit.

For elastic collisions, the conservation of energy is still valid. However, there is an added twist: in 1D,
vA' = vA + dp / mA
However, in 2D or 3D, this is not true anymore, since the variation of p is parallel to the normal of the impact, so you have to use the law of the cosines, to find that the "elastic" dp, dpE is (I won't demonstrate the whole thing, but it worked in my program)
cosA = Dot(vA, N) / |vA|
cosB = Dot(vB, N) / |vB|
dpE = 2 * (vA * cosA + vB * cosB) / (1 / mA + 1 / mB)

For inelastic collisions, you can't say that the objects stay "glued" together, as it was the case in 1D, so you can say that the final speed of the objects, perpendicularly to N is the same for both objects:
Dot(vA', N) = Dot(vB', N)
Ultimately, this will give you an "inelastic dp" dpI of
dpI = |Dot(vA - vB, N)| / (1 / mA + 1 / mB)

Finally, I use a linear equation to find the final dp:
dp = dpI + k * (dpE - dpI)

You can derive all the equations yourself; it's not that hard, but it still took me a couple of months to find this method as a whole(there's probably something much better in books, but it wouldn't have been as fun ). I wanted to write an article on Gamedev.net covering this in more detail, including non-spherical objects (with rotations and everything), but I didn't get a whole lot of positive feedback, so I dropped the idea. I'm still going to keep this explanation, as it might serve again, so don't believe I wrote all this just for you )

Critic is welcome,

Cédric

[edited by - cedricl on April 16, 2002 7:50:38 PM]

[edited by - cedricl on April 16, 2002 7:56:45 PM]
{Vlion: inf >=feedback >= 0}


Bugle4d
~V'lionBugle4d
The demonstatrion allows to have a general formula to deal with all kind of chocs (elastic and inelastic), with even a law different from Descartes reflection law (used with ball...). there''s no need to implement the whole formula for balls, but it''s just to bring a precision... The demonstration uses a vectorial basis changing. If you are in the center of mass basis, the linear momentum equation and the energy conservation is very simplified... It leads to a formula that gives the relation between initial kinetic energy and final kinetic energy, with a parameter, the deviation angle. With Kinetic energy variation you have the linear momentum variation (and the final speed value). You need a law to describe reflection conditions (Descarte reflection law for balls or ray of light on a mirror...) or more complex one if you want. The inelastic hypotethis acts on energy conservation with an accumulation term, wich allows to easily implement balls deformation... equations are easy to code, and are not that complicated, as Cedricl perfectly described them for balls...
This is used in Nuclear Physics (and elsewhere...) and you could acces such a demonstration in all good books of physics(mechanic or nuclear sciences).
Hi, Cédric.
You presented a very interesting idea on how this problem could be solved, and I have a couple of comments and questions about it.

First of all I can't agree with the physics teacher who says that the solution is not well defined in 2D and 3D, or that there is the need to use approximation. I am certain that the precise values of unknowns in this problem CAN be found, and that only one version of these values exists for a given set of initial parameters of the problem. I believe in that because of two facts:
1) We have ALL data about the moving objects before the collision.
2) The collision is governed by clearly defined laws of physics.
So why wouldn't the solution be well defined ?

I have carifully read your demonstration but I am not sure I fully understand everything. It is probably because our teachers used different terms to describe the same concepts.
It was a great idea to present the conservation of momentum in this way:
pA' = pA + dp * N
pB' = pB -dp * N
but I didn't get the technique you used to find dp for elastic collision
(what is Dot(), where V is vector, and where it is scalar, and so on..).
By the way, we don't have to use cosine to find projection of one vector onto another,
we can use the scalar product of vectors instead.
For example, if we have two vectors: V(Vx, Vy) and N(Nx, Ny) and we need to find the projection of V onto N (let's call it VN), then the length of VN is defined as (Vx * Nx + Vy * Ny) / Length(N)

Anyway I offer to take a simple but concrete example, and to use the best common language: hard-numbered equations based on laws to define a clear solution.

The simpliest example could be a 2D case with equal balls' masses (m1 = m2) and completely elastic collision.
So we have a horizontal plane XY
^ Y
|
|
|
| 0
|---------------> X
and two balls which move on it and collide.
Their velocities before the collision are
ball1: V1x, V1y
ball2: V2x, V2y
When they collide their centers are at points ball1(X1, Y1) and ball2(X2, Y2).
The question is what the velocities of these balls after the collision are ?
I mean the projections of their velocities onto axises X and Y. Let's call these unknown velocities like that
for ball1: V'1x, V'1y
for ball2: V'2x, V'2y

So the given data are
(X1, X2), (Y1, Y2), V1x, V1y, V2x, V2y,
and the unknowns are
V'1x, V'1y, V'2x, V'2y
---------------------------------------------------------------------------
Who dares to solve this?



------------------------------
msn: pamelinka@hotmail.com
icq: 115592659



[edited by - marinka on April 17, 2002 2:28:39 PM]

This topic is closed to new replies.

Advertisement