Sign in to follow this  

Resting Contact in Rigid Body Simulation

This topic is 3415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am trying to create a physics simulation where a number of balls bounce inside the 6 planes of a box. I have implemented the Rigid Body system described in Chris Heckers articles but he does not cover resting contact. Some siggraph papers show how to calculate resting contact but it involves using complex Quadratic Programming. Is there a simple and fast way to implement resting contact between 40-50 spheres of different radius and mass. Thanks in advance, Steve

Share this post


Link to post
Share on other sites
Hi Steve,

The simplest method to get your head around IMHO is the sequential impulse method as used in Box2D (for 2D) or the Bullet physics library (for 3D).

This paper will give you a good intro...

http://www.gphysics.com/files/IterativeDynamics.pdf

More info also on this page.

And full source is available for both Box2D and Bullet, so you can see actual implementations.

Edit: Just wanted to clarify, to avoid confusion that the IterativeDynamics paper linked above (from 2005) describes a method (PGS) that is equivent to, but not quite the same as the sequential impulse method. See Erin's Box2D source and site for more details of the differences.

[Edited by - WillC on August 10, 2008 12:07:40 PM]

Share this post


Link to post
Share on other sites
yes thanks for that information I will check it out. I am learning a lot of the math as I go. But some of it seams painfully complex. I thought there would be simpler ways to implement resting contact.

Share this post


Link to post
Share on other sites
Unfortunately it does get pretty tricky, as you need to find a global solution to a large number of simultaneous contact equations. In other words you need to find a set of forces that works for not just one pair of objects, but all the possible combinations of touching objects at the same time.

Using traditional techniques, and ignoring friction, this involves solving a big system of equations in matrix form. Add friction, and it becomes a Linear Complimentary Problem (LCP), which is harder and more error prone to solve (sometimes with no solution).

The beauty of the Sequential Impulse method is that it avoids the slow and error prone 'solve big matrix' issues by working on pairs of objects one at a time iteratively, in such a way that you gradually (over a number of iterations) calculate a force that gets closer and closer to the required global solution.

Share this post


Link to post
Share on other sites
I have had chance to read the GDC presentation relating to the “Sequential Impulse” method for handling contacts. I have also examined the Box2DLite source code, and I think that this technique is extremely cool and easy to understand. I need to use this method in a 3D environment where the rigid bodies will only consist of planes and spheres. Will this technique work for spheres or will I have to approximate the bounds of a sphere using a bounding box? I’m not sure how I would handle contacts as the collision detection/response relies on finding a separating plane between the rigid bodies, its intuitive to see how this works with bounding boxes but is this possible on a sphere?

Thanks,

Steve

Share this post


Link to post
Share on other sites
Yes you can use the same techniques with spheres. In fact it should be easier than dealing with boxes.

Two spheres are colliding if the distance between their centre points is less than or equal to the sum of their radii, and the point of contact will lie on the line joining the two centre points. Try drawing two different sized circles on a piece of paper so they are just touching and then draw a line between their centre points.

Similarly, a sphere is touching a plane if the distance from the plane to the sphere centre is less than or equal to the radius.

Spheres and planes are a great starting point for learning collision detection, as they are the easiest to deal with. Most importantly they only ever have one point of contact between each pair of objects. As soon as you start moving up to boxes or other more complex shapes, then you have to deal with potentially multiple contact points per pair, and worry about vertices, edges and faces.

The Box2DLite code only deals with box shapes, but the Box2D (non-lite version) code has circle collision primitives as well, and if you’re brave enough to delve into the Bullet source code than that has sphere collision primitives to play with.

Share this post


Link to post
Share on other sites
Thanks for the previous post it seams obvious now you have explained it. I have just been poking around inside the source code of Box2DLite and am confused with some code in the PreStep member function of Arbiter. The code calculates a normal mass and tangent mass. I am trying to create a 3D version of this function but I do not fully understand what it does and how it works. What does a normal mass mean and how does the calculation work?

for (int i = 0; i < numContacts; ++i)
{
Contact* c = contacts + i;
Vec2 r1 = c->position - body1->position;
Vec2 r2 = c->position - body2->position;

// Precompute normal mass, tangent mass, and bias.
float rn1 = Dot(r1, c->normal);
float rn2 = Dot(r2, c->normal);
float kNormal = body1->invMass + body2->invMass;
kNormal += body1->invI * (Dot(r1, r1) - rn1 * rn1) + body2->invI * (Dot(r2, r2) - rn2 * rn2);
c->massNormal = 1.0f / kNormal;
}

Thanks for all your help so far it has really helped.

Steve

Share this post


Link to post
Share on other sites

This topic is 3415 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this