1
$\begingroup$

Consider the following code

n = 6;
hexagon[x_, y_] := 
  Polygon[Table[{x, y} + {Sin[2 Pi j/6], Cos[2 Pi j/6]}, {j, 0, 5}]];
hexagoncenter = 
  Flatten[Table[{Sqrt[3] i + Sqrt[3]/2 j, 3/2 j}, {j, 0, n - 1}, {i, 
     0, n - j - 1}], 1];
hexagondist = Norm /@ hexagoncenter;
hexagonlist = hexagon[Sequence @@ #] & /@ hexagoncenter;
hassoc = Association @@ (#[[1, 1]] -> #[[All, 2]] & /@ 
     GatherBy[Transpose[{hexagondist, hexagonlist}], First]);
coloredHexagons = 
  KeyValueMap[
   Function[{key, hexagons}, {ColorData["DarkRainbow"][RandomReal[]], 
     hexagons}], hassoc];
slice = Graphics[{EdgeForm[{Thick, Transparent}], coloredHexagons}]

enter image description here

When I export it as a PDF file, I get a strange overlapping of the hexagons, as seen in this zoomed picture

enter image description here

Any idea as to why this happens? I suspect it might have to do with how the Edge is setup, but I am not sure. Any ideas?

$\endgroup$
1
  • 2
    $\begingroup$ This bug have been fixed in $Version >= 13.3.1. $\endgroup$
    – cvgmt
    Commented Feb 17 at 7:28

1 Answer 1

2
$\begingroup$

As a workaround:

gr = Graphics[{RandomColor[], 
     GeometricTransformation[#, 
      ScalingTransform[{0.976, 0.976}, RegionCentroid@#]]} & /@ 
   hexagonlist]

Export["C:/polygons.pdf", gr]

Prior to coming up with this workaround, I extracted all the intersecting lines between all polygons, plotted them and exported them.

ilines = (Tuples[hexagonlist, 2] // 
     Map[Apply[RegionIntersection]]) /. _EmptyRegion :> 
    Nothing /. _Polygon :> Nothing

Export["C:/ilines.pdf", Graphics[{ilines}]]

These show up at 6400% zoom on Acrobat without a problem; so as a workaround, I have scaled all the polygons slightly and thus the magic number 0.976 came about.

$\endgroup$

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