7

I have the following convex hull.

P0={0,0,0};
P1={1,0,0};
P2={0,1,0};
P3={0,0,1};

ConvexHullMesh[{P0,P1,P2,P3}]

Now I want the region algebraically as equality of the convex hull generated, in this case x+y+z<1&&x>0&&y>0&&z>0. Is there any automatic way to get it from Mathematica by converting the convex hull generated as a region and then convert it into inequality?

Epsilon
  • 1,122
  • 4
  • 8

1 Answers1

11
chm = ConvexHullMesh[{P0, P1, P2, P3}]; 

ClearAll[regFunc]

regFunc[{x, y, z}] := FullSimplify @ RegionMember[Rationalize @
    MeshPrimitives[DiscretizeRegion[chm, MaxCellMeasure -> ∞], 3][[1]]] @ {x, y, z}

regFunc @ {x, y, z}
 x + y + z <= 1 && z >= 0 && y >= 0 && x >= 0

Also

dm = DelaunayMesh[{P0, P1, P2, P3}];

ClearAll[regFunc2]

regFunc2[{x_, y_, z_}] := FullSimplify @
   RegionMember[Rationalize @ First @ MeshPrimitives[dm, 3]] @ {x, y, z};

regFunc2 @ {x, y, z}
 x + y + z <= 1 && z >= 0 && y >= 0 && x >= 0
kglr
  • 394,356
  • 18
  • 477
  • 896
  • 1
    Thanks a lot. Just another question: Can this be done for a 4-d convex hull? Of course, Mathematica cannot evaluate the convex hull for a 4-d case. But is there any way to get the inequality representation of the convex hull? The type of convex hull I work with has 5 points for a 4-d case and so is very simple. Say for example {0,0,0,0},{1,0,0,0}, {0,1,0,0},{0,0,1,0},{0,0,0,1}. Is there any way to get it just like the 3d case you showed in Mathematica itself? – Epsilon Jun 14 '20 at 04:32
  • 1
    @SumitBanik, thank you for the accept. Don't know how the nD case can be handled. – kglr Jun 14 '20 at 04:47
  • Alright.Thanks a lot – Epsilon Jun 14 '20 at 04:55
  • 1
    An nD example can be found here. – Greg Hurst Jun 14 '20 at 11:36
  • When I several convex hulls defined in an array R[i], where say – Epsilon Jun 15 '20 at 02:38
  • @Sumit, if I understand correctly, you can use the method above to get a region function for each of your several convex hulls, then you can combine them with Or to get a single region function. – kglr Jun 15 '20 at 02:42
  • @kglr Sorry the earlier comment was incomplete. When I have several convex hulls defined in an array R[i], where say R[1]= ConvexHullMesh[{P0, P1, P2, P3}]; Now I run a do loop to find the region inequality at once for all convex hull in the array R[i] using the code. Do[regFunc[i][{x, y, z}] := FullSimplify @ RegionMember[Rationalize @ MeshPrimitives[DiscretizeRegion[R[i], MaxCellMeasure -> [Infinity]], 3][[1]]] @ {x, y, z},{i,1,16}]; regFunc[1]@{x,y,z} But this code is not working – Epsilon Jun 15 '20 at 02:44
  • @SumitBanik, If you put ClearAll[regFunc] before Do[...] and it still does not work, please update your post (or post a new question) with a smaller version of your array R (with 2 regions instead of 16). – kglr Jun 15 '20 at 03:08
  • @kglr. Thanks for your comments. I tried it but it didn't help. So I made a new post with two problems https://mathematica.stackexchange.com/questions/223985/convert-convexhull-in-a-array-to-inequality. – Epsilon Jun 15 '20 at 03:29