1
$\begingroup$

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.

$\endgroup$
0
2
$\begingroup$

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],
  1]

Then,

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

enter image description here

$\endgroup$
6
  • $\begingroup$ But why not just generate it efficiently, i.e., directly? What's the value in iteration? $\endgroup$ May 14 '19 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
    May 14 '19 at 4:57
  • $\begingroup$ No no... not you. I was implicitly asking the OP. $\endgroup$ May 14 '19 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
    May 14 '19 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
    May 14 '19 at 18:18

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.