I am looking to recreate the following image from this reference as
using Mathematica's Polygon documentation under "Applications" as a starting point. I want to eventually use Mathematica to visualize the evolution of multi-colored Langton's ant on a hexagonal grid (not too important). In working to create the z = 0
row (shown in the above image as blue 0's) using Polygon
and Graphics
. I generate a hexagon using Mathematica's example with a Pi/6
rotation as follows:
rotatePoint[c_, p_, θ_] := {
(p[[1]] - c[[1]]) Cos[θ] - (p[[2]] - c[[2]]) Sin[θ] + c[[1]],
(p[[1]] - c[[1]]) Sin[θ] + (p[[2]] - c[[2]]) Cos[θ] + c[[2]]
}
hexagonPoly[x_, y_] :=
Polygon[
Table[rotatePoint[{x, y}, {Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y}, Pi/6],
{k, 6}]]
to create a polygon at the center of {x, y}
with side-length 1 rotated appropriately. I then look to create a row of these polygons evenly spaced so that their sides are touching as in the above image 2. For this I am thinking that each center will be 2r
away from the adjacent centers' where r
is defined as the length from the center point to the center of the side and is Sqrt[3]/2 * t
where t
is the side length as defined from Wikipedia. Therefore, I am trying to create hexagons where ith hexagon is Sqrt[3] * i
away from {0,0}
. To accomplish this I have the following code
hexgrid[xrange_, yrange_] :=
Table[hexagonPoly[x + x*Sqrt[3], 0], {x, xrange[[1]], xrange[[2]]}]
Graphics[{EdgeForm[Opacity[1]], LightRed, hexgrid[{0, 2}, {0, 0}]},
Frame -> True]
which produces the following output
I think that my maths are "solid" here in how I want to layout the polygons but I cannot seem to get them in the right configuration. How can I get my hexagons to touch at the edges in a row as such where I create a polygon based on where the center point should be (which I'd calculate based on the side-length of each hexagon)?
Thank you in advance! I am not proficient in Mathematica so I believe my error to be how I'm programming but it could be that I've missed something obvious in the problem and my code is correct :)
CirclePoints
than make the points up yourself:With[{rm = RotationMatrix[30 Degree]}, Graphics[{EdgeForm[Black], FaceForm[Red], Polygon[rm.# & /@ CirclePoints[6]]}] ]
$\endgroup$CirclePoints[6]
then creates a Polygon object from that? $\endgroup$Polygon[CirclePoints[{1, Pi/6}, 6]]
... $\endgroup$