This comes from Section 6.2.3.1 of Christer Ericson's book. I don't remember all the details, so if you figure it out, please post back here.
Thanks for the lead!
Progress Report 1: Ericson's book appears to pull the numbers out of the air. Apparently he expects readers to understand why, but I guess I have a mental block. One of the 2.0s is actually a real 2.0, the other is the degree of the tree which just happens to be 2. Ericson references two papers which I will hunt down. More later.
Now I understand. The cost of a node is the probability of having to do intersection tests. If the intersection test at the current node gives a positive result (probability proportional to its area), then you have to do 2 more tests in its children. Having waded through various tutorials on the subject, I have to say that the original Goldsmith-Salmon paper gives the clearest explanation.
@article{GoldsmithSalmon1987ObjectHierarchies,
author = {Jeffrey Goldsmith and John Salmon},
title = {Automatic Creation of Object Hierarchies for Ray Tracing},
journal = {IEEE Computer Graphics and Applications},
volume = 7,
number = 5,
pages = {14--20},
year = 1987
}
Thanks for the pointers!
Another question for you Erin, and perhaps people who have experience with Box2D on other platforms can share their experience. You've taken great pains to remove recursion from your code. Looking at b2DynamicTree I can see several places where recursion would normally be used. Did you remove recursion for speed, or because some platforms don't support it well (or at all), or because everybody else is doing it?
There's a recurrent meme from the 1970s (when I was a lowly undergraduate 🤓 ) that recursion is slow. That was often true back then, but it's not always true now. The "fact" gets copied from textbook to textbook, but it is an idea whose time has passed. Recursion is often faster than using your own stack, and it has the benefit of making your code shorter and easier to understand.
Shorter, faster, and easier to understand? What's not to like?