3
$\begingroup$

I'm new to mathematica and I need to get the equations for the set of planes which are part of a convex hull that I have calculated using ConvexHullMesh. It is a convex polyhedron. I tried searching quite a bit but there does not seem to be any mention of this. Any help is appreciated.

For the reference, here's the code for convex hull

pts = {{-0.00033004023134713956, 0, 0},{-0.00033004023134713956, -0.001, 0},
{0.00033004023134713956, -0.001, 0},{0.00033004023134713956, -0.00033004023134713956, 0},
{0,0,0},{-0.00033004023134713956, 0.001, -0.00033004023134713956},{0.00033004023134713956, 
0.001, 0.00033004023134713956},{0.00033004023134713956, 0, 0.00033004023134713956},
{-0.00033004023134713956, 0.00033004023134713956, -0.00033004023134713956},{0,0,0},
{-0.00033004023134713956, 0, 0},{-0.00033004023134713956, 0.00033004023134713956, 
-0.00033004023134713956},{0,0,0},{0.00033004023134713956, 0, 0.00033004023134713956},
{0.00033004023134713956, -0.00033004023134713956, 0},{0,0,0}};

ConvexHullMesh[pts, AxesLabel -> {"E(y)", "y", "E(z)"}]
$\endgroup$
2
  • $\begingroup$ PolyhedronData? $\endgroup$ Jul 29 '20 at 6:27
  • $\begingroup$ @CATrevillian are you suggesting that I take the convex polyhedron and using PolyhedronData extract the Polygons and then as specified in section Get condition for point membership in reference.wolfram.com/language/ref/Polygon.html, do RegionMember[\[ScriptCapitalR], {x, y, z}] to get the equations? If so, how do I convert the BoundaryMeshRegion returned by ConvexHullMesh to a Polyhedron? $\endgroup$ Jul 29 '20 at 7:13
2
$\begingroup$

You can get equations for each polygon membership like this:

eqns = FullSimplify[RegionMember[#, {x, y, z}]] & /@ MeshPrimitives[cvx, 2]

This has inequalities to constrain each plane to the triangular face of each polygon. You can throw these away just leaving the equations of the planes:

planeEqns = DeleteCases[eqns, (_ >= _) | (_ <= _), Infinity]

(* or better, you could do: *)
planeEqns = Select[Flatten[eqns /. And -> List], Head[#] === Equal &]

Result:

{1. x == 0.00033004 + 2. z, 0.001 + 1. y + 4.02993 z == 0, 
 0.00033004 + 1. x == 0, 0.001 + 1. y == 3.02993 z, 
 1. x == 0.00033004, 
 1. x + 2.50817*10^-16 z == 0.00033004 + 2.18777*10^-16 y, 
 1. x + 0.248143 y == 0.000248143 + 1. z, 
 0.00033004 + 1. x == 0.33004 y + 1. z, 
 0.00033004 + 1. x + 2.27638*10^-16 y + 4.78885*10^-16 z == 0, 
 1. x + 1.09024*10^-16 y == 0.00033004 + 2. z, 
 0.00033004 + 1. x + 2.79408*10^-17 y == 2. z, 
 0.00033004 + 1. x == 2. z}

Then you could convert this into a matrix form $A \hat{x}+b=\mathbf{0}$ if you needed to use it in something like a linear programming problem:

(* use chop to throw away some very small values if desired *)
mtxs = Chop@Normal@CoefficientArrays[planeEqns /. Equal -> Subtract, {x, y, z}]
$\endgroup$
3
$\begingroup$

Here is a way to get the triangle means and the normals of the triangular faces using ToBoundaryMesh. With that information, you should be able to obtain an equation of a plane.

Needs["NDSolve`FEM`"]
pts = {{-0.00033004023134713956, 0, 
    0}, {-0.00033004023134713956, -0.001, 
    0}, {0.00033004023134713956, -0.001, 
    0}, {0.00033004023134713956, -0.00033004023134713956, 0}, {0, 0, 
    0}, {-0.00033004023134713956, 
    0.001, -0.00033004023134713956}, {0.00033004023134713956, 0.001, 
    0.00033004023134713956}, {0.00033004023134713956, 0, 
    0.00033004023134713956}, {-0.00033004023134713956, 
    0.00033004023134713956, -0.00033004023134713956}, {0, 0, 
    0}, {-0.00033004023134713956, 0, 0}, {-0.00033004023134713956, 
    0.00033004023134713956, -0.00033004023134713956}, {0, 0, 
    0}, {0.00033004023134713956, 0, 
    0.00033004023134713956}, {0.00033004023134713956, \
-0.00033004023134713956, 0}, {0, 0, 0}};

chull = ConvexHullMesh[pts, AxesLabel -> {"E(y)", "y", "E(z)"}]
bmesh = ToBoundaryMesh[chull];
groups = bmesh["BoundaryElementMarkerUnion"];
temp = Most[Range[0, 1, 1/(Length[groups])]];
colors = ColorData["BrightBands"][#] & /@ temp;
Short[bn = bmesh["BoundaryNormals"]];
mean = Mean /@ GetElementCoordinates[bmesh["Coordinates"], #] & /@ 
   ElementIncidents[bmesh["BoundaryElements"]];
Show[
 bmesh["Wireframe"["MeshElementStyle" -> FaceForm /@ colors]],
 Graphics3D[
  MapThread[
   Arrow[{#1, #2}] &, {Join @@ mean, Join @@ (bn/2000 + mean)}]]]

Triangle Normals

The following should retrieve the equations of the plane normals (note that some are coplanar):

Simplify[({x, y, z} - #[[1]]).#[[2]] == 0] & /@ 
  Transpose@{mean[[1]], bn[[1]]} // MatrixForm

Plane Equations

$\endgroup$

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.