| 1 |
% !TeX spellcheck = en_US |
| 2 |
% !TeX root = tikz-ext-manual.tex |
| 3 |
% Copyright 2022 by Qrrbrbirlbel |
| 4 |
% |
| 5 |
% This file may be distributed and/or modified |
| 6 |
% |
| 7 |
% 1. under the LaTeX Project Public License and/or |
| 8 |
% 2. under the GNU Free Documentation License. |
| 9 |
% |
| 10 |
\clearpage |
| 11 |
\section{Mirror, Mirror on the Wall} |
| 12 |
\label{library:mirror} |
| 13 |
|
| 14 |
\begin{tikzlibrary}{ext.transformations.mirror} |
| 15 |
This library adds more transformations to \tikzname. |
| 16 |
\end{tikzlibrary} |
| 17 |
|
| 18 |
As explained in section~\ref{pgflibrary:transformations}, there are two approaches to setting a mirror transformation. |
| 19 |
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. |
| 20 |
|
| 21 |
\subsection{Using the reflection matrix} |
| 22 |
|
| 23 |
\begin{codeexample}[width=.4\linewidth,preamble=\usetikzlibrary{shapes.geometric,ext.transformations.mirror}] |
| 24 |
\begin{tikzpicture}[line join=round, thick, reg poly/.style={ |
| 25 |
shape=regular polygon, regular polygon sides={#1}}] |
| 26 |
\node[reg poly=5, minimum size=+2cm, draw, very thick] (a) {}; |
| 27 |
\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5} |
| 28 |
\node [ext/mirror=(a.corner \i)--(a.side \i), transform shape, |
| 29 |
reg poly=5, minimum size=+2cm, draw=red!\col!blue] {}; |
| 30 |
\end{tikzpicture} |
| 31 |
\end{codeexample} |
| 32 |
|
| 33 |
\begin{key}{/\tikzext/xmirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz} |
| 34 |
Sets up a transformation that mirrors along a horizontal line that goes through point $(\text{\meta{value}}, 0)$ or \meta{coordinate}. |
| 35 |
|
| 36 |
\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}] |
| 37 |
\begin{tikzpicture} |
| 38 |
\draw[help lines] (-0.25, -.25) grid (3.25, 1.25); |
| 39 |
\draw[-latex] (0,0) .. controls (.5,1) .. (1,1); |
| 40 |
|
| 41 |
\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25); |
| 42 |
\draw[ext/xmirror=(m),-latex] (0,0) .. controls (.5,1) .. (1,1); |
| 43 |
\end{tikzpicture} |
| 44 |
\end{codeexample} |
| 45 |
\end{key} |
| 46 |
|
| 47 |
\begin{key}{/\tikzext/ymirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz} |
| 48 |
Sets up a transformation that mirrors along a vertical line that goes through point $(0, \text{\meta{value}})$ or \meta{coordinate}. |
| 49 |
\end{key} |
| 50 |
|
| 51 |
|
| 52 |
\begin{key}{/\tikzext/mirror x=\meta{coordinate} (default {(0,0)})}\keycompat{tikz} |
| 53 |
Similar to |xmirror|, this however uses the |xyz| coordinate system instead of the |canvas| system. |
| 54 |
\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}] |
| 55 |
\begin{tikzpicture}[x=.5cm, y=(45:1cm)] |
| 56 |
|
| 57 |
\draw[-latex] (0,0) .. controls (.5,1) .. (1,1); |
| 58 |
|
| 59 |
\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25); |
| 60 |
|
| 61 |
\draw[ ext/xmirror=(m), -latex, red, dotted] (0,0) .. controls (.5,1) .. (1,1); |
| 62 |
\draw[ext/mirror x=(m), -latex] (0,0) .. controls (.5,1) .. (1,1); |
| 63 |
\end{tikzpicture} |
| 64 |
\end{codeexample} |
| 65 |
\end{key} |
| 66 |
|
| 67 |
\begin{key}{/\tikzext/mirror y=\meta{coordinate} (default {(0,0)})}\keycompat{tikz} |
| 68 |
Similar to |ymirror|, this however uses the |xyz| coordinate system instead of the |canvas| system. |
| 69 |
\end{key} |
| 70 |
|
| 71 |
|
| 72 |
\begin{key}{/\tikzext/mirror=\meta{point A}|--|\meta{point B}}\keycompat{tikz} |
| 73 |
Sets up a transformation that mirrors along a line that goes through \meta{point A} and \meta{point B}. |
| 74 |
|
| 75 |
When only \meta{point A} is given that line goes through \meta{point A} and the origin. |
| 76 |
\end{key} |
| 77 |
|
| 78 |
\subsection{Using built-in transformations} |
| 79 |
|
| 80 |
\begin{codeexample}[width=.4\linewidth,preamble=\usetikzlibrary{shapes.geometric,ext.transformations.mirror}] |
| 81 |
\begin{tikzpicture}[line join=round, thick, reg poly/.style={ |
| 82 |
shape=regular polygon, regular polygon sides={#1}}] |
| 83 |
\node[reg poly=5, minimum size=+2cm, draw, very thick] (a) {}; |
| 84 |
\foreach \i[evaluate={\col=(\i-1)/.04}] in {1,...,5} |
| 85 |
\node [ext/Mirror=(a.corner \i)--(a.side \i), transform shape, |
| 86 |
reg poly=5, minimum size=+2cm, draw=red!\col!blue] {}; |
| 87 |
\end{tikzpicture} |
| 88 |
\end{codeexample} |
| 89 |
|
| 90 |
\begin{key}{/\tikzext/xMirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz} |
| 91 |
Sets up a transformation that mirrors along a horizontal line that goes through point $(\text{\meta{value}}, 0)$ or \meta{coordinate}. |
| 92 |
|
| 93 |
\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}] |
| 94 |
\begin{tikzpicture} |
| 95 |
\draw[help lines] (-0.25, -.25) grid (3.25, 1.25); |
| 96 |
\draw[-latex] (0,0) .. controls (.5,1) .. (1,1); |
| 97 |
|
| 98 |
\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25); |
| 99 |
\draw[ext/xMirror=(m),-latex] (0,0) .. controls (.5,1) .. (1,1); |
| 100 |
\end{tikzpicture} |
| 101 |
\end{codeexample} |
| 102 |
\end{key} |
| 103 |
|
| 104 |
\begin{key}{/\tikzext/yMirror=\meta{value or coordinate} (default 0pt)}\keycompat{tikz} |
| 105 |
Sets up a transformation that mirrors along a vertical line that goes through point $(0, \text{\meta{value}})$ or \meta{coordinate}. |
| 106 |
\end{key} |
| 107 |
|
| 108 |
|
| 109 |
\begin{key}{/\tikzext/Mirror x=\meta{coordinate} (default {(0,0)})}\keycompat{tikz} |
| 110 |
Similar to |xMirror|, this however uses the |xyz| coordinate system instead of the |canvas| system. |
| 111 |
\begin{codeexample}[preamble=\usetikzlibrary{ext.transformations.mirror}] |
| 112 |
\begin{tikzpicture}[x=.5cm, y=(45:1cm)] |
| 113 |
|
| 114 |
\draw[-latex] (0,0) .. controls (.5,1) .. (1,1); |
| 115 |
|
| 116 |
\draw[dashed] (1.5, -.25) coordinate (m) -- (1.5, 1.25); |
| 117 |
|
| 118 |
\draw[ ext/xMirror=(m), -latex, red, dotted] (0,0) .. controls (.5,1) .. (1,1); |
| 119 |
\draw[ext/Mirror x=(m), -latex] (0,0) .. controls (.5,1) .. (1,1); |
| 120 |
\end{tikzpicture} |
| 121 |
\end{codeexample} |
| 122 |
\end{key} |
| 123 |
|
| 124 |
\begin{key}{/\tikzext/Mirror y=\meta{coordinate} (default {(0,0)})}\keycompat{tikz} |
| 125 |
Similar to |yMirror|, this however uses the |xyz| coordinate system instead of the |canvas| system. |
| 126 |
\end{key} |
| 127 |
|
| 128 |
|
| 129 |
\begin{key}{/\tikzext/Mirror=\meta{point A}\opt{|--|\meta{point B}}}\keycompat{tikz} |
| 130 |
Sets up a transformation that mirrors along a line that goes through \meta{point A} and \meta{point B}. |
| 131 |
|
| 132 |
When only \meta{point A} is given that line goes through \meta{point A} and the origin. |
| 133 |
\end{key} |
| 134 |
|
| 135 |
\endinput |