# Is there a way in TikZ to reflect regular polygons of an arbitrary number of edges?

Is there a way in TikZ to reflect regular polygons of an arbitrary number of edges, along each edge-considered-as-mirror?

I'm using MacTeX, and I'm new to LaTeX, pgf and TikZ.

I'd like to do this to demonstrate a geometric construction that can be done using reflections, with polygons of an arbitrary number of edges.

For some polygons (e.g. triangles and hexagons), this can be iterated to generate a tessellation of the plane. (Others have asked about hexagonal tilings, etc.)

Ideally, I'd like to be able simply to reference an edge, generate a line coincident with it, and provide the line as an argument to a subroutine that can perform the reflection of the polygon along the line through that edge.

This reflection can be simulated by rotations and translations, but I'd like to avoid the translations altogether (and the translation distance computations in (x,y) coordinates, or even in polar coordinates). This is to have the code also serve as a demonstration of the principles of construction, not just the graphics. For polygons of an odd number of edges n, a rotation of 180/n is needed before translation; for polygons of an even number of edges, such rotation is not needed.

I've tried referencing nodes of superposed constructions to re-center the effectively-reflected polygons, but my references didn't seem to work. I've also tried what I'd thought were planar coordinates (ordered pairs) based on a radial coordinate system, which I'd taken from an example, but they didn't work as expected in my code.

• Welcome to TeX.SE. It is always best to compose a MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. In this case you could at least provide the code to produce the original polygon. – Peter Grill Nov 12 '11 at 4:28

Regular polygons can be drawn after loading the shapes.geometric library by using something like \node (<name>) [regular polygon, regular polygon sides=5, draw] {} for a pentagon. The corners of the polygon are then available as (<name>.corner <n>), and the midpoints of the sides as (<name>.side <n>).

To reflect the corners along a line coincident with a side, you can use a combination of two TikZ functions: The let syntax, which allows you to temporarily store a point in a macro, and the calc library, with which you can perform coordinate calculations.

Here's a pentagon with the corners labeled: \node (A) [draw,regular polygon, regular polygon sides=5, minimum size=2cm,outer sep=0pt] {};
\foreach \n in {1,...,5} {
\node at (A.corner \n) [anchor=360/5*(\n-1)+270] {\scriptsize\texttt{A.corner \n}};
}


Now say you want to mirror corner 4 on the line passing through corner 1 and corner 2. TikZ doesn't provide a mirror operation directly, but you can use the projection syntax for this. Coordinate calculation expressions are surrounded by ($...$), and the projection syntax is (<first coordinate)!(<projection coordinate>)!(<second coordinate>), so the projection of corner 4 on the line passing through corners 1 and 2 can be expressed as

($(A.corner 1)!(A.corner 4)!(A.corner 2)$) If we call that point Q, the reflection of corner 4 (let's call that point C4) can be expressed as C4' = Q - (C4 - Q) = 2*Q - C4. In TikZ notation, this would look like

($2*($(A.corner 1)!(A.corner 4)!(A.corner 2)$) - (A.corner 4)$)


In order to do this for all corners of the polygon, we can use a \foreach loop. To make the code a little more readable, the points A.corner 1 and A. corner 2 can be saved into temporary macros using the let syntax. Finally, the whole thing can be wrapped into a TikZ style.

The lines

\node (A) [polygon=5, thick] {};
\draw [blue,mirror polygon=1];
\draw [orange,mirror polygon=2];
\draw [red,mirror polygon=3];
\draw [cyan,mirror polygon=4];
\draw [purple,mirror polygon=5];


will yield and the lines

\node (A) [polygon=3, thick] {};
\draw [blue,mirror polygon=1];
\draw [orange,mirror polygon=2];
\draw [red,mirror polygon=3];


will yield Here's the complete code:

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes.geometric, calc}

\begin{document}
\begin{tikzpicture}
\tikzset{
polygon n/.code=\gdef\polygonN{#1}, % Save N in a global macro
polygon/.style={
regular polygon,
regular polygon sides=#1,
polygon n=#1,
draw,
minimum size=2cm,
outer sep=0pt
},
mirror polygon/.style={
insert path={
let \p1 = (A.corner #1),
\p2 = (A.side #1) in (\p1)
($2*($(\p1)!(A.corner 1)!(\p2)$) - (A.corner 1)$) % Path needs to be started before the foreach
\foreach \n in {2,...,\polygonN} {
-- ($2*($(\p1)!(A.corner \n)!(\p2)$) - (A.corner \n)$)
} -- cycle
}
}
}

\node (A) [polygon=5, thick] {};
\draw [blue,mirror polygon=1];
\draw [orange,mirror polygon=2];
\draw [red,mirror polygon=3];
\draw [cyan,mirror polygon=4];
\draw [purple,mirror polygon=5];
\end{tikzpicture}
\end{document}

• How to draw apothem – casio Jan 14 '17 at 1:02
• @Anony-Mousse How to draw apothem, if i use \node (<name>) [regular polygon, regular polygon sides=5, draw] {} – casio Jan 14 '17 at 1:02

run texdoc pst-cox for the documentation of creating regular polytopes. A simple example, run with xelatex:

\documentclass{minimal}
\usepackage{pst-coxcoor}
\begin{document}
\begin{pspicture}(-4,-4)(4,4)
\CoxeterCoordinates[linewidth=0.1mm,choice=33]
\end{pspicture}
\end{document} • As the question is about Tikz, a preamble in the answer explaining this is an alternative approach would be useful. – Joseph Wright Nov 12 '11 at 19:19

Similar to Jake’s solution but with my qrr.trans library (, ).

## Code

\documentclass[tikz]{standalone}
\usetikzlibrary{shapes.geometric,qrr.trans}
\tikzset{
reg poly/.style={shape=regular polygon, regular polygon sides={#1}, outer sep=+0pt}}
\tikzset{
unreg poly/.style={/utils/exec=\def\myPolygonCounter{1},
@unreg poly/.list={#1,(unreg poly-corner 1)}, insert path={-- cycle}},
@unreg poly/.style={
insert path={coordinate         (unreg poly-corner \myPolygonCounter)
-- coordinate[midway] (unreg poly-side \myPolygonCounter) #1},
/utils/exec=\pgfmathtruncatemacro\myPolygonCounter{\myPolygonCounter+1}},
unreg poly*/.style={
@unreg poly*/.list={#1},
insert path={-- cycle}},
@unreg poly*/.style={insert path={-- #1}}}
\tikzset{every picture/.append style={line join=round,thick}}
\begin{document}
\begin{tikzpicture}
\node[reg poly=5, minimum size=+2cm, draw, very thick] (a) {};
\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5}
\node [mirror=(a.corner \i)--(a.side \i), transform shape,
reg poly=5, minimum size=+2cm, draw=red!\col!blue] {};
\end{tikzpicture}
\begin{tikzpicture}
\draw[very thick] (0,0) [unreg poly={(1,1), (2,-.5), ++(south west:1), ++(left:1)}];
%\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5}
%  \draw[red!\col!blue, mirror=(unreg poly-corner \i)--(unreg poly-side \i)]
%    (0,0) [unreg poly*={(1,1), (2,-.5), ++(south west:1), ++(left:1)}];
\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5}
\draw[red!\col!blue, m/.style={mirror=(unreg poly-corner \i)--(unreg poly-side \i)}]
([m]unreg poly-corner 1) \foreach\j in {2,...,5}{-- ([m]unreg poly-corner \j)} -- cycle;
\end{tikzpicture}
\end{document}


## Output
{"ft_lang_label":"__label__en","ft_lang_prob":0.95003426,"math_prob":0.9789456,"size":1740,"snap":"2019-35-2019-39","text_gpt3_token_len":378,"char_repetition_ratio":0.11232719,"word_repetition_ratio":0.013937282,"special_character_ratio":0.21034482,"punctuation_ratio":0.1051051,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9970416,"pos_list":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14],"im_url_duplicate_count":[null,5,null,5,null,5,null,5,null,5,null,5,null,5,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-09-21T21:19:25Z\",\"WARC-Record-ID\":\"<urn:uuid:06ed3c4c-6dd7-4f01-8e72-3b0ad61badb1>\",\"Content-Length\":\"158367\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:f7b08beb-caf1-419d-84d6-0ac4b3cc5518>\",\"WARC-Concurrent-To\":\"<urn:uuid:1fc6fbf8-5dcf-425b-b9cc-f34643329075>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://tex.stackexchange.com/questions/34547/is-there-a-way-in-tikz-to-reflect-regular-polygons-of-an-arbitrary-number-of-edg\",\"WARC-Payload-Digest\":\"sha1:OZO73MTFEK2B5BZT7LJ46W3NT66SXHY5\",\"WARC-Block-Digest\":\"sha1:CFLILLIJXF5XJ4CVERI2AWLP7UC3QTCJ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-39/CC-MAIN-2019-39_segments_1568514574665.79_warc_CC-MAIN-20190921211246-20190921233246-00107.warc.gz\"}"}