10
$\begingroup$

I am trying to find a convex hull command for a Graphics3D object. Does it exist in Mathematica?

egg = Graphics3D[Cuboid /@ Position[DiskMatrix[{12, 10, 8}], 1]]

Mathematica graphics

The ConvexHull command of the "ComputationalGeometry`" package does not work on 3D objects:

Needs["ComputationalGeometry`"]
ConvexHull[egg]

Mathematica graphics

$\endgroup$
0

3 Answers 3

17
$\begingroup$

Since ConvexHull doesn't support 3D points (and you incorrectly tried to compute the ConvexHull of the Graphics object) your code didn't work.

Here is one way to do what I think you want (I left out of the step of the Cuboids but if you want that basically just offset your convex hull).

Needs["TetGenLink`"]

pos = Position[DiskMatrix[{12, 10, 8}], 1];
Graphics3D[Point@pos]

Mathematica graphics

{pts, surface} = TetGenConvexHull[pos];
Graphics3D[GraphicsComplex[pts, Polygon[surface]]]

Mathematica graphics

If you do want to compute the ConvexHull of your Graphics3D object you can extract the points from the InputForm. This is fragile and will only work for this simple case.

pos = InputForm[egg][[1, 1, All, 1]]
$\endgroup$
5
  • $\begingroup$ Thank you +1, solved. How did you realize this? Cannot understand why mathematica has no ConvexHull3D[...] command. $\endgroup$
    – hhh
    Commented Mar 22, 2013 at 15:27
  • 4
    $\begingroup$ The documentation for ConvexHull shows the syntax: ConvexHull[{{x1,y1},{x2,y2},...}] no z coordinate implies that its 2D (x,y) only. Searching ConvexHull in the documentation doesn't appear to simply direct you to TetGenLink unfortunately. I just knew about it. $\endgroup$
    – s0rce
    Commented Mar 22, 2013 at 15:31
  • $\begingroup$ I tried to do similar thing but for some reason it plots none, why? i.sstatic.net/fbthu.png $\endgroup$
    – hhh
    Commented Mar 22, 2013 at 15:48
  • $\begingroup$ Your statement with Position doesn't seem to return anything for me. None of the statements are 1 they are Cuboid[{_,_,_}] $\endgroup$
    – s0rce
    Commented Mar 22, 2013 at 15:57
  • 3
    $\begingroup$ @sOrce, The fact that this link is missing is an oversight on my part. I'll add a link such that when one searches for ConvexHull that the TetGenLink example is found. Thanks. $\endgroup$
    – user21
    Commented Mar 24, 2013 at 9:12
8
$\begingroup$

Without using the TetGen package:

Needs["ComputationalGeometry`"];
egg = Graphics3D[{Red, Cuboid /@ Position[DiskMatrix[{3, 4, 5}], 1]}];

v = Flatten[Cases[egg, Cuboid[x_]:> Outer[Plus, Tuples[{0, 1}, 3], {x}, 1][[All, 1]], 3], 1];
prism@v_ = Cases[ComputationalGeometry`Methods`ConvexHull3D[v], _GraphicsComplex, Infinity];


GraphicsRow@{egg, 
            Show[egg, Graphics3D[{Opacity[.3], Yellow, prism@v}]], 
            Graphics3D[{Opacity[1], Yellow, prism@v}]}

enter image description here

$\endgroup$
3
  • 1
    $\begingroup$ That does not appear to be a well-formed polyhedron: it has edges passing through each other and faces that overlap. $\endgroup$
    – user484
    Commented Nov 26, 2013 at 20:22
  • $\begingroup$ @RahulNarain Yes, it seems so. Apparently a bug in ConvexHull3D[] . What a shame! $\endgroup$ Commented Nov 26, 2013 at 20:46
  • 1
    $\begingroup$ Well, dealing with degenerate cases like collinear and coplanar vertices is the hardest part to get right in computational geometry algorithms, and this point set has them in spades. That's probably why they kept the function internal... $\endgroup$
    – user484
    Commented Nov 26, 2013 at 20:51
8
$\begingroup$

In Version 10, there is now the built-in ConvexHullMesh to do exactly this.

pos = Position[DiskMatrix[{12, 10, 8}], 1];

To get the 3D convex hull:

ConvexHullMesh[pos]

Mathematica graphics

$\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.