# Convex hull of a 3D object?

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]]


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

Needs["ComputationalGeometry"]
ConvexHull[egg]


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]


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


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]]

• Thank you +1, solved. How did you realize this? Cannot understand why mathematica has no ConvexHull3D[...] command.
– hhh
Mar 22, 2013 at 15:27
• 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. Mar 22, 2013 at 15:31
• I tried to do similar thing but for some reason it plots none, why? i.stack.imgur.com/fbthu.png
– hhh
Mar 22, 2013 at 15:48
• Your statement with Position doesn't seem to return anything for me. None of the statements are 1 they are Cuboid[{_,_,_}] Mar 22, 2013 at 15:57
• @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.
– user21
Mar 24, 2013 at 9:12

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[ComputationalGeometryMethodsConvexHull3D[v], _GraphicsComplex, Infinity];

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


• That does not appear to be a well-formed polyhedron: it has edges passing through each other and faces that overlap.
– user484
Nov 26, 2013 at 20:22
• @RahulNarain Yes, it seems so. Apparently a bug in ConvexHull3D[] . What a shame! Nov 26, 2013 at 20:46
• 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...
– user484
Nov 26, 2013 at 20:51

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]