Background: I want to imply periodicity along the given edges for a graph. For example in a square lattice with identifying parallel edges, you can construct a torus. consider the following image
So I start with the construction of a square lattice network
nmax = 15;(*Length of lattice*)
points = Flatten[Table[{i, j}, {i, -nmax, nmax}, {j, -nmax, nmax}],
1];(*list coordinate of the lattice*)
d1 = (Sqrt[2] + 1)/2;(*Max distance to construct linked between coordination of the lattice*)
d0 = 1/2;(*Min distance to construct linked between coordination of the lattice*)
nn = Nearest[points -> "Index"];
(*function which determine the nearest of a vertex. we can do this*)
(*also by for example DistanceMatrixor or NearestNeighborGraph*)
ha = Select[
Flatten[ParallelTable[Module[{pp}, pp = nn[points[[i]], {10, d1}];
Select[{i + 0 pp, pp,
Norm /@ ((points[[pp]]\[Transpose] -
points[[i]])\[Transpose])}\[Transpose],
d1 > #[[3]] &][[All, {1, 2}]]], {i, 1, Length[points]}],
1], #[[1]] > #[[2]] &];
(*I use select to just consider one linke between two vortex ,*)
(*This part is somehow hard to catch at a glince but it did not *)
(*change following discussion. Consider this line as a function*)
(*making nearest neighbor links*)
Graph3D[ha]
where gives,
now I am looking to identifying edges. I use the following, for the left and right one
vortexL =points//SortBy[Flatten[Position[#[[All, 1]], Max[#[[All, 1]]]]], points[[#, 2]] &] &;
vortexR =points//SortBy[Flatten[Position[#[[All, 1]], Min[#[[All, 1]]]]],points[[#, 2]] &] &;
and for up and down edge we have
vortexU =points//SortBy[Flatten[Position[#[[All, 2]], Max[#[[All, 2]]]]], points[[#, 1]] &] &;
vortexD =points//SortBy[Flatten[Position[#[[All, 2]], Min[#[[All, 2]]]]],points[[#, 1]] &] &;
now i define identifier as
vchanger = {Table[vortexL[[i]] -> vortexR[[i]], {i, 1, Length@vortexL}],Table[vortexU[[i]]-> vortexD[[i]], {i, 1, Length@vortexU}]};
By applying it on ha (the link address) sequentially you can see how periodicity along those edges established,
ha = ha /. vchanger[[1]];
Graph3D[ha]
and
ha = ha /. vchanger[[2]];
Graph3D[ha]
where gives,
although it seems torus, by rotation it, you notify two crossings of the links
Question? So I am wondering, I did a mistake to construct the lattice and implication of periodic boundary condition, or this is the problem of Mathematica? Do someone has an option for Graph3D to make it correct shape?
Update My problem is almost the visualization of correct geometry this lattice has.