Quote:
Originally Posted by brainwreck
What is this spring simulation?
|
Something that spreads out the blocks. It's meant for when things are initially a bit kludgy (you might see for instance that when you open a project for the first time, the blocks sort of jiggle into place).
Two forces act on the blocks:
1. A spring force, where every connection between two blocks is considered as a spring pulling them together.
2. A repellent force between all blocks which pushes blocks apart. This force decreases faster with distance than the spring force (quadratically in this case).
This system can then be simulated with a verlet algorithm which puts the blocks in non-overlapping but reasonably close positions.
It's a very simple technique and more advanced stuff exists for placing graph structures, but this seemed like a decent enough start that wouldn't cause too many hard to debug corner cases. Hitting CTRL + Enter will make it do a few iterations of the verlet algorithm if you're interested in seeing what it does.