Bug introduced in 10.0 and persisting through 10.2 or later

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:


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:


Mathematica graphics

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

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

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

If we go one step further and use

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

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,
pts = Cases[data, {_?NumericQ, _?NumericQ, _?NumericQ}];

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

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

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@
       "Table"][[2 ;; -2]][[All, {2, 3, 4}]];
faces = Developer`ToPackedArray@
      "Table"][[2 ;; -2]][[All, {2, 3, 4}]];
{pts2, intersectingFacets} = 
   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

  • $\begingroup$ Thanks for this. I edited the answer (maybe you'll notice what changed) :) $\endgroup$ – RunnyKine Jul 21 '14 at 14:27
  • 1
    $\begingroup$ @RunnyKine, thanks for that - it's an open secret I guess :-) $\endgroup$ – user21 Jul 21 '14 at 14:37
  • $\begingroup$ Can you comment on the inability of VoronoiMesh to handle 3D data? Is it coming anytime soon, perhaps in a point update? $\endgroup$ – RunnyKine Jul 21 '14 at 15:57
  • $\begingroup$ @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.... $\endgroup$ – user21 Jul 21 '14 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:


enter image description here


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.