I am writing an application which subdivides an N-dimensional axis aligned bounding box into smaller N-dimensional bounding boxes, I need an algorithm which will do this.
For example:
in 1 dimension a “bounding box” is simply a length
e.g. { Min=0, Max=100 }
which would be subdivided into
{Min=0, Max=50} and {Min=50, Max=100}
in 2 dimensions a “bounding box” is a square
e.g. {Min=[0,0], Max=[100,100]}
would be divided into
{Min=[0,0], Max=[50,50]}
{Min=[0,50], Max=[50,100]}
{Min=[50,0], Max=[100,50]}
{Min=[50,50], Max=[100,100]}
And so on, all I need is a description of an algorithm for doing this, language doesn’t particularly matter, since once I know how to do it I can translate it into the language of choice (C# in this case)
EDIT:: In response to questions in comments:
- subdivisions must always be equal (as
in the examples) - boundaries are
floating points, so divisibility by two isn’t a problem
Break it into two problems: iterating over the grid of “Min” points, and constructing a small box for a Min point.
For your second case, {[0,0], [100,100]}, deltaX=50 and deltaY=50. The grid is
and it is trivial to construct the second column from the first:
Here’s a three-dimensional case {[0,0,0], [100,100,60]}, delta = [50, 50, 30]