QuadTree with finite sized objects

MJS 2015-09-02

This version of a quadTree works with objects with a finite size. As you move the mouse around you can see, highlited in red, which objects the tree returns. Clicking adds an object to the tree at the current position with a random size. The objects that overlap a boundary are included in each side, this means the the list of returned objects can contain duplicates. This is usually ok as there are just a few of them, and checking for collisions is now quite cheap. However if the tree is used for action-at-a-disance stuff, e.g. a gravity simulator, then this will cause double counting, in which case just remove the duplicates.

The demo below has the threshold set to 4 objects, this means that the fith object added to a region will cause the tree to divide. The tree depth is also limited to 6.

View to source to this page to see how.