7

I found DelaunayMesh works fine for 2D. For example,

coordinateList = Tuples[{Range[3], Range[3]}];
DelaunayMesh[coordinateList, PlotTheme -> "Lines"]

gives

2D Delaunay triangulation

Oddly enough, it does not work for simple regular point array like below

coordinateList = Tuples[{Range[3], Range[3], Range[3]}];
DelaunayMesh[coordinateList, PlotTheme -> "Lines"]

which just prints out the original data like

DelaunayMesh[{{1, 1, 1}, {1, 1, 2}, {1, 1, 3}, {1, 2, 1}, {1, 2, 
   2}, {1, 2, 3}, {1, 3, 1}, {1, 3, 2}, {1, 3, 3}, {2, 1, 1}, {2, 1, 
   2}, {2, 1, 3}, {2, 2, 1}, {2, 2, 2}, {2, 2, 3}, {2, 3, 1}, {2, 3, 
   2}, {2, 3, 3}, {3, 1, 1}, {3, 1, 2}, {3, 1, 3}, {3, 2, 1}, {3, 2, 
   2}, {3, 2, 3}, {3, 3, 1}, {3, 3, 2}, {3, 3, 3}}, 
 PlotTheme -> "Lines"]

I have to jiggle each point a little to make DelaunayMesh work. Define

ClearAll[jiggleCoordinateList];
jiggleCoordinateList[coordinateList_, eta_] := Module[{},
  RandomReal[eta*{-1, 1}, Dimensions@coordinateList] + coordinateList
  ]

then

coordinateList = Tuples[{Range[3], Range[3], Range[3]}];
DelaunayMesh[jiggleCoordinateList[coordinateList, 0.00001], 
 PlotTheme -> "Lines"]

gives

Delaunay tetrahedralization of "jiggled" grid

But why is that? I can not think of a reason why a regular point array in 3D can not be DelaunayMeshed.

Though a jiggled mesh is fine for display, for calculations, a jiggled mesh is not the same as the original mesh and will introduce error (even though it is small, it is not perfect).

Is there any workaround other than jiggling coordinates?

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
matheorem
  • 17,132
  • 8
  • 45
  • 115

1 Answers1

7

As a workaround you can use the finite element mesh generator:

Needs["NDSolve`FEM`"]
coordinateList = Tuples[{Range[3], Range[3], Range[3]}];
MeshRegion[ToElementMesh[coordinateList], PlotTheme -> "Lines"]

enter image description here

user21
  • 39,710
  • 8
  • 110
  • 167
  • That is quite ironic for me. Because I was reading doc and tutorial of ToElementMesh all day and never thought it could directly support bare coordinate list. Thank you so much!! – matheorem Feb 03 '21 at 12:50
  • 2
    @matheorem, and that's a shortcoming; in the next version you can specify ToElementMesh["Coordinates" -> coords] and it will give you the Delaunay triangulation. If you have suggestions for improving the FEM documentation, let me know. – user21 Feb 03 '21 at 12:53
  • I do have other questions about FEM package. I will post later :) – matheorem Feb 03 '21 at 12:58
  • Hi, user21. I am wondering if I could directly control the mesh quality during ToElementMesh[coords]. I mean throw away triangles whose quality is below a threshold, So I won't have to do a postprocessing deleting work. I tried various options of ToElementMesh all failed. – matheorem Feb 04 '21 at 06:05
  • @matheorem, no that's not possible. The point of a Delaunay mesh is to connect a set of nodes, however, it does not fiddle with the position of them. – user21 Feb 04 '21 at 06:21
  • Yeah, I know the definition of Delaunay mesh is to generate triangles to span the largest space. But for interpolation on machine precision point array, the mesh frequenlty got many bad triangles at edges. So before deleting those bad triangles, the mesh is not usable for interpolation. – matheorem Feb 04 '21 at 06:29