Given a triangular lattice which grows with number n
, as follows
I want to list all the connected points in the lattice to form the pairlist
. As an example:
n=1:
pairlist={{p_{1},p_{2}},{p_{1},p_{3}},{p_{2},p_{3}}}
n=2:
pairlist={{p_{1},p_{2}},{p_{1},p_{4}},{p_{2},p_{3}},{p_{2},p_{4}},{p_{2},p_{5}},{p_{3},p_{5}},{p_{4},p_{5}},{p_{4},p_{6}},{p_{5},p_{6}}}
n=3:
pairlist={{p_{1},p_{2}},{p_{1},p_{5}},{p_{2},p_{3}},{p_{2},p_{5}},{p_{2},p_{6}},{p_{3},p_{4}},{p_{3},p_{6}},{p_{3},p_{7}},{p_{4},p_{7}},{p_{5},p_{8}},{p_{5},p_{6}},{p_{6},p_{8}},{p_{6},p_{9}},{p_{6},p_{7}},{p_{7},p_{9}},{p_{8},p_{10}},{p_{8},p_{9}},{p_{9},p_{10}}}
Notice that there is no need to list the elements in pairlist
in order.
Questions:
- Is there some automatical way to do above tasks?
- If I have
points= Flatten[Table[Subscript[p, i], {i, 1, Binomial[n + 2, 2]}]];
, how can I create the triangle lattice withpoints
automatically?
For Question-2, I make one code for n=2
in the below (is there any simple and general way for different n
?).
pairlists = {};
n = 2;
points = Flatten[Table[Subscript[p, i], {i, 1, Binomial[n + 2, 2]}]];
For[ii = 1, ii <= Length[points], ii++,
For[jj = ii + 1, jj <= Length[points], jj++,
If[(Abs[points[[ii]][[2]]-points[[jj]][[2]]]==1&&ii != 3) ||(Abs[points[[ii]][[2]]-points[[jj]][[2]]]==2&&Abs[ii-jj]==2&& ii!=1 )||(Abs[points[[ii]][[2]]-points[[jj]][[2]]]==3&&Abs[ii-jj]==3&&ii!=3),
AppendTo[pairlists, {points[[ii]], points[[jj]]}];
]
];
]