11727

Applying Coefficient of Restitution in a collision resolution method

I have a collision resolution method in my physics engine, that goes like this:

Vector2 n1pos = n1.NonLinearSpace != null ? n1.NonLinearPosition : n1.Position; Vector2 n2pos = n2.NonLinearSpace != null ? n2.NonLinearPosition : n2.Position; Vector2 posDiff = n2pos - n1pos; Vector2 posDiffNormal = posDiff; posDiffNormal.Normalize(); float totalRadius = n1.Radius + n2.Radius; float posDiffLength = posDiff.Length(); float interPenetration = totalRadius - posDiffLength; float averageRestitution = (n1.RestitutionCoefficient + n2.RestitutionCoefficient) / 2; Vector2 forceAmount = Vector2.Multiply(posDiffNormal, interPenetration); Vector2 n1force = ( (n1.Velocity * n1.Mass) + (n2.Velocity * n2.Mass) + n2.Mass * averageRestitution * (n2.Velocity - n1.Velocity) ) / (n1.Mass + n2.Mass); Vector2 n2force = ( (n1.Velocity * n1.Mass) + (n2.Velocity * n2.Mass) + n1.Mass * averageRestitution * (n2.Velocity - n1.Velocity) ) / (n1.Mass + n2.Mass); n1.ApplyForce(???); if (!n1.IsStatic) { n1.Position += ???; } n2.ApplyForce(???); if (!n2.IsStatic) { n2.Position += ???; }

Now, i can't figure out what to apply to the bodies in my engine in order to get proper coefficient of restitution working. (the ??? parts). Can someone help?

Answer1:

Judging by this and your other questions, you are trying to run before you can walk.

<ol> <li>You're trying to code several unfamiliar things at once, when you should be tackling them one at a time. Try setting the coefficient of restituion to 0, so that your objects act like lumps of putty. That'll be easier to code, and once you have that working you can try elastic collisions. <li>No offense, but trying to write a physics engine when you haven't studied basic physics is just masochistic. You can either sit down with a textbook or <strong>experiment</strong>, but there's simply no way to get the engine working without understanding its parts. </ol>

Answer2:

I realize this is an old question, but I ran into the same issue and Google turned up this page. I figured I might share my findings. First, you must realize that the coefficient of restitution is a property of the collision, not of either of the bodies involved in the collision. That is, for n objects, you need to define n(n-1)/2 coefficients of restitution (one for each pair of bodies).

However, the physics engines I have looked into (Bullet, Chipmunk, and Box2d) all define the restitution as a property of the bodies. Upon the time of the collision, they combine the two bodies' coefficients of restitution into a single value and use that in the collision resolution. Obviously, this isn't physically correct. But that doesn't matter much for games: it just needs to behave in an intuitive manner. Here are the restitution functions that those physics engines use:

    <li>Bullet: restitution = body1->restitution * body2->restitution</li> <li>Chipmunk: restitution = body1->restitution * body2->restitution</li> <li>Box2d: restitution = max(body1->restitution, body2->restitution)</li> </ul>

    Box2d allows the users to customize the restitution function in a configuration file. Bullet and Chipmunk do not.

    I recommend you select whatever restitution mixing function feels best. Just play around with it a bit and see what you like.

Recommend

  • Physics Issue When Loading SCNScene from .dae
  • Calculating distance travelled by a b2body before it stops in Box2D
  • how to insert new data in an embedded document in MongoDB
  • Whats the best way to do character animations with Box2D?
  • Data Cleanup, post conversion from ALLCAPS to Title Case
  • init method of a Serlvet without ServletException
  • TCP HL7 message has .(period) as segment terminator
  • SKSpriteKit maintaining constant velocity after collision
  • Serialize JSON array from a web request
  • ES6 imports in Node with --experimental-modules
  • Out of memory when using `outer` in solving my big normal equation for least squares estimation
  • Can't update Label from other class in Swift
  • How to solve symbolic equation with double coefficients in matlab?
  • Plot: color all larger than different color
  • Generating binary lists that sum to a given number
  • Django Admin wont allow me to allocate permissions to Users or Groups
  • python regex [:alpha:]
  • Simulate keypress in java to write user inputs to another application
  • Efficient random permutation of n-set-bits
  • Model to match this JSON for deserialization, field names with dashes
  • RegularExpressionValidator With DropDownList(asp.net)
  • FLAG_ACTIVITY_REORDER_TO_FRONT and startActivityForResult
  • Filter Values of Current Week with XQuery
  • C++ mySQL connector LINKER errors (Windows)
  • Entity Framework Core: Include many-to-many related objects in WebAPI
  • Invalid Date on validation Date of js
  • error importing numpy
  • How integrated is Collada to OpenGL ES
  • Breeze - Deleted Items nav properties bug
  • javaw.exe and eclipse startup problems
  • Javascript Callbacks with Object constructor
  • Return words with double consecutive letters
  • Proper folder structure for lots of source files
  • Rails 2: use form_for to build a form covering multiple objects of the same class
  • Hits per day in Google Big Query
  • need help with bizarre java.net.HttpURLConnection behavior
  • File not found error Google Drive API
  • Is there any way to bind data to data.frame by some index?
  • How can I use `wmic` in a Windows PE script?
  • Converting MP3 duration time