# How can I select a specific triangle in my Delaunay mesh?

Here is the code I am working with. I create a list of random coordinates, then I create a triangular mesh with the code:

list = RandomInteger[{1, 10}, {10, 2}]
mesh = DelaunayMesh[
list,
MeshCellLabel -> {0 -> "Index"},
PlotTheme -> "Lines",
MeshCellHighlight -> {{1, All} -> Green, {0, All} -> Black},
Frame -> True
]


How can I select a specific triangle? For example, how can I select the triangle with vertices {10,7,2}.

Update: A more convenient version that allows the vertex indices in any order:

ClearAll[vToF]
vToF[vl : {__}] := KeyMap[ Sort, vertexToFace][Sort[vl]];

HighlightMesh[mesh, {Style[{2, vToF[{10, 9, 4}]}, Red],
Style[{2, vToF[{8, 1, 5}]}, Yellow]}]


SeedRandom[1]
list = RandomInteger[{1, 10}, {10, 2}];
mesh = DelaunayMesh[list, MeshCellLabel -> {0 -> "Index"},
PlotTheme -> "Lines",
MeshCellHighlight -> {{1, All} -> Green, {0, All} -> Black},
Frame -> True]


You can create an association mapping face vertices to face indices using the property "FaceVertexConnectivityRules":

vertexToFace = Association[Reverse /@ mesh["FaceVertexConnectivityRules"]]


<|{3, 8, 5} -> 1, {8, 3, 7} -> 2, {2, 5, 10} -> 3, {1, 5, 8} -> 4, {10, 5, 1} -> 5, {8, 9, 1} -> 6, {9, 7, 4} -> 7, {7, 9, 8} -> 8, {10, 4, 6} -> 9, {4, 10, 9} -> 10, {10, 6, 2} -> 11, {9, 10, 1} -> 12|>

HighlightMesh[mesh, Style[{2, vertexToFace[{3, 8, 5}]}, Red]]


• How did you know about the faces vertex coordinates rules? I couldn't find it in the documentation. Commented Jul 3, 2019 at 15:53
• @LasdesNestor Yes, these things are mostly undocumented. This is why Mathematica.StackExchange is so valuable: People try a lot of spelunking and also a few of the developers are around here. Commented Jul 3, 2019 at 15:58
• @LasdesNestor, try mesh["Properties"] to see a long list of properties. Since they are not documented it is by trial and luck that you discover quiet a few useful properties.
– kglr
Commented Jul 3, 2019 at 16:00
• Is there a way to extract that particular triangle, so I can compare them with the other ones? Let say that I select a triangle and I want to check if the triangle is part of the original plot. Commented Jul 3, 2019 at 17:33
• @LasdesNestor, the triangle (polygon) can be obtained using MeshPrimitives[mesh, {2,1}] or using MeshPrimitives[mesh, {2,vertexToFace[{3,8,5}]}].
– kglr
Commented Jul 3, 2019 at 18:06