samizdatco/arbor — pull request #27 by pcottle (2012-04-12 22:24:24+00:00)
Title: Velocity Verlet Integration Change

Hi Christian:

As we discussed, I have modified the Physics simulation to use velocity verlet integration. There is a considerable stability improvement in low-friction simulations.

To see the stability difference:

* Open up the halfviz demo for this fork by running the python SimpleHTTPServer.
* Select "abominable snowman" from the examples list
* Set Friction to 0%
* Increase spring tension and monitor performance of the nodes. For me, around **3300** is when I begin to get "flickering" of the nodes. I suspect jittering occurs here because the timesteps are too large for such high forces.

To compare to the stable branch:

* Navigate to http://arborjs.org/halfviz
* Select "abominable snowman"
* Set Friction to 0%
* Increase spring tension. Jittering for me begins around **1800**, and once going into a jittering state, there is a considerable hysteresis (you must go far below 1800 to obtain stable motion).

The only issue with this change is that the nodes reach stability quite quickly in most simulations, and the code to turn off the simulation activates too soon (because it detects a low amount of energy I believe). It can be somewhat visually jarring. I'm not sure where this code activates or if there is a default parameter to change (I looked for it in physics.js but had no luck), but changing this deactivation constant to a lower parameter might obtain the best results.

Let me know what you think. This is my first pull request!

Thanks,
Peter