Problème de coupe de cube

Sep 26 2020
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}]]

Trois plans divisent le cube unité en 8 petits cubes, quel est le moyen le plus simple d'obtenir ces 8 petits cubes? J'ai essayé l'opération booléenne régionale
RegionIntersection[Cuboid[], ImplicitRegion[x < 1/3 && y < 1/4 && z < 1/5, {x, y, z}]]donne

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

mais je veux

Cuboïde [{0, 0, 0}, {1/3, 1/4, 1/5}]

Le résultat final attendu est

{Cuboïde [{1 / 3,1 / 4,1 / 5}, {1,1,1}], Cuboïde [{1 / 3,1 / 4,0}, {1,1,1 / 5}] , Cuboïde [{1 / 3,0,1 / 5}, {1,1 / 4,1}], Cuboïde [{1 / 3,0,0}, {1,1 / 4,1 / 5}] , Cuboïde [{0,1 / 4,1 / 5}, {1 / 3,1,1}], Cuboïde [{0,1 / 4,0}, {1 / 3,1,1 / 5}] , Cuboïde [{0,0,1 / 5}, {1 / 3,1 / 4,1}], Cuboïde [{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}]]

Si peut être étendu au cas de six avions, ce sera mieux.

Réponses

5 kglr Sep 26 2020 at 13:23
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]

4 DavidG.Stork Sep 26 2020 at 12:04

Cela peut être rendu beaucoup plus élégant et concis en utilisant Outer, mais cela fonctionne:

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]