My main purpose is to eventually generate a triangle lattice from one original point, let's say the origin. So I want to start with the origin and generate 6 points around it, which are the vertices of an hexagon of side with length 1. Then, I would like to have those new six points to do the same and generate six other points (I know there will be repetitions). Then, I want those points to from a triangle lattice, but I am new to mathematica.

So far I constructed a function that generates the vertices of an hexagon:

h[x_, y_] := Point[Table[{Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y}, {k, 6}]]

Now i am looking to generate the other poits from my new ones.


1 Answer 1


You could do it recursively like this:

h[x_, y_, 0] := Table[{Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y}, {k, 6}]
h[x_, y_, n_] := DeleteDuplicates@Flatten[
   Table[{Cos[2 Pi k/6] + #1, Sin[2 Pi k/6] + #2}, {k, 6}] & @@@ h[x, y, n - 1],


Graphics@Point@h[0, 0, 2]

enter image description here

  • $\begingroup$ But why not just generate it efficiently, i.e., directly? What's the value in iteration? $\endgroup$ Commented May 14, 2019 at 4:52
  • $\begingroup$ @DavidG.Stork. Mainly because I was just following along on what the OP was asking. Clearly there are faster ways of doing this, but since the OP doesn't mention speed as a requirement, I figured it wasn't necessary (and this method can generate 1400 points in half a second). Finally, I couldn't quickly come up with a direct way that would yield a result that looks like a hexagon (as shown). I always end up getting points in a rectangular region. $\endgroup$
    – march
    Commented May 14, 2019 at 4:57
  • $\begingroup$ No no... not you. I was implicitly asking the OP. $\endgroup$ Commented May 14, 2019 at 5:06
  • $\begingroup$ Because I want to control the amount of iterations i would like to get. By the way, i am really thankful to you for helping me! Could you explain me what «@» is used for? $\endgroup$
    – user65572
    Commented May 14, 2019 at 17:33
  • $\begingroup$ @user65572. f@x is the same as f[x] (aside from operator precedence issues). I could have just as easily done DeleteDuplicates[Flatten[ ... ] ]. $\endgroup$
    – march
    Commented May 14, 2019 at 18:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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