Pretty knew to Mathematica here. I have created a code stemming from a basic function that I found here in the stack exchange. I am basically making three different hexagonal lattices. Two of them are rotated with respect to the [un]-rotated one. There are two different angles of rotation, but what they are is not relevant. My code is the following:
\[Theta]tm = 5;
\[Theta]mb = -5;
unitcell[x_, y_] := {Black, Disk[{x, y}, 0.05], Black,
Disk[{x, y + 2/3 Sin[120 Degree]}, 0.05],
, Black, Line[{{x, y}, {x, y + 2/3 Sin[120 Degree]}}],
Line[{{x, y}, {x + Cos[30 Degree]/2, y - Sin[30 Degree]/2}}],
Line[{{x, y}, {x - Cos[30 Degree]/2, y - Sin[30 Degree]/2}}]}
Rtm[\[Theta]_] = {{Cos[\[Theta]*Pi/360.], -Sin[\[Theta]*Pi/360.]},
{Sin[\[Theta]*Pi/360.], Cos[\[Theta]*Pi/360.]}};
topmoire[x_, y_] := {Red, Disk[Rtm[\[Theta]tm] . {x, y}, 0.05], Red,
Disk[Rtm[\[Theta]tm] . {x, y + 2/3 Sin[120 Degree]}, 0.05],
, Red, Line[{Rtm[\[Theta]tm] . {x, y},
Rtm[\[Theta]tm] . {x, y + 2/3 Sin[120 Degree]}}],
Line[{Rtm[\[Theta]tm] . {x, y},
Rtm[\[Theta]tm] . {x + Cos[30 Degree]/2, y - Sin[30 Degree]/2}}],
Line[{Rtm[\[Theta]tm] . {x, y},
Rtm[\[Theta]tm] . {x - Cos[30 Degree]/2, y - Sin[30 Degree]/2}}]}
Rmb[\[Theta]_] = {{Cos[\[Theta]*Pi/360.], -Sin[\[Theta]*Pi/360.]},
{Sin[\[Theta]*Pi/360.], Cos[\[Theta]*Pi/360.]}};
bottommoire[x_, y_] := {Green, Disk[Rtm[\[Theta]mb] . {x, y}, 0.05],
Green, Disk[Rtm[\[Theta]mb] . {x, y + 2/3 Sin[120 Degree]}, 0.05],
, Green,
Line[{Rtm[\[Theta]mb] . {x, y},
Rtm[\[Theta]mb] . {x, y + 2/3 Sin[120 Degree]}}],
Line[{Rtm[\[Theta]mb] . {x, y},
Rtm[\[Theta]mb] . {x + Cos[30 Degree]/2, y - Sin[30 Degree]/2}}],
Line[{Rtm[\[Theta]mb] . {x, y},
Rtm[\[Theta]mb] . {x - Cos[30 Degree]/2, y - Sin[30 Degree]/2}}]}
middle = Graphics[
Block[{A = {Cos[120 Degree], Sin[120 Degree]}, B = {1, 0},
C = {-1, 0}},
Table[unitcell @@ (A j + B k + C l), {j, -20, 20}, {k,
Ceiling[j/2], 20 + Ceiling[j/2]}, {l, Ceiling[j/2],
20 + Ceiling[j/2]}]], ImageSize -> 500];
top = Graphics[
Block[{A = {Cos[120 Degree], Sin[120 Degree]}, B = {1, 0},
C = {-1, 0}},
Table[topmoire @@ (A j + B k + C l), {j, -20, 20}, {k,
Ceiling[j/2], 20 + Ceiling[j/2]}, {l, Ceiling[j/2],
20 + Ceiling[j/2]}]], ImageSize -> 500];
bottom = Graphics[
Block[{A = {Cos[120 Degree], Sin[120 Degree]}, B = {1, 0},
C = {-1, 0}},
Table[bottommoire @@ (A j + B k + C l), {j, -20, 20}, {k,
Ceiling[j/2], 20 + Ceiling[j/2]}, {l, Ceiling[j/2],
20 + Ceiling[j/2]}]], ImageSize -> 500];
Show[top, middle, bottom]
I was having trouble superimposing the three lattices on top of each other. For this I used
Show[top,middle,bottom]
However, in order to center the lattices at the origin, I had to introduce another vector within the function Table
, the vector "C" multiplied by "l". I think this has made my code crash everytime I try to run it. Is there another efficient way to either center the lattices on the origin of rotation with only two vectors, or perhaps a replacement of the Table
function?
Also, while this is not urgent, and not as important. I would like to know how to generalize this code in order to depend on a position argument, i.e. "r" where I can tweak how big (unit of length) I want the lattice to be (in x and y directions).