'Convert a set of overlapping cuiboids to a minumum set of non-overlapping cuiboids

I am trying to decompose an overlapping set of cuboids to non-overlapping ones, the fewer non-overlapping cuboids used the better.

For example, in the case below: An example of three overlapping cuboids

There are three overlapping cuboids, a 2 by 2 by 1 cuboid starting at (0,0,0), a 7 by 5 by 2 cuboid starting at (1,1,0) and a 3 by 2 by 4 cuboid starting at (4,2,0). Each of the cuboid intersects with another one. One possible solution of non-overlapping decomposition would be 2 by 2 by 1 at (0,0, 0), 1 by 4 by 1 at (1, 2,0),1 by 5 by 1 at (1,1,1), 6 by 5 by 2 at (2,1,0) and 3 by 2 by 2 at (4,2,2). There are of course more than one possible solutions to this setting.

Thank you in advance for your input, and please let me know if I can clarify the question better.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source