🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Simultaneous collisions

Started by
12 comments, last by arnero 4 years, 5 months ago

My understanding of physics is pretty weak these days, and I am trying to understand what should happen in simple 2d simultaneous elastic collisions of objects in a few toy theoretical cases (ignoring things like real world back and forth micro collisions, spin etc):

1) Object A hits an immovable wall W, as object B hits A, and as object C hits B

W C

| |

A – B

2) Object A hits an immovable wall W, as object B hits A, and as object C hits A

W C

| /

A – B

I vaguely remember something about not being able to use conservation of momentum/energy for more than two objects without additional restrictions as you end up with not enough equations with respect to the number of unknowns.

In case (1) as it is a chain of instantaneous collisions is it somehow correct to reflect the momentum of A off W, then use momentum conservation to pairwise solve between the modified A and B, and then B and C?

Case (2) I am not really sure of at all. Also I don't know if it makes sense to somehow think of the moving objects as one composite object at the instant of collisions with their composite momentum against the wall, then somehow redistribute that reflected off the wall composite momentum back among the objects?

As there isn't such a thing as an immovable wall, then I think I have to model the wall collision as the wall applying an instant force to the colliding object. Where the force is calculated pretending the colliding object has zero mass (so the wall doesn't get the tiny movement in reality it should), using the pairwise momentum/kinetic energy formulas.

Advertisement

Various physics engines handle them differently.

Having each object respond in turn is risky since it allows for infinite chains when objects are trapped, such as a bunch of objects dropped into a bag. You could have C hit B, then B hits A, then A hits the wall, then the wall pushes back on A, which pushes back on B, which pushes back on C. But if you go that route, you'll need a way to stop chain reactions such as a count of collision depths.

Another option is to process each item once and accumulate a collection of collision events that need a response. Then process each response once. If one object shoves back against another it can wait until the next pass.

Actually, I more mean how to determine what should be the reference behaviour to be tested against. So for example in case (1) above:

W C

| |

A – B

Say the velocities in the simultaneous collision are:

vA = (0, 1)

vB = (-1, 0)

vC = (0, -1)

And say they all have a mass of 2. What should their velocities be after such a simultaneous collision?

In the scenario stated, if it wasn't for a collision from B, A should perfectly bounce off the wall W with a velocity (0, -1), by ‘inventing’ a reaction force strong enough to do that, so that the wall doesn't move at all (not physically correct I know).

So perhaps that would give the intermediate state from which momentum then needs to be conserved:

vA = (0, -1)

vB = (-1, 0)

vC = (0, -1)

I thought we may be able to start from Newtons axioms (you already mention them). And use more intensive values. I get that extensive values like energy, momentum are quite useful for a lot of calculations, but are they not derived from integrating the Newton axioms? For multiple collisions I feel the need to define elastic constants for the bodies. They are so stiff that all spring action happens within one time-step for the coarse calculation, but we do a bullet time calculation for all contact points. Only calculate the time while the contact exists? Or do adaptive steps while the force does not change significantly (for stacking).

Conservation of momentum:

mA * v0A + mB * v0B + mC * v0C = mA * v1A + mB * v1B + mC * v1C

Conservation of kinetic energy:

0.5 * mA * (v0A)^2 + 0.5 * mB * (v0B)^2 + 0.5 * mC * (v0C)^2 = 0.5 * mA * (v1A)^2 + 0.5 * mB * (v1B)^2 + 0.5 * mC * (v1C)^2

Three unknowns v1A, v1B & v1C but only two equations (For only two bodies that's easily solvable). So there does need to be some other additional constraint. But I am not sure whether it should be based on collision time/elasticity, zero impulse or geometric in nature (Non rotating hard elastic circles/squares in this theoretical case for example).

I guess I am struggling a bit to intuitively imagine why that must suddenly be introduced for a third body too. Then there is the momentum change caused by the 'idealistic wall' that I think should be applied before trying to work from the equations of conservation, evaluating at the time the contacts all exist for an instant.

Actually I wonder if this case is restricted such that there is only one contact between any two objects like in my examples, that's actually enough of a constraint for it to suddenly be solvable?

Which if so would seem to imply that the extra constraint is needed for geometric reasons. Because disregarding the wall for a moment, in the two body case there can only be one point of collision between the bodies, but for three bodies there could be an ambiguous amount without further describing the geometric situation further somehow?

There are basically two ways to go at this. One is to treat collisions as spring-like events. That's more accurate and looks better, but it's hard to do in fixed time. You have to cut the time step way down as objects come into contact, or you get huge errors and things fly off into space. (Some early games with physics did that. See the old Game Developer postmortem of Trespasser.) Engineering work and some cinematic animation are done that way, but games usually don't do it that way. Here's what that looks like, from a demo I made back in 1997.

Games usually solve multiple collisions to figure out what the end result would be after the collision. Look up “linear complementarity problem” for how this is done. That can be done in roughly constant time. It suffers from the “boink” problem - all colliding objects change direction in zero time, which is fine for bullets but looks bad for large objects. This is how most game engines do it today.

As Nagle says - simulating collisions as springs will give you accurate results, but if your timestep is small enough to resolve these finite duration events, then the computational overhead will be impractical for games.

Normally objects are treated as rigid objects, so that collisions are impulsive - i.e. they happen instantaneously. That means in a game simulation, that is supposed to represent/be an approximation of the real world (i.e. don't worry about approximating artificial situations), simultaneous collisions don't really exist. They may happen within the same simulation step, but that doesn't mean they're actually at the same time. What this means is that if you process the collision pairs one by one, in any order, using Newton's restitution law (which only applies to pairs of bodies), you will get a plausible result. It will be approximate - but anything a rigid body simulation produces is an approximation, and you can improve the approximation by iterating through that collision pair list multiple times. At some point you can simply give up and go onto processing any remaining contacts as simultaneous resting contacts.

This will allow you to simulate things like a Newton's cradle, where you do actually get simultaneous collisions as the shock propagates through.

If you try to solve all the collisions (as opposed to resting contacts) in the system simultaneously using an LCP solver (either iterative or exact), then the result will actually be wrong. For example, using ODE (which is great, but does collisions wrong!), using a tiny timestep, then a Newton's Cradle looks like this:

Each individual collision is “correct” according to Newton's law of restitution - but it just shows you can't use this law to process simultaneous collisions with more than two bodies. Btw - the result is the same whether you use the Dantzig or Quickstep solver (with lots of iterations) - the problem here is that the conversion from physics into maths is incorrect.

To my surprise, I get the same (incorrect) result in PhysX - though less “perfect” because it is generally a much more approximate solver. I had expected PhysX to do a pass over collisions prior to solving contacts, thus contradicting Nagle's last comment, but that doesn't appear to be the case!

Most are seemingly jumping directly into ‘how game engines implement this’ which if you re-read what I was asking, isn't quite what I was after. What I am asking may be a bit nonsensical, but in some ways that's what I am trying to convince myself to accept :-)

For example I gave a situation with explicitly known velocities of 3 interacting bodies and a wall defined to be interacting at an instant simultaneously (Sorta a simplified 3 body newtons cradle). How would you work that ‘on paper’ so that you have a result to test an implementation against? If it helps, how could you unit test the simultaneous collision examples I gave?

Or is it a mathematically ill defined problem without bringing in the concept of springs or some other type of additional constraint? Is there a way to do it keeping the rules of the universe completely rigid, without introducing springs, perhaps using a constraint that defines the shape of rigid things geometrically? (Also I pondered if constraining to allow only one contact per object pair is enough to make it fall into being exactly solvable).

So Mr Rowl's comments are much more relevant. Discussions of this seemingly subtle area, seem to me at least, to get glossed over a little:

“If you try to solve all the collisions (as opposed to resting contacts) in the system simultaneously using an LCP solver (either iterative or exact), then the result will actually be wrong

Each individual collision is “correct” according to Newton's law of restitution - but it just shows you can't use this law to process simultaneous collisions with more than two bodies. Btw - the result is the same whether you use the Dantzig or Quickstep solver (with lots of iterations) - the problem here is that the conversion from physics into maths is incorrect.”

These are interesting, but I am not sure they are correct(!):

https://stackoverflow.com/questions/16423466/how-to-handle-multiple-simultaneous-elastic-collisions

https://physics.stackexchange.com/questions/173596/is-this-solveable-simultaneous-elastic-collision-of-4-objects-in-xy-plane

https://physics.stackexchange.com/questions/64130/how-multiple-objects-in-contact-are-resolved-in-an-inelastic-collision-when-edg/91069#91069

This topic is closed to new replies.

Advertisement