Large energy gain on object collision

Please don't post Bullet support questions here, use the above forums instead.
arcoraven
Posts: 8
Joined: Sun Jun 13, 2010 3:33 am

Large energy gain on object collision

Post by arcoraven »

I've been implementing my own rigid body physics: an iterative, discrete timestepping method as described in the Guendelman paper. I've tweaked it a bunch after reading up on a ton of white papers (Baraff, Catto, Mirtich, Erleben) and code demos (Box2D Lite).

Here's my problem: when an object collides with another object, I'm currently using the separating axis theorem to find the minimal translational distance to use as the collision normal. I then find the deepest interpenetrating points on each object along that collision normal. This leaves me with an array of collision points. If there are > 2 points, it has collided on a face, and I run a 2D convex hull to find only the outer-most set of collision points. I then apply the impulse formula to each contact point to update the linear/angular velocities.

The result is visually plausible for cubes and spheres with < 4 collision points, but when I get to dense meshes like cylinders with 8-20 collision points, the impulses all add up and "reflect" the velocity way too much. The more collision points, the more energy gain. However, when the cylinder is knocked on its side so that it collides only with 4 collision points, the simulation runs more normally. I'm able to get cubes, spheres, and simple meshes to come to rest. Objects like toruses and cylinders, with faces that have many contact points,

Am I correct in applying the same impulse to all the collision points? When I apply it only to the average collision point, energy dies out very fast (as if every object had a trivial restitution value).

Also, another question: where should the collision points be on a discrete solver? If object A and object B interpenetrate, I'm currently finding the collision point on A and offsetting it halfway toward B along the collision normal.

Any help is greatly appreciated.
User avatar
Dennis
Posts: 12
Joined: Sat Jun 23, 2007 9:13 pm
Location: San Francisco

Re: Large energy gain on object collision

Post by Dennis »

The most common way is to solve each contact point in isolation, and after each point, apply the impulses before considering the next. This is called sequential impulses (SI). Hence, you should NOT apply the same impulses to all points, but for each point you should apply the same, but opposite direction, impulse to both objects.

For you other question, half way between A and B works just fine. I personally prefer to apply one impulse at A and the other at B, though it shouldn't make a big difference if interpenetration/separation is small.

Hope this helps.

Dennis
arcoraven
Posts: 8
Joined: Sun Jun 13, 2010 3:33 am

Re: Large energy gain on object collision

Post by arcoraven »

Thanks. I'm currently implementing that "aggressive optimization" mentioned in the Guendelman paper, i.e. after finding all the collision points in one collision iteration, compute the impulse for each point separately and apply it at that point. So yes, I am using different impulses for each contact point (because obviously the relative normal velocity is different at each point). Once all the impulses have been applied and velocities updated, I reset the positions, re-integrate positions with the updated velocities, and re-run collision detection to see if another collision call is needed.

Since the impulse equation depends on linear and angular velocities, I'm currently storing a copy of the velocities BEFORE applying impulses, and using these stored copies to compute the relative velocities. Am I correct in doing this? Or are you suggesting that after applying each impulse, I should compute the relative velocity of the next collision point using the newly updated linear/angular velocities?

I thought I was implementing the sequential impulses method correctly, but perhaps I am missing something. Thanks again for your help.
User avatar
Dennis
Posts: 12
Joined: Sat Jun 23, 2007 9:13 pm
Location: San Francisco

Re: Large energy gain on object collision

Post by Dennis »

That's right, just update the relative velocity before you solve the next point, and you should be fine. The solver you describe is more similar to a Jacobi solver. I have tried that approach too and it works if you scale each impulse by (1/numberOfContactsInTheManifold), but it converges slower than the SI (Gauss-Seidel) method. Good luck!
arcoraven
Posts: 8
Joined: Sun Jun 13, 2010 3:33 am

Re: Large energy gain on object collision

Post by arcoraven »

Thanks, after tweaking around with using the updated relative velocities, the impulses are as strong as I expect now.

A new problem, though:
A resting box does nothing in the collision resolution step and gains velocity in the -y direction (from gravity), as expected. The contact resolution step, however, doesn't exactly "cancel out" this velocity. The result is that the resting box starts out jittering a little before coming to rest.

I'm guessing it's probably due to the "aggressive optimization" in the collision function. Is the contact resolution step supposed to apply an impulse to ONE collision point, then repeat the entire collision detection step? This seems particularly slow.

Also, when determining collision points to apply impulses to in the collision resolution step, are the DEEPEST INTERPENETRATING points the only ones I need to look at? Or should I be taking into account ALL points that are interpenetrating, and then apply impulses in order of deepest -> shallowest interpenetration?

Thanks again. My sim is slowly coming along.