Block Solver
Box2D now implements a block solver for normal contact. If the contact manifold consists of two points, then the 2-by-2 MLCP is solved directly through enumeration. For small systems enumeration is easy to implement:
- Assume both constraints are active and solve the 2-by-2 equality problem. If both contact forces are positive then we are done.
- Assume contact 1 is active and contact 2 is inactive. Solve for contact force 1. If contact force 1 is positive and contact velocity 2 is non-negative then we are done.
- Same as step 2 except reversed.
- Set contact force 1 and 2 to zero.
Dirk Gregorius originally implemented this in Box2D_Lite in Jan. 07. I devised a scheme to make it work with accumlated impulses so that each block solve considers the total impulse applied over the step. Recently I ported this to Box2D 2.0.
The result is quite good and Box2D is now able to stack 24 boxes vertically without difficultly (1m cubes, 60Hz, 10 iterations, gravity = 10m/s^2). The behavior is similar to sphere stacking.
One additional contribution: you need to check the condition number of the block to avoid numerical problems. In the 2-by-2 case this is simple. If the condition number is too large then Box2D will ignore the second contact (because the constraints are somehow redundant).
September 14th, 2008 at 7:10 am
Dear Erin!
I’m not an expert on dynamics simulation, but the numbers presented here (24) surprises me:
*Isn’t the number of boxes dependent on their shape (wide boxes would stack better in my mind)?
*Isn’t 24 a rather small number, at least if it’s a revamped best effort? Glaze (http://home.planet.nl/~borst595/glaze.html) seems to be able to stack 50 layers (demo 3, “Slat Stack”) and Phyz (http://phyz.ath.cx) has a 128-layer demo which is perfectly stable (”stack128.pzs” from the “Scenes and models” page).
Kind regards
Lars Bengtsson
Sweden
September 14th, 2008 at 4:12 pm
Hi Lars,
As I stated, the cubes are 1m on each side.
A single vertical stack is more difficult to stabilize than a pyramid.
The previous revision of the Box2D solver could only handle a vertical stack of around 11 boxes with the same simulation specifications. So yeah, this is a big improvement for Box2D. I’m not saying that Box2D is the best engine for stacking, just that it has improved.