2
$\begingroup$

I am using RegionMember[] to determine wether a point is within a shape.

shape1 = Cuboid[{0, 0, 0}, {1, 1, 1}]
RegionMember[shape1, {0.5, 0.5, 0.5}]

Returns True, but this doesn't

shape2 = Cuboid[{0, 0, 0}, {1, 1, -1}]
RegionMember[shape2, {0.5, 0.5, -0.5}]

Any ideas on why this is the case, or how to fix. I would like a True returned if the point is within the Cuboid.

$\endgroup$
  • $\begingroup$ In versions 10.0.1 and 10.4.1 RegionMember[shape2, {0.5, 0.5, -0.5}] generates a message RegionMember::regp: "A correctly specified region expected at position 1 of RegionMember[Cuboid[{0,0,0},{1,1,-1}],{0.5,0.5,-0.5}].", but in versions 11.1.1 and 11.2.0 it doesn't. $\endgroup$ – Alexey Popkov Jan 12 '18 at 8:06
  • $\begingroup$ @AlexeyPopkov Ah. Now I get it. I also got the message (v 11.0.1) but wondered how this can be overlooked... $\endgroup$ – Henrik Schumacher Jan 12 '18 at 8:07
2
$\begingroup$

Try shape2 = Cuboid[{0, 0, -1}, {1, 1, 0}] or Cuboid @@ Transpose[Sort /@ Transpose[{{0, 0, 0}, {1, 1, -1}}]]. Mathematica expects that the entries of the first argument list are all less or equal the respective entries of the second argument list.

$\endgroup$
  • 2
    $\begingroup$ Isn't this assumption unexpected? $\endgroup$ – Kuba Jan 12 '18 at 7:14
  • 1
    $\begingroup$ @Kuba ?Cuboid says Cuboid[Subscript[p, min],Subscript[p, max]] represents an axis-aligned filled cuboid with lower corner Subscript[p, min] and upper corner Subscript[p, max]. I see "min", "max" and "lower corner" and "upper corner", so no, I don't think that this should be considered unexpected. Moreover, the documentation page is also quite detailed about it. Btw: Graphics3D accepts Cuboid[{0, 0, 0}, {1, 1, -1}], but it gets the rendering wrong. $\endgroup$ – Henrik Schumacher Jan 12 '18 at 8:02
  • $\begingroup$ I know it is for people but for arbitrary ViewVertical, terms lower/upper make not so much sense. p.s. I can't reproduce the problem with rendering, what exactly did you have in mind? $\endgroup$ – Kuba Jan 12 '18 at 8:08
  • $\begingroup$ @Kuba Since the normals point inwards, the shading is not computed correctly. But maybe this is also version specific? $\endgroup$ – Henrik Schumacher Jan 12 '18 at 8:10
  • 1
    $\begingroup$ @Kuba Getting an error message from Cuboid might be difficult as it was orginally meant merely as a wrapper for Graphics3D. But I am with you that at least RegionMember should tell us that something is going wrong. Actually in v 11.0.1 it does... $\endgroup$ – Henrik Schumacher Jan 12 '18 at 8:19

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.