My unordered adjacency list of nodes with their 2D coordinates:
adjacency_list = [[1, 4], [0, 2, 5], [1, 3, 7], [2, 6, 12],
[5, 0, 11], [4, 1, 7, 13], [3, 15, 8],
[2, 5, 12, 14], [6, 9, 16], [8, 10, 17],
[9, 19], [4, 13, 18], [7, 15, 3], [5, 11, 14, 20],
[7, 13], [6, 12, 16], [8, 15, 17], [16, 9, 19, 22],
[11, 20, 21], [10, 17, 24], [13, 18, 23], [18, 23, 27],
[17, 24, 28], [20, 21, 25, 30], [19, 22, 31],
[23, 26, 32], [25, 29, 34], [21, 30, 35], [22, 31, 36],
[26, 33, 37], [23, 27, 32, 38], [24, 28, 39],
[25, 30, 34, 40], [29, 36, 41], [26, 32, 37, 42],
[27, 38], [33, 43, 39, 28], [29, 34, 41, 44],
[30, 35, 40], [31, 36, 45], [32, 38, 42],
[33, 37, 43, 46], [34, 44, 40], [36, 41, 45],
[46, 37, 42], [39, 43], [41, 44]]
centers = [(1023, 763), (902, 742), (776, 718), (629, 681),
(1041, 673), (924, 651), (479, 643), (799, 625),
(329, 620), (180, 599), (41, 581), (1051, 580),
(653, 580), (937, 556), (810, 529), (498, 529),
(340, 509), (188, 491), (1059, 490), (47, 470),
(943, 463), (1059, 393), (195, 386), (941, 365),
(54, 361), (814, 339), (663, 311), (1055, 294),
(201, 286), (509, 285), (933, 262), (62, 256),
(806, 234), (357, 232), (657, 199), (1043, 189),
(210, 185), (507, 167), (925, 157), (74, 149),
(798, 128), (360, 122), (652, 88), (219, 79),
(507, 53), (87, 41), (364, 11)]
When I plot them using these coordinates I get a deformed grid:
I want to determine the connectivity of the nodes in a regular grid (find their locations on a structured 2D grid):
I found a possible solution. To program this in Python my idea is to find the diagonals for every node and then resolve the connectivity between neighboring nodes. I’m looking for a more detailed approach to map the nodes to a regular grid based on the adjacency (and the 2D coordinates if necessary).
My plot already shows the vertices arranged as I want. However, this does not tell me how any given node is connected to others. I can see that node 1 is connected west to node 2, south to node 5, and east to node 0. If I know that node 1 is at position (6,0) in a regular grid I can determine its neighbors at (5,0), (6,1), and (7,0). I’d like to avoid heuristic approaches based on angles or distances in a deformed grid since in my final application the grid can be distorted, with angles greater than 45°.
A simpler example to show the algorithmic idea:
I start at node 0 knowing it is connected to 1 in east direction and connected to 3 in south direction. If we look for common neighbors between pairs of neighbors of node 1, we find node 4 (a diagonal node). Since nodes 0, 1, 4, and 3 form a quadrilateral face and node 0 is connected east to 1 and south to 3, we can deduce that:
- node 1 is connected west to 0 and south to 4,
- node 3 is connected north to 0 and east to 4.
If we move to a neighbor of node 0 (node 1), we find that node 3 is a diagonal (in the quadrilateral 0, 1, 4, 3) and so is node 5 (in quadrilateral 1, 2, 5, 4).
- In the first case we already know that node 0 is connected east to 1 and south to 3. From this we deduce that node 4 is connected west to 3 and north to 1.
- In the second case with diagonal node 5, we only know that node 1 is connected south to 4. At this point node 2 could be either west or east of node 1. But since node 1 is already connected west to 0, node 2 must be east.
Therefore:
- node 2 is connected west to 1 and south to 5,
- node 4 is connected north to 1 and east to 5.


