4
$\begingroup$
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}]]

enter image description here

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. enter image description here

$\endgroup$
3
  • $\begingroup$ 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. $\endgroup$ Commented Sep 26, 2020 at 10:09
  • $\begingroup$ @J.M. RegionIntersection[Cuboid[],HalfSpace[{0,1,0},1/3]] The returned nor cuboid. $\endgroup$
    – expression
    Commented Sep 26, 2020 at 10:25
  • $\begingroup$ That's what I meant by "not sufficiently smart", yes. $\endgroup$ Commented Sep 26, 2020 at 10:27

2 Answers 2

5
$\begingroup$
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]

enter image description here

$\endgroup$
1
  • $\begingroup$ Once again... bested by the mysterious @kglr (+1). $\endgroup$ Commented Sep 26, 2020 at 18:35
4
$\begingroup$

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]
$\endgroup$
1
  • $\begingroup$ Good job, Thank you. $\endgroup$
    – expression
    Commented Sep 26, 2020 at 12:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.