Octree Post

5 Mar

The only differences between an Octree and a Quadtree is an additional axis.  This post will cover bounding box checks; for Tree psuedo code and structure breakdown go to my Quadtree page.  Please note an interactive example is below for this tree structure.  For spheres and cubes (circles/rectangles in 2d) it’s always quicker to check intersections by comparing centers and length or radius.  For simplicity I only store a bounding boxes length and center.


To test if a point is inside a bounding box. Take the absolute value of the distance between the point and this boxes center, if this value is less than 1/2 it’s length (I times the distance by two because I don’t store half lengths).  If it’s true for every axis this point is inside.


To test if bounding boxes overlap.  Take the ABS of the distance between the two boxes (times by two or compare to their half lengths) and check if that value is less than the boxes combined length.  If it is, they overlap.


OctreeBoxTo find the child node a point falls into can be solved with three axis checks.  Example of how I arranged the nodes to the left (the cube that isn’t visible is 101.)

(Please note interactive example below takes about 30 seconds to load):

Leave a Reply

Your email address will not be published.