3
$\begingroup$

According to the documentation RegionMember should work with regions that are true for ConstantRegionQ. However, the function does not work with simple polyhedra.

Consider:

ConstantRegionQ@RandomPolyhedron[5]
(*True*)
RegionMember@RandomPolyhedron[5]
(* {} *)

I am using version 12.0. Is this a bug?

And since RegionMember is not working, is there a way to test whether a point lies inside or outside a user defined polyhedra?

An example for a user defined polyhedron (here i have triangulated the individual faces because the vertices of a face does not have to be coplanar):

data = {{{0.9000000000, 9.803074361, -0.2788974201}, {0.6750000000, 
10.19278579, -0.2270388454}, {0.4500000000, 
9.803074361, -0.2935999100}}, {{0.6750000000, 
10.19278579, -0.2270388454}, {0.2250000000, 
10.19278579, -0.2379129589}, {0.4500000000, 
9.803074361, -0.2935999100}}, {{0.2250000000, 
10.19278579, -0.2379129589}, {0, 
9.803074361, -0.3066046725}, {0.4500000000, 
9.803074361, -0.2935999100}}, {{0, 
9.803074361, -0.3066046725}, {0.2250000000, 
9.413362929, -0.3638887807}, {0.4500000000, 
9.803074361, -0.2935999100}}, {{0.2250000000, 
9.413362929, -0.3638887807}, {0.6750000000, 
9.413362929, -0.3472567826}, {0.4500000000, 
9.803074361, -0.2935999100}}, {{0.6750000000, 
9.413362929, -0.3472567826}, {0.9000000000, 
9.803074361, -0.2788974201}, {0.4500000000, 
9.803074361, -0.2935999100}}, {{0.9000000000, 
9.803074361, -1.278897420}, {0.6750000000, 
10.19278579, -1.227038845}, {0.4500000000, 
9.803074361, -1.293599910}}, {{0.6750000000, 
10.19278579, -1.227038845}, {0.2250000000, 
10.19278579, -1.237912959}, {0.4500000000, 
9.803074361, -1.293599910}}, {{0.2250000000, 
10.19278579, -1.237912959}, {0, 
9.803074361, -1.306604673}, {0.4500000000, 
9.803074361, -1.293599910}}, {{0, 
9.803074361, -1.306604673}, {0.2250000000, 
9.413362929, -1.363888781}, {0.4500000000, 
9.803074361, -1.293599910}}, {{0.2250000000, 
9.413362929, -1.363888781}, {0.6750000000, 
9.413362929, -1.347256783}, {0.4500000000, 
9.803074361, -1.293599910}}, {{0.6750000000, 
9.413362929, -1.347256783}, {0.9000000000, 
9.803074361, -1.278897420}, {0.4500000000, 
9.803074361, -1.293599910}}, {{0.9000000000, 
9.803074361, -0.2788974201}, {0.9000000000, 
9.803074361, -1.278897420}, {0.7875000000, 
9.997930077, -0.7529681327}}, {{0.9000000000, 
9.803074361, -1.278897420}, {0.6750000000, 
10.19278579, -1.227038845}, {0.7875000000, 
9.997930077, -0.7529681327}}, {{0.6750000000, 
10.19278579, -1.227038845}, {0.6750000000, 
10.19278579, -0.2270388454}, {0.7875000000, 
9.997930077, -0.7529681327}}, {{0.6750000000, 
10.19278579, -0.2270388454}, {0.9000000000, 
9.803074361, -0.2788974201}, {0.7875000000, 
9.997930077, -0.7529681327}}, {{0.6750000000, 
10.19278579, -0.2270388454}, {0.6750000000, 
10.19278579, -1.227038845}, {0.4500000000, 
10.19278579, -0.7324759022}}, {{0.6750000000, 
10.19278579, -1.227038845}, {0.2250000000, 
10.19278579, -1.237912959}, {0.4500000000, 
10.19278579, -0.7324759022}}, {{0.2250000000, 
10.19278579, -1.237912959}, {0.2250000000, 
10.19278579, -0.2379129589}, {0.4500000000, 
10.19278579, -0.7324759022}}, {{0.2250000000, 
10.19278579, -0.2379129589}, {0.6750000000, 
10.19278579, -0.2270388454}, {0.4500000000, 
10.19278579, -0.7324759022}}, {{0.2250000000, 
10.19278579, -0.2379129589}, {0.2250000000, 
10.19278579, -1.237912959}, {0.1125000000, 
9.997930077, -0.7722588157}}, {{0.2250000000, 
10.19278579, -1.237912959}, {0, 
9.803074361, -1.306604673}, {0.1125000000, 
9.997930077, -0.7722588157}}, {{0, 9.803074361, -1.306604673}, {0, 
9.803074361, -0.3066046725}, {0.1125000000, 
9.997930077, -0.7722588157}}, {{0, 
9.803074361, -0.3066046725}, {0.2250000000, 
10.19278579, -0.2379129589}, {0.1125000000, 
9.997930077, -0.7722588157}}, {{0, 9.803074361, -0.3066046725}, {0,
9.803074361, -1.306604673}, {0.1125000000, 
9.608218645, -0.8352467266}}, {{0, 
9.803074361, -1.306604673}, {0.2250000000, 
9.413362929, -1.363888781}, {0.1125000000, 
9.608218645, -0.8352467266}}, {{0.2250000000, 
9.413362929, -1.363888781}, {0.2250000000, 
9.413362929, -0.3638887807}, {0.1125000000, 
9.608218645, -0.8352467266}}, {{0.2250000000, 
9.413362929, -0.3638887807}, {0, 
9.803074361, -0.3066046725}, {0.1125000000, 
9.608218645, -0.8352467266}}, {{0.2250000000, 
9.413362929, -0.3638887807}, {0.2250000000, 
9.413362929, -1.363888781}, {0.4500000000, 
9.413362929, -0.8555727816}}, {{0.2250000000, 
9.413362929, -1.363888781}, {0.6750000000, 
9.413362929, -1.347256783}, {0.4500000000, 
9.413362929, -0.8555727816}}, {{0.6750000000, 
9.413362929, -1.347256783}, {0.6750000000, 
9.413362929, -0.3472567826}, {0.4500000000, 
9.413362929, -0.8555727816}}, {{0.6750000000, 
9.413362929, -0.3472567826}, {0.2250000000, 
9.413362929, -0.3638887807}, {0.4500000000, 
9.413362929, -0.8555727816}}, {{0.6750000000, 
9.413362929, -0.3472567826}, {0.6750000000, 
9.413362929, -1.347256783}, {0.7875000000, 
9.608218645, -0.8130771013}}, {{0.6750000000, 
9.413362929, -1.347256783}, {0.9000000000, 
9.803074361, -1.278897420}, {0.7875000000, 
9.608218645, -0.8130771013}}, {{0.9000000000, 
9.803074361, -1.278897420}, {0.9000000000, 
9.803074361, -0.2788974201}, {0.7875000000, 
9.608218645, -0.8130771013}}, {{0.9000000000, 
9.803074361, -0.2788974201}, {0.6750000000, 
9.413362929, -0.3472567826}, {0.7875000000, 
9.608218645, -0.8130771013}}};

Polyhedron@data

$\endgroup$

3 Answers 3

4
$\begingroup$

You could also try:

RegionMember[
 BoundaryDiscretizeGraphics@CanonicalizePolyhedron[Polyhedron[data]]]
$\endgroup$
4
$\begingroup$

Polyhedrons are a very new data type and it is not unusual that not all possible functions have been overloaded for them.

You can extract the vertex coordinates of a Polyhedron R with R[[1]]; combined with ConvexHullMesh, this allows you to convert the Polyhedron to a MeshRegion and to apply `RandomPoint:

R = RandomPolyhedron[5];
S = ConvexHullMesh[R[[1]]];
RandomMember[S]

With the user-defined "polyhedron", you can do, e.g., this:

R = BoundaryDiscretizeGraphics@Graphics3D[
   Polygon[{{{0.9000000000, 
       9.803074361, -0.2788974201}, {0.6750000000, 
       10.19278579, -0.2270388454}, {0.4500000000, 
       9.803074361, -0.2935999100}}, {{0.6750000000, 
       10.19278579, -0.2270388454}, {0.2250000000, 
       10.19278579, -0.2379129589}, {0.4500000000, 
       9.803074361, -0.2935999100}}, {{0.2250000000, 
       10.19278579, -0.2379129589}, {0, 
       9.803074361, -0.3066046725}, {0.4500000000, 
       9.803074361, -0.2935999100}}, {{0, 
       9.803074361, -0.3066046725}, {0.2250000000, 
       9.413362929, -0.3638887807}, {0.4500000000, 
       9.803074361, -0.2935999100}}, {{0.2250000000, 
       9.413362929, -0.3638887807}, {0.6750000000, 
       9.413362929, -0.3472567826}, {0.4500000000, 
       9.803074361, -0.2935999100}}, {{0.6750000000, 
       9.413362929, -0.3472567826}, {0.9000000000, 
       9.803074361, -0.2788974201}, {0.4500000000, 
       9.803074361, -0.2935999100}}, {{0.9000000000, 
       9.803074361, -1.278897420}, {0.6750000000, 
       10.19278579, -1.227038845}, {0.4500000000, 
       9.803074361, -1.293599910}}, {{0.6750000000, 
       10.19278579, -1.227038845}, {0.2250000000, 
       10.19278579, -1.237912959}, {0.4500000000, 
       9.803074361, -1.293599910}}, {{0.2250000000, 
       10.19278579, -1.237912959}, {0, 
       9.803074361, -1.306604673}, {0.4500000000, 
       9.803074361, -1.293599910}}, {{0, 
       9.803074361, -1.306604673}, {0.2250000000, 
       9.413362929, -1.363888781}, {0.4500000000, 
       9.803074361, -1.293599910}}, {{0.2250000000, 
       9.413362929, -1.363888781}, {0.6750000000, 
       9.413362929, -1.347256783}, {0.4500000000, 
       9.803074361, -1.293599910}}, {{0.6750000000, 
       9.413362929, -1.347256783}, {0.9000000000, 
       9.803074361, -1.278897420}, {0.4500000000, 
       9.803074361, -1.293599910}}, {{0.9000000000, 
       9.803074361, -0.2788974201}, {0.9000000000, 
       9.803074361, -1.278897420}, {0.7875000000, 
       9.997930077, -0.7529681327}}, {{0.9000000000, 
       9.803074361, -1.278897420}, {0.6750000000, 
       10.19278579, -1.227038845}, {0.7875000000, 
       9.997930077, -0.7529681327}}, {{0.6750000000, 
       10.19278579, -1.227038845}, {0.6750000000, 
       10.19278579, -0.2270388454}, {0.7875000000, 
       9.997930077, -0.7529681327}}, {{0.6750000000, 
       10.19278579, -0.2270388454}, {0.9000000000, 
       9.803074361, -0.2788974201}, {0.7875000000, 
       9.997930077, -0.7529681327}}, {{0.6750000000, 
       10.19278579, -0.2270388454}, {0.6750000000, 
       10.19278579, -1.227038845}, {0.4500000000, 
       10.19278579, -0.7324759022}}, {{0.6750000000, 
       10.19278579, -1.227038845}, {0.2250000000, 
       10.19278579, -1.237912959}, {0.4500000000, 
       10.19278579, -0.7324759022}}, {{0.2250000000, 
       10.19278579, -1.237912959}, {0.2250000000, 
       10.19278579, -0.2379129589}, {0.4500000000, 
       10.19278579, -0.7324759022}}, {{0.2250000000, 
       10.19278579, -0.2379129589}, {0.6750000000, 
       10.19278579, -0.2270388454}, {0.4500000000, 
       10.19278579, -0.7324759022}}, {{0.2250000000, 
       10.19278579, -0.2379129589}, {0.2250000000, 
       10.19278579, -1.237912959}, {0.1125000000, 
       9.997930077, -0.7722588157}}, {{0.2250000000, 
       10.19278579, -1.237912959}, {0, 
       9.803074361, -1.306604673}, {0.1125000000, 
       9.997930077, -0.7722588157}}, {{0, 
       9.803074361, -1.306604673}, {0, 
       9.803074361, -0.3066046725}, {0.1125000000, 
       9.997930077, -0.7722588157}}, {{0, 
       9.803074361, -0.3066046725}, {0.2250000000, 
       10.19278579, -0.2379129589}, {0.1125000000, 
       9.997930077, -0.7722588157}}, {{0, 
       9.803074361, -0.3066046725}, {0, 
       9.803074361, -1.306604673}, {0.1125000000, 
       9.608218645, -0.8352467266}}, {{0, 
       9.803074361, -1.306604673}, {0.2250000000, 
       9.413362929, -1.363888781}, {0.1125000000, 
       9.608218645, -0.8352467266}}, {{0.2250000000, 
       9.413362929, -1.363888781}, {0.2250000000, 
       9.413362929, -0.3638887807}, {0.1125000000, 
       9.608218645, -0.8352467266}}, {{0.2250000000, 
       9.413362929, -0.3638887807}, {0, 
       9.803074361, -0.3066046725}, {0.1125000000, 
       9.608218645, -0.8352467266}}, {{0.2250000000, 
       9.413362929, -0.3638887807}, {0.2250000000, 
       9.413362929, -1.363888781}, {0.4500000000, 
       9.413362929, -0.8555727816}}, {{0.2250000000, 
       9.413362929, -1.363888781}, {0.6750000000, 
       9.413362929, -1.347256783}, {0.4500000000, 
       9.413362929, -0.8555727816}}, {{0.6750000000, 
       9.413362929, -1.347256783}, {0.6750000000, 
       9.413362929, -0.3472567826}, {0.4500000000, 
       9.413362929, -0.8555727816}}, {{0.6750000000, 
       9.413362929, -0.3472567826}, {0.2250000000, 
       9.413362929, -0.3638887807}, {0.4500000000, 
       9.413362929, -0.8555727816}}, {{0.6750000000, 
       9.413362929, -0.3472567826}, {0.6750000000, 
       9.413362929, -1.347256783}, {0.7875000000, 
       9.608218645, -0.8130771013}}, {{0.6750000000, 
       9.413362929, -1.347256783}, {0.9000000000, 
       9.803074361, -1.278897420}, {0.7875000000, 
       9.608218645, -0.8130771013}}, {{0.9000000000, 
       9.803074361, -1.278897420}, {0.9000000000, 
       9.803074361, -0.2788974201}, {0.7875000000, 
       9.608218645, -0.8130771013}}, {{0.9000000000, 
       9.803074361, -0.2788974201}, {0.6750000000, 
       9.413362929, -0.3472567826}, {0.7875000000, 
       9.608218645, -0.8130771013}}}]
   ];
RandomMember[R]

PS.: I have no clue at all what this new datatype is supposed to ship what is not already provided MeshRegions.

$\endgroup$
3
  • $\begingroup$ thanks. what about the case if my polyhedron have faces wherein the vertices are not coplanar. What I have done is that I have triangulated those faces and can display a polyhedron successfully. Do you think the approach that you have mentioned above will work for such a polyhedron? $\endgroup$
    – Ali Hashmi
    Commented Jul 10, 2019 at 4:32
  • $\begingroup$ kindly check the example that I posted in the question $\endgroup$
    – Ali Hashmi
    Commented Jul 10, 2019 at 4:43
  • $\begingroup$ thanks. I was working on a solution myself as well. We both reached the same answer :) I will accept your answer however $\endgroup$
    – Ali Hashmi
    Commented Jul 10, 2019 at 5:47
3
$\begingroup$

here is a little fix that should work for both cases:

datamodified = data /. {0.4500000000, 9.803074361, -0.2935999100} -> {0.4500000000, 
9.803074361, -0.3935999100} (* this will make vertices of one face non-coplanar *)

poly = Polyhedron[datamodified];

points = DeleteDuplicates@Flatten[poly[[1]], 1];

assoc = AssociationThread[points -> Range[Length@points]];

order = Map[Lookup[assoc, #] &, poly[[1]]];

reg = DiscretizeGraphics@Region@Polyhedron[points, order];

enter image description here

RegionMember@reg

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.