4

I am using the follwing coder from here, answered by Michael E2, to create 2d lattice points, without the center ponts of the cells.

hexTile[n_, m_] := 
  With[{hex = 
     Table[{Cos[2 Pi k/6] + #, Sin[2 Pi k/6] + #2}, {k, 6}] &}, 
   Table[hex[3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j], {i, n}, {j, m}]];
factor = 12;
coordinates = Flatten[hexTile[4, 10], 2]*factor;
ListPlot[coordinates, AspectRatio -> Automatic]

enter image description here

One problem here is that double coordinates are produced, which I don't need:

Length@coordinates
240

Length@DeleteDuplicates@coordinates
106

How can I modify the function hexTile[n_, m_] that no double coordinates are produced and how can I add center points to the hexagonal cells?

lio
  • 2,396
  • 13
  • 26

1 Answers1

5

try this

hexTile[n_,m_]:=With[{hex=Join[t=Table[{Cos[2 Pi k/6]+#,Sin[2 Pi k/6]+#2},{k,6}],
{Median@t}]&},Table[hex[3 i+3 ((-1)^j+1)/4,Sqrt[3]/2 j],{i,n},{j,m}]];
factor=12;
coordinates=Union@Flatten[hexTile[4,10],2]*factor;
ListPlot[coordinates,AspectRatio->Automatic]    

enter image description here

ZaMoC
  • 6,697
  • 11
  • 31
  • Please see my updated question. Do you know why there are a lot of duble coordinates produced? I find for your solutionLength@coordinates = 280 and Length@DeleteDuplicates@coordinates = 146 – lio May 14 '19 at 16:24
  • @lio I fixed the algorithm. now everything is fine – ZaMoC May 14 '19 at 16:52