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.

Consider points taken from the following parametric plot. See this question

pf = {Cos[u], Sin[u] + Cos[v], Sin[v]};
data = Reap[ParametricPlot3D[Sow[pf], {u, 0, 2 Pi}, {v, -Pi, Pi}]][[2, 1]];
pts = Cases[data, {_?NumericQ, _?NumericQ, _?NumericQ}];

Graphics3D[{Red, Point[pts]}, Boxed -> False]

Mathematica graphics

When I tried to compute the ConvexHull I was greeted with this error message and output:

Mathematica graphics

Interesting!. Well, let's load the TetGenLink package:

Needs["TetGenLink`"]

We compute the ConvexHull again

tethull = TetGenConvexHull[pts]

Mathematica graphics

Which works fine as the output above and the following plot shows

Graphics3D[GraphicsComplex[tethull[[1]], Polygon[tethull[[2]]]], Boxed -> False]

Mathematica graphics

Interestingly, one can easily compute the Delaunay tetrahedralization using DelaunayMesh:

DelaunayMesh[pts]

Mathematica graphics

The question is, have I found a bug in ConvexHullMesh? I'm on Windows 8.1

share|improve this question
    
Behavior confirmed in v10.0.0 under Windows 7. Can any OSX or Linux users confirm? –  Mr.Wizard Jul 21 at 6:49
    
Yes, it's a bug (also on Linux) which I am going to file and I am preparing an answer. –  user21 Jul 21 at 6:55
    
@user21. Thanks for the confirmation and I await your answer. –  RunnyKine Jul 21 at 6:59
    
I can reproduce this on OS X as well. –  Rahul Jul 21 at 7:05
    
Confirmed in Mac OS 10.9.4 –  Murta Jul 21 at 12:02

2 Answers 2

up vote 8 down vote accepted

This is at least one bug, possibly more. Let me explain:

If we go one step further and use

Needs["TetGenLink`"]
tethull = TetGenConvexHull[pts];
bmr = BoundaryMeshRegion[tethull[[1]], {Polygon[tethull[[2]]]}]

BoundaryMeshRegion::binsect: "The boundary curves self-intersect or cross each other in BoundaryMeshRegion[{{1.,-0.999551,-0.000449248},{0.900969,-0.566116,-4.48799*10^-7},{0.222521,-1.97493,-4.48799*10^-7},<<46>>,{0.222521,1.8759,-0.433884},<<5751>>},<<1>>]" 

So we know why ConvexHullMesh failed, but I think ConvecHullMesh could be a little more informative about that. The next question is why are there self intersections or crossings? This is much harder to say, I suspect that some interplay with the duplicate coordinates and TetGen goes south. That is going to take some time to track down. It seems the points are too regular for TetGen.

A possible workaround (depending on the application of this) is to perturbe the input data a bit:

npts = pts + RandomReal[10^-6*{-1, 1}, {Length[pts], 3}];
ConvexHullMesh[npts]

enter image description here

I had another look at this one. To me it seems that there is an issue within TetGen for this specific input. Let's delete the duplicate coordinats:

pf = {Cos[u], Sin[u] + Cos[v], Sin[v]};
data = Reap[ParametricPlot3D[Sow[pf], {u, 0, 2 Pi}, {v, -Pi, Pi}]][[2,
     1]];
pts = Cases[data, {_?NumericQ, _?NumericQ, _?NumericQ}];
Graphics3D[Point[pts]];
Length[pts]
(*pts=DeleteDuplicates[pts];*)

pts = Region`Mesh`DeleteDuplicateCoordinates[pts][[1]];
Length[pts]

Lets export the coordinates and run tetgen on the command line:

Needs["TetGenLink`"]
inst = TetGenCreate[];
TetGenSetPoints[inst, pts];
TetGenExport["test.node", inst]

./tetgen -E test.node

When we reimport the result we get intersecting facets:

coords = Developer`ToPackedArray@
   N@Import["test.1.node", 
       "Table"][[2 ;; -2]][[All, {2, 3, 4}]];
faces = Developer`ToPackedArray@
   Import["test.1.face", 
      "Table"][[2 ;; -2]][[All, {2, 3, 4}]];
Length[coords]
{pts2, intersectingFacets} = 
  TetGenDetectIntersectingFacets[coords, 
   Developer`ToPackedArray@Partition[faces, 1]];
Graphics3D[GraphicsComplex[pts2, Polygon[intersectingFacets]]]

There is not much that can be done about this. I have informed the TetGen developer. Sorry about that.

enter image description here

share|improve this answer
    
Thanks for this. I edited the answer (maybe you'll notice what changed) :) –  RunnyKine Jul 21 at 14:27
1  
@RunnyKine, thanks for that - it's an open secret I guess :-) –  user21 Jul 21 at 14:37
    
Can you comment on the inability of VoronoiMesh to handle 3D data? Is it coming anytime soon, perhaps in a point update? –  RunnyKine Jul 21 at 15:57
    
@RunnyKine, it's being discussed but I can not say how hard or long it is do get implemented. It's always good to send such requests to the support. If there is a large enough interest, then it might get done quicker.... –  user21 Jul 21 at 16:35

In the current release, you can try the following:

pf = {Cos[u], Sin[u] + Cos[v], Sin[v]};

gr = ParametricPlot3D[pf, {u, 0, 2 Pi}, {v, -Pi, Pi}];

mr = DiscretizeGraphics[gr // Normal]

enter image description here

Disregard the message about Lighting not supported, DiscretizeGraphics[gr //Normal] will remove the duplicated points

Now this will work:

ConvexHullMesh[MeshCoordinates[mr]]

enter image description here

share|improve this answer

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.