# How are penetration forces calculated in PhysX 4 and 5 for rigid bodies?

I read the documentation and could not find the formulas for force calculation. I could only find the following information at the Advanced Collision Detection section of the docs:

The generation of contact points does not however mean that a large impulse will immediately be applied at these locations to separate the shapes, or to even prevent further motion in the direction of penetration. This would make the simulation jitter unless the simulation time step is selected to be tiny, which is not desirable for real time performance. Instead, we want the force at the contact to smoothly increase as penetration increases until it reaches a value sufficiently high to stop any further penetrating motion. The distance at which this maximum force is reached is the restDistance, because at this distance two shapes stacked on each other will reach static equilibrium and come to rest. When the shapes are for some reason pushed together so much that they have a distance below restDistacnce, an even greater force is applied to push them apart until they are at restDistance again. The variation of force applied as the distance changes is not necessarily linear, but it is smooth and continuous which results in a pleasing simulation even at large time steps.

I would like to find a formula for such forces.

• Is the formula of calculation of the forces exerted by objects that are pushed apart available?
• Is it the same formula used by simulated force/torque sensors?
• Are calculations for PhysX 4 and 5 performed in the same manner for penetrating rigid bodies?

The purpose of these questions is to evaluate manipulation experiments with robotic grippers. Interactions between the gripper and grabbed objects are usually difficult to approximate to the real world.

1 Like

The details vary slightly depending on whether we are simulating rigid bodies or articulations, but the approach is mathematically equivalent.

The force acting between bodies when colliding is governed by the rigid body impulse equation, which is proportional to the relative velocity of the bodies at the contact point and properties like the effective mass of the bodies at the point of contact and the restitution value.

The effective mass of the bodies can be expressed in a simple closed form for rigid bodies, but it isn’t available in closed form for articulations. Instead, it’s a function of the set of bodies in the articulation. For reference, for a simple rigid body/single link articulation, the effective mass of a pair of bodies at a particular contact is given by 1/(invM1 + invM2 + (r1 x n)^T * invI1 * (r1 x n) + (r2 x n)^T * invI2 * (r2 x n)), where n = normal, r1 and r2 are the offset from COM to the contact WRT each body.

There is a pretty good discussion of the basic theory here: http://www.chrishecker.com/images/e/e7/Gdmphys3.pdf

In addition to the velocity terms, there is an error corrective Baumgarte stabilization term commonly added to correct drift (in this case penetrations) to add in some extra force to correct errors. This adds an additional bias to the velocity term used to compute the impulse response - effectively error * baumgarte* 1/dt, where baumgarte is a value in the range [0,1]. This is internally computed and its value is fixed (0.8) in PhysX 4 and adaptive in PhysX 5.

PhysX operates using both position and velocity iterations in its solver. These names are a bit misleading as both approaches are solving constraints on the velocity level using the exact same formula. The difference is that position iterations include the bias term and velocity iterations do not (so baumgarte becomes 0 with velocity iterations). PhysX first runs the position iterations to calculate the velocity that is used to integrate pose in the frame, then it runs velocity iterations afterwards to compute the velocity that will be carried over to subsequent frames. The forces reported by the simulation are those produced after all position and velocity iterations, with the intention being that the fictitious forces added to correct any simulation error due to discrete time-stepping/solvers not fully converging are removed before reporting something that closely approximates the expected forces. In practice, this is best effort and, if insufficient iterations are provided, the forces reported can still contain some forces caused by error correction.

Is the same formula used by simulated force/torque sensors? The sensors are capturing the aggregated forces acting on the links in an articulation. As a result, they are recording the same forces. They report the final forces, as the solver is allowed to apply both positive and negative contact forces each iteration, provided the total force applied at a contact remains positive. It’s also possible to get the contact forces acting on each individual contact.

The approach for PhysX 4 and PhysX 5 are similar. With the PGS solver, things are relatively unchanged between PhysX 4 and 5, although the articulation model was improved quite a bit. With the TGS solver, there have been quite a number of changes that improve solver convergence and stability. The underlying formulas, however, remain the same and both approaches would converge on the same results if the solver was run an unbounded number of iterations.