bepu / bepuphysics2

Pure C# 3D real time physics simulation library, now with a higher version number.
Apache License 2.0
2.25k stars 261 forks source link

Consider incremental tree refines on insertion #286

Closed RossNordby closed 10 months ago

RossNordby commented 10 months ago

By default, greedy leaf insertion easily falls into pathological cases. Consider inserting a series of boxes with uniformly increasing position: each split that gets created cannot be undone, resulting in something more like a linked list.

Gathering subtrees along the path to an insertion and running a refinement on it does work to avoid that, but the binned refinement is too slow to be practical for simulations that need to insert millions of elements.

It's not surprising that a full binned build is too expensive. A lot of other cheaper options exist. It may be worth trying local rotations; they're small, but so is the effect of a single insertion.

Value of this is relatively low—most people aren't creating a perfectly ordered simulation of 50,000+ objects, and incremental refinement can bring the tree to high quality rapidly—but it may be worth a little bit of experimentation.

RossNordby commented 10 months ago

Well that was easy. Default add now performs rotations top-down along the insertion path. Faster than bottom-up by a little, but a little worse quality. Prevents pathological trees.