The Pendulum Challenge
Matthias Müller, Nvidia
This simulation shows that extended position based dynamics (XPBD) is a strong competitor to state of the art simulation methods in terms of accuracy, stability, speed and simplicity. To understand why and how to use the demo see the text below..
This pendulum simulation shows single step XPBD in action. Two small modifications in our original position based dynamics method PBD turns the latter from a toy used in games into a serious competitor of physical simulation methods even surpassing their accuracy while staying as simple as PBD. We describe the method here. The pendulum simulation showcases the following features: It handles stiff systems with large mass ratios. (Zero compliance means infinite stiffness). It shows high frequency details and a high level of energy conservation both of which are difficult to achieve with implicit global solvers. All quantities have physical units and internal forces can easily be evaluated. It removes the conceptual differences of PBD to the backward Euler method. It also generalizes beyond the distance constraints we show here.
The challenge is to beat our method in terms of simplicity, speed, stability or accuracy. The html document you see here is self-contained. It includes the GUI, the rendering and the complete simulation code. You can have a look at it here. The solver itself only takes 100 lines of code (lines 460-560) which you can simply replace it with your own solution.
- The triple pendulum
The demo starts with a triple pendulum. The reason is that there are quite a few double pendulum simulations on the web. While their reduced coordinates formulation is reasonable complex, the equations for the triple pendulum cover an entire page. Although our method conserves energy quite well, the simulation comes to a stop eventually. If you want to look at it forever, turn on "Enforce energy conservation". I do not recommend to use this feature in general however.
- Mouse interaction
You can use the mouse to drag the masses. The mouse pointer is attached to the weights via a spring. This allows you to experience the weight variation and the stiffness of the rods.
- Number of sub-steps
The crucial idea to tremendously increase the convergence rate of PBD was to replace iterations by sub-steps. We have set the number of sub-steps to 50. Almost all demos work well with 20. The only reason to go higher is to reduce the amount of energy loss. Note that effect of compliance is independent of the number of sub-steps due to the XPBD update.
- Force labels
Set the equilibrium position and turn on force labels. As you can see, the forces correspond to 10 times the weight below each link since gravity is 10. At the same time, the elongations are zero if the compliance is zero (corresponding to infinite stiffness). If you increase the compliance the elongations become proportional (via inverse compliance) to the forces. This is best seen with high edge damping. Pull on the weights to see what happens.
The single pendulum
Set the number of segments to 1. Choose compliance zero. As expected from physics, the frequency is independent of the mass but dependent on the link length. Set the mass to ten and the compliance to 0.01. Then hit restart with a variety of edge damping coefficients. While the demo is running, change the number of sub-steps. As you see, the stiffness is unaffected.
- The double pendulum
Compare the behavior with the many simulations on the web. Play with all the parameters.
- Unilateral constraints
Turn compliance to zero and check the "uni" box. The links turn green. In this case, they are allowed to compress but not to expand. The corresponding constraints are called unilateral. Handling them with traditional solvers is challenging.
Turn on collision handling and see what happens. The last weight bounces off the x = 0 line. This experiment shows the high fidelity of you method. In this case, the trajectory has sharp edges. These are damped out with implicit solvers. The problem increases by increasing the order of the integration method. Collision constraints are unilateral as well.
- High mass ratios
To see how well our method handles high mass ratios, set the number of links to four. Set the firs three masses to 0.1 and the last to 10 while all compliances are zero. Hit restart and see how there is almost no stretching in the links. Play with the number of sub-steps. Twenty are enough to handle this situation.
Edge damping decreases the bouncing of compliant links. As stiffness, damping is unconditionally stable with our method. Sometimes, users like the overall damping introduced artificially be implicit solvers. You can inject it in a controlled manner via the global damping parameter.
Note the stability of our approach over the wide space of parameters. We have not seen serious crashes but if it happens, simply re-load the page by hitting F5.