Consider the list of points
pts = {{1, 1}, {1, 2}, {2, 1}, {2, 2}}
I want to use them to define a 2x2 square mesh using VoronoiMesh
, where each cell has two neighbours. Following the discussion in this question, consider the following code
mesh = VoronoiMesh[pts, ImageSize -> Medium];
conn = mesh["ConnectivityMatrix"[2, 1]];
adj = conn.Transpose[conn];
centers = PropertyValue[{mesh, 2}, MeshCellCentroid];
g = AdjacencyGraph[adj, PlotTheme -> "Scientific",
VertexCoordinates -> centers];
Show[mesh, g]
As one can see, unlike other meshes, this one does not seem to work exactly as I want, since the diagonal edge should not appear. Why is this happening? Any way of avoiding that edge and get
as one would expect from a square lattice?
Edit: As noticed in the comment section, some of the polygons seem to have sharing edges that are single points, which is enough for them to be considered neighbouring cells. This effect is unchanged with the size of the lattice. If I consider, for example, the points
pts = Flatten[Table[{i, j}, {i, 7}, {j, 5}], 1];
I get
Any ideas on how to solve this? Maybe omit the extra edge in a way that doesn't this or other non-square meshes. For example, considering a random VoronoiMesh
, nothing seems to wrong, though it could, theoretically, go
In[52]:= MeshCells[mesh, 2] Out[52]= {Polygon[{4, 1, 3, 6}], Polygon[{5, 1, 2, 9}], Polygon[{7, 3, 1, 1, 5}], Polygon[{8, 2, 1, 1, 4}]}
. But notice1
is repeated twice...so structurally they share an edge, but that 'edge' is really just a point. $\endgroup$1
in a reasonably natural manner? So that it wouldn't affect other possible meshes? $\endgroup$IGMeshCellAdjacencyGraph[mesh, 2]
. You may also want to addVertexCoordinates -> Automatic
$\endgroup$