14

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:

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

RunnyKine
  • 33,088
  • 3
  • 109
  • 176

2 Answers2

9

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

user21
  • 39,710
  • 8
  • 110
  • 167
  • Thanks for this. I edited the answer (maybe you'll notice what changed) :) – RunnyKine Jul 21 '14 at 14:27
  • 1
    @RunnyKine, thanks for that - it's an open secret I guess :-) – user21 Jul 21 '14 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 '14 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 '14 at 16:35
  • Well, the question of OP is 5 years ago, these days in mathematica 12.0, I encounter with this problem. – HyperGroups Jan 10 '20 at 08:42
  • @HyperGroups, in version 12.0 ConvexHullMesh[pts] works just fine for me. – user21 Jan 10 '20 at 09:15
  • https://mathematica.stackexchange.com/a/212842/6648 maybe you can try this data. – HyperGroups Jan 14 '20 at 03:22
  • @HyperGroups, works fine for me. You should report this then to WRI at support@wolfram.com. Someone there can help you track the issue down. – user21 Jan 14 '20 at 06:50
  • OK, I've reported, the data copied also works fine for me, so I deleted it. Maybe it like the operation of npts = pts + RandomReal[10^-6*{-1, 1}, {Length[pts], 3}]; I uploaded the sample data here, if you are interest. Any way, thank for your solution. https://github.com/HyperGroups/Mathematica/blob/master/Bug%26%26Problem/ConvexHullMesh%E7%9A%84%E4%B8%80%E4%BA%9B%E9%97%AE%E9%A2%98%40Problems%4012.0/%E6%97%A0%E6%B3%95%E8%AE%A1%E7%AE%97%E7%9A%84%E4%B8%80%E4%B8%AA%E9%97%AE%E9%A2%98%40CalculateFailed%40ConvexHullMesh/data%40ConvexHullMeshFailed.wdx – HyperGroups Jan 15 '20 at 08:34
3

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

Öskå
  • 8,587
  • 4
  • 30
  • 49
user18673
  • 131
  • 2