I have the following problem, which can be stated geometrically as follows:
List all pairs of vertex coordinates in a mesh region of measure 2 (a surface consisting of triangles) where these points are on two triangles sharing an edge, and where these resulting vertex points are not on the shared edge.
Best I came around with is the following:
With[{mesh = DiscretizeRegion[Rectangle[], MaxCellMeasure -> 1/9]},
Function[line,
Select[MeshPrimitives[mesh, 2],
MemberQ[Sort /@ Partition[First@#, 2, 1, 1], line] &] //
If[Length@# == 2, Complement[Flatten[#[[All, 1]], 1], line],
Nothing] &]@*Sort@*First /@ MeshPrimitives[mesh, 1] //
Show[mesh, Graphics[{Red, Line@#}]] &]
Frankly, I'm not at all pleased of all the munging and unintuitiveness on my code, which looks for all lines on the mesh, then finds all pairs of triangles sharing it as an edge (note Sort
unintuitiveness there!), and then excludes the vertices on the shared side before spitting out the result. Surely there would be a more intuitive way to do this?
Another way to formulate this problem would be to consider the mesh to be a (well-behaved, planar) graph, and query for all pairs of neighboring vertices on the dual graph, and to extract desired "real" triangle vertices from there. Is making such a query even possible in an efficient manner with Mma built-in graph functionality? (I doubt it.)