5
$\begingroup$

I want to subtract one Cuboid[] form another Cuboid[]. This is the code I use:

RegionPlot3D@ RegionDifference[Cuboid[{1, 1, 1}, {-1, -1, -1}],Cuboid[{0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}]]

but I get the error:

RegionDifference::reg: "Cuboid[{1,1,1},{-1,-1,-1}] is not a correctly specified region. "

On the other hand, the code:

RegionPlot3D@ RegionDifference[Cuboid[{1, 1, 1}],Cuboid[{0.5, 0.5, 0.5}]]

works:

enter image description here

Graphics3D and Show can visualize the two cube:

Show[Graphics3D[{Opacity[0.2],Cuboid[{0.5, 0.5, 0.5}, {-0.5, -0.5, -0.5}]}], 
 Graphics3D[{Opacity[0.2], Cuboid[{1, 1, 1}, {-1, -1, -1}]}]]

What am I doing wrong?

enter image description here

$\endgroup$
3
  • 3
    $\begingroup$ Graphics3D can be forgiving but in general the first point should be a lower one. Not sure where exactly does it matter but I recall a question where lighting of cuboid was broken on MacOS due to that reversed spec, worked on Windows. $\endgroup$
    – Kuba
    Commented Aug 17, 2018 at 11:32
  • $\begingroup$ @Kuba that is a bug then, or do you see a rationale that will justify such restriction? $\endgroup$
    – rhermans
    Commented Aug 17, 2018 at 14:48
  • $\begingroup$ @rhermans it is the first line in Cuboid docs :) $\endgroup$
    – Kuba
    Commented Aug 17, 2018 at 16:01

1 Answer 1

6
$\begingroup$

The definition of Cuboid states:

enter image description here

So just reorder your arguments:

d = RegionDifference[Cuboid[{-1, -1, -1}, {1, 1, 1}], 
   Cuboid[{-0.5, -0.5, -0.5}, {0.5, 0.5, 0.5}]];
HighlightMesh[d, Style[2, Opacity[0.3]]]

enter image description here

$\endgroup$

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.