% !TeX spellcheck = en_US
% !TeX root = tikz-ext-manual.tex
% Copyright 2022 by Qrrbrbirlbel
%
% This file may be distributed and/or modified
%
% 1. under the LaTeX Project Public License and/or
% 2. under the GNU Free Documentation License.
%
\clearpage
\section{Mirror, Mirror on the Wall}
\label{library:mirror}

\begin{tikzlibrary}{ext.transformations.mirror}
  This library adds more transformations to \tikzname.
\end{tikzlibrary}

As explained in section~\ref{pgflibrary:transformations}, there are two approaches to setting a mirror transformation.
As with the commands in \pgfname, we'll be using a lowercase |m| for the reflection matrix and an uppercase |M| for the built-in approach.

\subsection{Using the reflection matrix}

\begin{codeexample}[width=.4\linewidth,preamble=\usetikzlibrary{shapes.geometric,ext.transformations.mirror}]
\begin{tikzpicture}[line join=round, thick, reg poly/.style={
  shape=regular polygon, regular polygon sides={#1}}]
\node[reg poly=5, minimum size=+2cm, draw, very thick] (a) {};
\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5}
  \node [ext/mirror=(a.corner \i)--(a.side \i), transform shape,
         reg poly=5, minimum size=+2cm, draw=red!\col!blue] {};
\end{tikzpicture}
\end{codeexample}

\begin{key}{/\tikzext/xmirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz}
  Sets up a transformation that mirrors along a horizontal line that goes through point $(\text{\meta{value}}, 0)$ or \meta{coordinate}.

\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}]
\begin{tikzpicture}
\draw[help lines] (-0.25, -.25) grid (3.25, 1.25);
\draw[-latex] (0,0) .. controls (.5,1) .. (1,1);

\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25);
\draw[ext/xmirror=(m),-latex] (0,0) .. controls (.5,1) .. (1,1);
\end{tikzpicture}
\end{codeexample}
\end{key}

\begin{key}{/\tikzext/ymirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz}
  Sets up a transformation that mirrors along a vertical line that goes through point $(0, \text{\meta{value}})$ or \meta{coordinate}.
\end{key}


\begin{key}{/\tikzext/mirror x=\meta{coordinate} (default {(0,0)})}\keycompat{tikz}
  Similar to |xmirror|, this however uses the |xyz| coordinate system instead of the |canvas| system.
\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}]
\begin{tikzpicture}[x=.5cm, y=(45:1cm)]

\draw[-latex] (0,0) .. controls (.5,1) .. (1,1);

\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25);

\draw[ ext/xmirror=(m), -latex, red, dotted] (0,0) .. controls (.5,1) .. (1,1);
\draw[ext/mirror x=(m), -latex]              (0,0) .. controls (.5,1) .. (1,1);
\end{tikzpicture}
\end{codeexample}
\end{key}

\begin{key}{/\tikzext/mirror y=\meta{coordinate} (default {(0,0)})}\keycompat{tikz}
  Similar to |ymirror|, this however uses the |xyz| coordinate system instead of the |canvas| system.
\end{key}


\begin{key}{/\tikzext/mirror=\meta{point A}|--|\meta{point B}}\keycompat{tikz}
  Sets up a transformation that mirrors along a line that goes through \meta{point A} and \meta{point B}.
  
  When only \meta{point A} is given that line goes through \meta{point A} and the origin.
\end{key}

\subsection{Using built-in transformations}

\begin{codeexample}[width=.4\linewidth,preamble=\usetikzlibrary{shapes.geometric,ext.transformations.mirror}]
\begin{tikzpicture}[line join=round, thick, reg poly/.style={
  shape=regular polygon, regular polygon sides={#1}}]
\node[reg poly=5, minimum size=+2cm, draw, very thick] (a) {};
\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5}
  \node [ext/Mirror=(a.corner \i)--(a.side \i), transform shape,
         reg poly=5, minimum size=+2cm, draw=red!\col!blue] {};
\end{tikzpicture}
\end{codeexample}

\begin{key}{/\tikzext/xMirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz}
  Sets up a transformation that mirrors along a horizontal line that goes through point $(\text{\meta{value}}, 0)$ or \meta{coordinate}.

\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}]
\begin{tikzpicture}
\draw[help lines] (-0.25, -.25) grid (3.25, 1.25);
\draw[-latex] (0,0) .. controls (.5,1) .. (1,1);

\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25);
\draw[ext/xMirror=(m),-latex] (0,0) .. controls (.5,1) .. (1,1);
\end{tikzpicture}
\end{codeexample}
\end{key}

\begin{key}{/\tikzext/yMirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz}
  Sets up a transformation that mirrors along a vertical line that goes through point $(0, \text{\meta{value}})$ or \meta{coordinate}.
\end{key}


\begin{key}{/\tikzext/Mirror x=\meta{coordinate} (default {(0,0)})}\keycompat{tikz}
  Similar to |xMirror|, this however uses the |xyz| coordinate system instead of the |canvas| system.
\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}]
\begin{tikzpicture}[x=.5cm, y=(45:1cm)]

\draw[-latex] (0,0) .. controls (.5,1) .. (1,1);

\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25);

\draw[ ext/xMirror=(m), -latex, red, dotted] (0,0) .. controls (.5,1) .. (1,1);
\draw[ext/Mirror x=(m), -latex]              (0,0) .. controls (.5,1) .. (1,1);
\end{tikzpicture}
\end{codeexample}
\end{key}

\begin{key}{/\tikzext/Mirror y=\meta{coordinate} (default {(0,0)})}\keycompat{tikz}
  Similar to |yMirror|, this however uses the |xyz| coordinate system instead of the |canvas| system.
\end{key}


\begin{key}{/\tikzext/Mirror=\meta{point A}\opt{|--|\meta{point B}}}\keycompat{tikz}
  Sets up a transformation that mirrors along a line that goes through \meta{point A} and \meta{point B}.
  
  When only \meta{point A} is given that line goes through \meta{point A} and the origin.
\end{key}

\endinput