# Cube cutting problem

Show[Graphics3D[{Cuboid[]}],
ContourPlot3D[{x==1/3,y==1/4,z==1/5},{x,-0.2,1.2},{y,-0.2,1.2},{z,-0.2,1.2}]]


Three planes divide the unit cube into 8 small cubes, what's the easiest way to get these 8 little cuboids? I've tried the regional boolean operation
RegionIntersection[Cuboid[], ImplicitRegion[x < 1/3 && y < 1/4 && z < 1/5, {x, y, z}]] gives

BooleanRegion[#1&&#2&,{Cuboid[{0,0,0}],ImplicitRegion[x<1/3&&y<1/4&&z<1/5,{x,y,z}]}]

but I want

Cuboid[{0, 0, 0}, {1/3, 1/4, 1/5}]

The expected final output is

{Cuboid[{1/3,1/4,1/5},{1,1,1}], Cuboid[{1/3,1/4,0},{1,1,1/5}], Cuboid[{1/3,0,1/5},{1,1/4,1}], Cuboid[{1/3,0,0},{1,1/4,1/5}], Cuboid[{0,1/4,1/5},{1/3,1,1}], Cuboid[{0,1/4,0},{1/3,1,1/5}], Cuboid[{0,0,1/5},{1/3,1/4,1}], Cuboid[{0,0,0},{1/3,1/4,1/5}]}

Show[Graphics3D[{Cuboid[]}],
ContourPlot3D[{x==1/3,y==1/4,z==1/5,x==3/4,y==5/6,z==6/7},
{x,-0.2,1.2},{y,-0.2,1.2},{z,-0.2,1.2}]]


If can be extended to the case of six planes, it will be better.

• RegionIntersection[] is not sufficiently smart to figure out that the intersection of Cuboid[] and HalfSpace[] should be representable as a Cuboid[] as well, so you'll need to do it manually. Sep 26, 2020 at 10:09
• @J.M. RegionIntersection[Cuboid[],HalfSpace[{0,1,0},1/3]] The returned nor cuboid. Sep 26, 2020 at 10:25
• That's what I meant by "not sufficiently smart", yes. Sep 26, 2020 at 10:27

xmesh = {0, 1/3, 2/3, 1};
ymesh = {0, 1/4, 2/4, 3/4, 1};
zmesh = {0, 1/5, 3/5, 4/5, 1};

cuboids =  Cuboid@@@(Transpose /@ Tuples[Partition[#, 2, 1]& /@ {xmesh, ymesh, zmesh}]);

Graphics3D[{Opacity[.3, RandomColor[]], #} & /@ cuboids, Boxed -> False]


• Once again... bested by the mysterious @kglr (+1). Sep 26, 2020 at 18:35

This can be made far more elegant and terse using Outer, but it works:

xplanes = {1/3, 2/3};
yplanes = {1/4, 2/4, 3/4};
zplanes = {1/5, 3/5, 4/5};
ends = {0, 1};

myPlanes = Union[ends, #] & /@ {xplanes, yplanes, zplanes};

theCuboidlets=Flatten[Table[
Cuboid[{myPlanes[[1, i]],
myPlanes[[2, j]],
myPlanes[[3, k]]},
{myPlanes[[1, i + 1]],
myPlanes[[2, j + 1]],
myPlanes[[3, k + 1]]}],
{i, Length[myPlanes[[1]]] - 1},
{j, Length[myPlanes[[2]]] - 1},
{k, Length[myPlanes[[3]]] - 1}]];

Graphics3D[theCuboidlets]

• Good job, Thank you. Sep 26, 2020 at 12:30