Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
add comment

2 Answers

up vote 15 down vote accepted

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]]
share|improve this answer
    
Thank you +1, solved. How did you realize this? Cannot understand why mathematica has no ConvexHull3D[...] command. –  hhh Mar 22 '13 at 15:27
3  
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. –  s0rce Mar 22 '13 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 '13 at 15:48
    
Your statement with Position doesn't seem to return anything for me. None of the statements are 1 they are Cuboid[{_,_,_}] –  s0rce Mar 22 '13 at 15:57
3  
@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 '13 at 9:12
add comment

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

share|improve this answer
1  
That does not appear to be a well-formed polyhedron: it has edges passing through each other and faces that overlap. –  Rahul Narain Nov 26 '13 at 20:22
    
@RahulNarain Yes, it seems so. Apparently a bug in ConvexHull3D[] . What a shame! –  belisarius Nov 26 '13 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... –  Rahul Narain Nov 26 '13 at 20:51
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.