cpArbiterTotalKE definition

Official forum for the Chipmunk2D Physics Library.
Post Reply
glyf
Posts: 4
Joined: Wed Sep 05, 2012 1:18 pm
Contact:

cpArbiterTotalKE definition

Post by glyf »

I'm trying to figure out how to approximate the severity of the collision of various balls into a static body for the purpose of assigning damage to the balls. The balls have varying friction and restitution so the values for cpArbiterTotalImpulse are inconsistent with what I'm looking for, I think. What I need is a value that would be proportional to the momentum of the ball before the collision tempered by the obliqueness of the collision.

Would cpArbiterTotalKE be appropriate here?
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpArbiterTotalKE definition

Post by slembcke »

So there are two physical laws that are interesting to know here in thinking about what you are asking for.
1) When two objects collide, their total momentum is always conserved.
2) In a closed system (like two objects colliding), energy is conserved.

So #1 tells you that if you add the momentum (mass*velocity) of two objects together before and after a collision, the sum will be the same. This is regardless of elasticity, friction, or the angle the objects hit at. #2 tells you that "energy" in a closed system is conserved, but not specifically kinetic energy. When a perfectly elastic collision occurs, no kinetic energy is lost. When inelastic collisions occur, it's because some of the kinetic energy is lost to deforming the materials and turning it into heat.

So how does that relate to Chipmunk functions? cpArbiterTotalImpulseWithFriction() gives you the impulse that was exchanged during the collision. It's the amount of momentum subtracted from one object and added to the other at all the contact points. cpArbiterTotalKE() gives you the amount of kinetic energy lost (to deformation or heat) during the impact. Remember that elasticity reduces the amount of kinetic energy lost.

So how does kinetic energy and momentum relate to damage? I actually have no idea. The kinetic energy lost is a pretty good indication of how much energy changed into "damage", but I don't think it's that simple. Faster moving objects probably cause shorter collision times, higher forces, and thus higher pressures. Smaller objects with the same kinetic energy will also produce more pressure. Is denting a can with a small rock more or less damage than piercing it with a tiny BB? I would guess the rock has many times more kinetic energy. It seems like if you wanted to, you could make this a really complicated problem. FWIW, I use kinetic energy directly as a indicator of damage.

What about static bodies?
Static bodies are sort of a physical impossibility since they have infinite mass. A "immovable object" in the real world isn't actually immovable, just very hard to move. With finite mass momentum is conserved, but when colliding with infinite mass objects it sort of disappears into the ether. Not really important in practice though, assume the static body has an infinitely small velocity after the collision so that it's conserved. ;)
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
glyf
Posts: 4
Joined: Wed Sep 05, 2012 1:18 pm
Contact:

Re: cpArbiterTotalKE definition

Post by glyf »

Thanks, that really helps me understand what's going on. Just to check I tested with all shapes having elasticity of 1, and of course the TotalKE was 0.

It makes sense also that you would use this as an indicator of damage, since as you describe the energy lost in a collision with less than perfect elasticity is really being lost to the structural integrity of the objects colliding. For my purposes though, I want to find a something that would be proportional to the momentum of the ball as it enters the collision irregardless of its elasticity since part of the object of the game is to accelerate the ball enough to cause it damage when it collides. I guess I could find this by adding the the TotalImpulseWithFriction together with the TotalKE but I'm not sure what kind of unit the TotalKE is since it seems a lot greater than the impulse. Or perhaps there is some way to simply calculate this using the TotalImpulseWithFriction and elasticity? Like if the static shape always has an elasticity of 1, and the balls have varying elasticity, would (TotalImpulse / elasticity) give an accurate value (i.e does the elasticity affect the TotalImpulse linearly)?

Thanks again I've found your explanation very illuminating.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpArbiterTotalKE definition

Post by slembcke »

So the impulses are actually instantaneous impulses so they have units of mass*velocity (same as momentum). KE is in units of energy which would be (uh... gotta think about this one, force*distance so...) mass*velocity^2. I'm not sure that's directly useful unless you want to convert that energy value to some other form of energy or something. I've always just multiplied it by a coefficient then compared it to a threshold.

Off the top of my head, I think that when you have an elasticity of 0.0 you get impulse x. When the elasticity is 1.0, the same collision would get an impulse of 2.0*x. Makes sense intuitively that way, but I'm not 100% certain the math works out. Easy to see in the simplest case of a ball hitting a wall straight on. If the elasticity is 0, the ball will stop. If the elasticity is 1.0, it will stop and bounce off with the same velocity it came in with. That's double the momentum change. Regardless of impact angle or location, that is true of the normal impulse (the part without friction) for sure. I think it might change based on if dynamic friction is exceeded though?

Going back a few steps, what seems inconsistent about the impulse for you? Like you don't get the same values for the same collisions or that it varies to to the masses of the objects? You are going to find the same issue with the kinetic energy if you use that in some way. Maybe the relative velocity of the bodies at collision time is a good enough estimation and more what you are looking for?
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
glyf
Posts: 4
Joined: Wed Sep 05, 2012 1:18 pm
Contact:

Re: cpArbiterTotalKE definition

Post by glyf »

The reason the impulse value wasn't what I wanted was that I wanted values independent of the elasticity of the colliding shapes. Since the static shape has a constant elastiticity, using your info on how elasticity affects the impulse I was able to get the value I wanted by multiplying the length of the impulse by 1/(1+elasticity) . I compensated for the mass of the ball as well. So you're right the relative velocities at collision time is more or less what I want but I found this solution easier than figuring the math for the angle of the collision.

Thanks for your help.
User avatar
slembcke
Site Admin
Posts: 4166
Joined: Tue Aug 14, 2007 7:13 pm
Contact:

Re: cpArbiterTotalKE definition

Post by slembcke »

Ok. I guess that makes sense.

Just FYI, you can get the computed elasticity the arbiter applied to the collision using cpArbiterGetElasticity(). You can also modify it in the pre-solve callback if you don't like the default way it's computed.
Can't sleep... Chipmunks will eat me...
Check out our latest projects! -> http://howlingmoonsoftware.com/wordpress/
Post Reply

Who is online

Users browsing this forum: No registered users and 5 guests