# How do I plot a series of disks in the center of each hexagon?

I am trying to put a series of disks at the center of each hexagon, but I could center only 1. How do I center all of the disks at the center of each hexagon?

Here is the code I am using.

h[x_, y_] := Polygon[Table[{Cos[2 Pi k/6] + x, Sin[2 Pi k/6] + y}, {k, 6}]]
p1 = Graphics[{EdgeForm[Opacity[.7]], White, Table[h[3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j], {i, 0, 1}, {j, 0,3}]}];
Show[p1, Table[Graphics[Disk[{i, j}, {0.25, 0.25}]], {i, 0, 2, 1.5}, {j, 0, 2, 1.5}]]


Here is my result:

• I do this might seem trite and still, wouldn't the solution have been more obvious if you'd thought about "How to plot a disk in the center of each hexagon?" – Robbie Goodwin Jun 7 at 23:33

Just reuse the expression for the x and y components that you used when centering the hexagons:

Table[
Graphics[Disk[{3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j}, {0.25, 0.25}]],
{i, 0, 1},
{j, 0, 3}
]


This gives you:

Clear["Global*"]


You can use CirclePoints to define the Polygon

h[x_, y_] := Polygon[{x, y} + # & /@ CirclePoints[6]]


EDIT: As pointed out in the comment by J.M., using RegularPolygon this can be simplified to

h[x_, y_] := RegularPolygon[{x, y}, 1, 6]


The common center points are

ctrs = Table[
{3 i + 3 ((-1)^j + 1)/4, Sqrt[3]/2 j},
{i, 0, 1}, {j, 0, 3}] //
Flatten[#, 1] &;


Map Polygon and Disk onto the centers.

Graphics[{
EdgeForm[Opacity[.7]], {
White, h @@ #,
Black, Disk[#, 0.25]} & /@
ctrs}]


• Of course, your h[x, y] is the same as RegularPolygon[{x, y}, 1, 6]. – J. M.'s technical difficulties Jun 6 at 15:52

1. You can post-process your p1 to add disks at RegionCentroid of polygons:

p1 /. p_Polygon:> {p, FaceForm[Black], Disk[RegionCentroid @ p, {1, 1} / 4]}


2. Alternatively, you can create a single disk/hexagon pair centered at {0, 0}

prims = {Black, Scale[Disk[], {1, 1}/4],
EdgeForm[Gray], FaceForm[], RegularPolygon[{0, 0}, 1, 6]};


and Translate it using centers:

centers = {3 # + 3 (1 + (-1)^#2)/4, Sqrt[3] #2/2} & @@@
Tuples[{{0, 1}, Range[0, 3]}];

Graphics[Translate[prims, #] & /@ centers]
`