0

I would like to mirror below parts by x = 2.5 line (AB), xscale will mirror it by x = 0 line.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \def\parts{(1,1) -- (2.5,3) -- (1,4)}
\begin{tikzpicture}
    \draw [help lines, dashed] (0,0) grid(5,4);
   \draw[] \parts [xscale=-1] \parts;
   \draw[red] (2.5,1) node[below]{A} -- (2.5,4) node[above]{B};
\end{tikzpicture}
\end{document}

What's proper way to do such mirror? enter image description here

3

This introduces a key mirror, whatever you pass to this key will get mirrored. In your figure this amounts to saying

\tikzset{mirror={\draw (1,1) -- (2.5,3) -- (1,4);}}

There are styles mirrored and unmirrored, which can be used to change the transformation laws, introducing offsets or also name prefixes, say.

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[mirror/.code={\tikzset{mirrored stuff/.code={#1}}
    \begin{scope}[unmirrored]
     \tikzset{mirrored stuff}
    \end{scope}
    \begin{scope}[mirrored]
     \tikzset{mirrored stuff}
    \end{scope}},mirrored/.style={xscale=-1},unmirrored/.style={}]
  \draw [help lines, dashed] (0,0) grid(5,4);
  \tikzset{mirrored/.append style={xshift=-5cm},
  mirror={\draw (1,1) -- (2.5,3) -- (1,4);}}
  \draw[red] (2.5,1) node[below]{A} -- (2.5,4) node[above]{B};
\end{tikzpicture}
\end{document}

enter image description here

Please note that there are much more versatile options available like this one which I found after completing the example.

0

xshift helped to fix this issue!

\documentclass{standalone}
\usepackage{tikz}
\begin{document}
    \def\parts{(1,1) -- (2.5,3) -- (1,4)}
    \begin{tikzpicture}
        \draw [help lines, dashed] (0,0) grid(5,4);
        \draw[] \parts[x={(-1,0)},y={(0,1)},xshift=2*2.5cm] \parts;
        \draw[red] (2.5,1) node[below]{A} -- (2.5,4) node[above]{B};
    \end{tikzpicture}
\end{document}

enter image description here

0

The idea is x-shifting to the origin, then using [xscale=-1] to mirror, and x-shifting back. Note: the order of options matters!

The code is corrected from @beetlej.

enter image description here

\documentclass[tikz,border=5mm]{standalone}
\begin{document}
\begin{tikzpicture}
% object to be mirrored
\def\xmirror{2.5}   
\def\myobject{(1,1) -- (2.5,3) -- (1,4)}
\draw[violet,opacity=.3] (0,0) grid (5,5);
\draw[red] (\xmirror,1) node[below]{A} -- (\xmirror,4) node[above]{B};

\draw \myobject;
\draw[shift={(\xmirror,0)},xscale=-1,shift={(-\xmirror,0)}] \myobject;
\end{tikzpicture}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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