# Rotating and flipping in TikZ

It is known that if I want to shift a draw command by a constant vector, I can do that. My question is, is it possible to flip a draw command (along a given direction), or to rotate it around the zero/other point, given an angle?

-
does this help how-do-i-rotate-a-tikz-rectangle-about-a-specific-axis/ –  cmhughes Feb 29 '12 at 19:06
Thanks, that answers the rotating question. Is it possible to flip, then? –  Ron Feb 29 '12 at 19:28

calc library can do this pretty easily but there might be even easier ways to do this. Here is a simple example

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\node (one) at (1,0) {1};
\node (zero) at (0,0) {0};
\draw[thick] (0,0) -- ($(0,0)!-1!(1,0)$); % Flips it
\draw[red,thick] (0,0) -- ($(0,0)!-1!90:(1,0)$); % Flips it and rotates further 90 deg.
\draw[blue,thick] (0,0) -- ($(0,0)!0.5!45:(1,0)$); %Draws it halfway and rotates 45deg.
\end{tikzpicture}
\end{document}


-

You can use a combination of xscale=-1 and the rotation commands to flip along the x-axis (or similarly for yscale and the y-axis) and then rotate into position. If you want to do it in one step, Tikz has a /tikz/cm={a,b,c,d,<coordinate>} option (p253 in the v2.10 manual) that lets you specify the 2d transformation matrix...but the manual recommends you not use this option directly.

-

You could use a scope. For instance:

\foreach \x in {0,90,180,270} {
\begin{scope}[rotate=\x]
\draw (0,0) -- (1,0);
\end{scope}
}


I agree this is some overkill if it is only for one command, but if you plan to rotate a couple of lines, rectangles,... this is an elegant solution.

-

picture

code

\documentclass{scrartcl}
\usepackage{tikz}

\definecolor{myblue}{RGB}{17, 59, 99}
\definecolor{myorange}{RGB}{187, 114, 42}
\definecolor{mybetween}{RGB}{102, 86, 70}

\def\tikzbox{%
\fill[myblue] (-0.1, -0.1) rectangle +(1.6, 3.2);
\fill[myorange] (0.8, 0) arc(180:90:0.1cm)  -- (1, 0.1) arc(-90:0:0.1cm) -- %
(1.1, 0.45) arc(-90:90:0.015cm and 0.03cm) -- (1.1, 0.51) arc(-90:90:0.015cm and 0.03cm)%
-- (1.1, 1) arc(180:90:0.05cm) -- (1.3, 1.05) arc(-90:0:0.05cm) -- (1, 1.8)  arc(210:120:0.05cm) .. controls (1.05cm, 2.2cm) and  (0.9cm, 2.3cm) ..  (0.7, 2.5)%
.. controls (0.5, 2.7) .. (0.3, 2.7) arc(270:180:0.3cm) -- (0, 3) -- (1.5, 3) --%
(1.5, 0) -- cycle;  }
\begin{document}

\begin{tikzpicture}[scale = 2]
\tikzbox
\begin{scope}[cm={-1,0,0,1,(3,0)}]
\tikzbox
\end{scope}
\begin{scope}[cm={1,0,0,-1,(0,-.1)}]
\tikzbox
\end{scope}
\begin{scope}[cm={-1,0,0,-1,(3,-.1)}]
\tikzbox
\end{scope}
\begin{scope}[cm={0.707,0.707,-0.707,0.707,(6,0)}]
\tikzbox
\end{scope}
\end{tikzpicture}

\end{document}

-
for people, that like me, dont know about the cm= key: tex.stackexchange.com/a/49172/19326 –  ted Sep 3 '13 at 22:43