2
$\begingroup$

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] Two mesh cubes does nothing!

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

BooleanRegion fails

$\endgroup$
3
  • 5
    $\begingroup$ Change MeshRegion to BoundaryMeshRegion and try again. $\endgroup$ Jul 7 at 13:10
  • $\begingroup$ @J.M. thank you sir, i'm such a nub )))) $\endgroup$
    – Anton
    Jul 7 at 13:24
  • 1
    $\begingroup$ 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] $\endgroup$
    – user21
    Jul 7 at 13:33

1 Answer 1

5
$\begingroup$

The solution was embarrassingly obvious:

c1=BoundaryMeshRegion[cube1Coordinates, cube1Cells];
c2=BoundaryMeshRegion[cube2Coordinates,cube2Cells];

RegionDifference[c1,c2]
$\endgroup$
3
  • 5
    $\begingroup$ In brief: the problem was that you were trying to take the difference of two surfaces (MeshRegion[]) instead of two solids (BoundaryMeshRegion[]). $\endgroup$ Jul 7 at 13:31
  • 1
    $\begingroup$ @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. $\endgroup$
    – user21
    Jul 7 at 15:10
  • $\begingroup$ @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. $\endgroup$ Jul 7 at 15:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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