I've searched for this algorithm, including on stackoverflow, but did not find one. Unlike finding the minimum bounding rectangle for a known 3D figure, I'm trying to find one, axis-aligned, for an arbitrary, solid, continuous, 3D figure...the only constraint is that this figure completely fits into a 3D matrix of a gives size, say 800X800X800. Can someone please give me an efficient algo for this?
1 Answers
How is the 3D figure represented, as a set of bounding polygons, or something else?
I assume you can get a set of vertex points on the 3D figure, whether or not they are on its exterior surface.
I assume by "minimum bounding rectangle" you mean the bounding rectilinear solid (like a brick) with minimum volume.
By "axis-aligned" I assume you mean the edges of the brick are aligned with the preexisting x, y, and z axes. i.e. you can't make the brick smaller by rotating it.
Then from your description it sounds like you just want the min and max along each coordinate axis. That would take linear time in the number of points.
Unless I misunderstand the question.
EDIT: OK, from your clarification that you are starting from an 800^3 array a of booleans, the best I can think of is:
// a lot depends on how you index array a
// this assumes it is one big block of bools
#define A(i,j,k) a[(i)*800*800 + (j)*800 + (k)]
// to get the minimum X value
for (ix = 0; ix < 800; ix++){
// search over the entire plane at x == ix
// this can probably be improved by stepping pointers
for (iy = 0; iy < 800; iy++){
for (iz = 0; iz < 800; iz++){
// nobody likes goto, but it's probably the quickest way out
// of the 3 nested loops
if (A(ix, iy, iz)) goto L100;
}
}
}
L100:;
// here, ix is minimum x value
// do similar code for max x, min and max y, min and max z
It can probably be improved somewhat. Worst case, this will do 3^800^3 tests, if the volume is empty. Best case, it will do 6*800^2 tests, if the volume is full.

- 40,059
- 14
- 91
- 135
-
The only input I have is a 3D matrix of booleans...the aforementioned cube, say 800x800x800. The 3D figure, for which I have to calculate the axis-aligned minimum bounding rectangle, is of unspecified size (fully enclosed in the input matrix) and at an unspecified location within the input matrix. It is solid and continuous and represented by TRUE values for the corresponding input matrix elements. The rest of the input matrix elements are FALSE. – user1869484 Dec 02 '12 at 01:46
-
Yes, I do mean bounding rectilinear solid...a box, or brick. – user1869484 Dec 02 '12 at 02:04
-
Yes, the edges are aligned with the preexisting x, y, and axws...same as the input cube. – user1869484 Dec 02 '12 at 02:04