4
$\begingroup$

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?

$\endgroup$
  • 4
    $\begingroup$ Possible duplicate of How to create an hexagonal lattice structure $\endgroup$ – yarchik May 7 '19 at 12:45
  • 2
    $\begingroup$ A honeycomb lattice with the centers filled in is also called a triangular lattice; the question becomes what do you want to do about the boundaries? $\endgroup$ – evanb May 7 '19 at 13:06
5
$\begingroup$

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

$\endgroup$
  • $\begingroup$ 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 $\endgroup$ – lio May 14 '19 at 16:24
  • $\begingroup$ @lio I fixed the algorithm. now everything is fine $\endgroup$ – J42161217 May 14 '19 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.