Hello, The problem of finding the coordinates of a triangular (equilateral) mesh discussed earlier is solved. It also counts the number of equilateral triangles formed by the intersecting parallel lines. But the problem is that the code takes more time for larger values of n i.e. the size of the side of the triangle. Can the code be improved? The code is given here. Thanks for any suggestion.
n = 4;
Print["Number of lines/size of triangle = ", n]
h = Sqrt[3] /2;
Array[x, n];
Array[s, n];
x[0] = {{n/2, n h}};
For[i = 1, i <= n, i++,
x[i] = Table[{x[0][[1, 1]] - i/2 + j, n h - i h}, {j, 0, i}]];
set = Apply[Union, Table[x[i], {i, 0, n}]];
Print["Number of vertices = ", Length[set]]
cond := (EuclideanDistance[#[[1]], #[[2]]] ==
EuclideanDistance[#[[2]], #[[3]]] ==
EuclideanDistance[#[[1]], #[[3]]] && #[[1]] != #[[2]] != #[[
3]] && #[[1, 1]] < #[[2, 1]] < #[[3,
1]] && (#[[1, 2]] == #[[2, 2]] || #[[2, 2]] == #[[3, 2]] || #[[
3, 2]] == #[[1, 2]]) &)
tr0 = Tuples[set, 3];
tr1 = Select[tr0, cond];
Print["Number of Triangles = ", Length[tr1]]