# RegionDifference Fails at Two Simple Cubes

Or, maybe, I just dont get it right.

I got two simple mesh cubes:

cube1Coordinates={{10,-10,10},{-10,-10,10},{10,-10,-10},{-10,-10,-10},{10,10,10},{10,10,-10},{-10,10,10},{-10,10,-10}};
cube1Cells={Polygon[{1,2,3}],Polygon[{3,2,4}],Polygon[{5,1,6}],Polygon[{6,1,3}],Polygon[{7,5,8}],Polygon[{8,5,6}],Polygon[{2,7,4}],Polygon[{4,7,8}],Polygon[{5,7,1}],Polygon[{1,7,2}],Polygon[{8,6,4}],Polygon[{4,6,3}]};

cube2Coordinates={{15,5,15},{5,5,15},{15,5,5},{5,5,5},{15,15,15},{15,15,5},{5,15,15},{5,15,5}};
cube2Cells={Polygon[{1,2,3}],Polygon[{3,2,4}],Polygon[{5,1,6}],Polygon[{6,1,3}],Polygon[{7,5,8}],Polygon[{8,5,6}],Polygon[{2,7,4}],Polygon[{4,7,8}],Polygon[{5,7,1}],Polygon[{1,7,2}],Polygon[{8,6,4}],Polygon[{4,6,3}]};

cube1=MeshRegion[cube1Coordinates, cube1Cells];
cube2=MeshRegion[cube2Coordinates,cube2Cells];

Show[cube1,HighlightMesh[cube2,2]]


But, RegionDifference[cube1,cube2] does nothing!

What is the right way to substract one cube from another?

• Change MeshRegion to BoundaryMeshRegion and try again. Jul 7 at 13:10
• @J.M. thank you sir, i'm such a nub )))) Jul 7 at 13:24
• I think this is a bug. It should do the equivalent of m1 = MeshRegion[{{-1, -1}, {1, -1}, {1, 1}, {-1, 1}}, {Line[{{1, 2}, {2, 3}, {3, 4}, {4, 1}}]}]; m2 = MeshRegion[{{0, 0}, {1, 0}, {1, 1}, {0, 1}}, {Line[{{1, 2}, {2, 3}, {3, 4}, {4, 1}}]}]; RegionDifference[m1, m2] Jul 7 at 13:33

c1=BoundaryMeshRegion[cube1Coordinates, cube1Cells];

• In brief: the problem was that you were trying to take the difference of two surfaces (MeshRegion[]) instead of two solids (BoundaryMeshRegion[]). Jul 7 at 13:31
• @J.M., and why should that not work? I understand what OP wanted, but I see not reason why RegionDifference should not have worked in some way. Either in analogy to the 2D example (or that is a bug also) and it would return a lower level difference. Jul 7 at 15:10
• @user21 I can't say exactly why, but I'll show a simpler example: RegionDifference[DiscretizeRegion @ Sphere[{0, 0, 0}, 1], DiscretizeRegion @ Sphere[{1, 0, 0}, 1]] does nothing, but RegionDifference[DiscretizeRegion @ Ball[{0, 0, 0}, 1], DiscretizeRegion @ Ball[{1, 0, 0}, 1]] works well, and we again see the difference between surfaces vs. solids. Jul 7 at 15:27