# Tikz: Rotating a circle

In the below code I place a circle on an inclined plane.

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def\iangle{atan(4/5)}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 4);
\draw (O)--coordinate[pos=0.5] (mid) (A);

\begin{scope}[rotate=\iangle]
\end{scope}
\end{tikzpicture}
\end{document}


Even though this is as simple as it gets, is there an even more straightforward method, perhaps without scope? I ask because had the shape been, say, a square, I could do it just by rotating the shape and shifting.

Further; why node doesn't give the same result in the below code:

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def\iangle{atan(4/5)}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 4);
\draw (O)--coordinate[pos=0.5] (mid) (A);

\begin{scope}[rotate=\iangle]
\node[draw, circle, minimum size=2cm,  yshift=1cm] at (mid) {};
\end{scope}
\end{tikzpicture}
\end{document}


See if

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def\iangle{atan(4/5)}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 4);
\draw (O)--coordinate (mid) (A);
%
\node[draw, circle, minimum size=2cm, rotate=\iangle, yshift=1cm] at (mid) {};
\end{tikzpicture}
\end{document}


is what you looking for :)

• Thanks for your answer. I see why your solution works, but I do not see why the second option in my question does not. (node inside scope.) – blackened May 9 '17 at 19:12
• @blackened, because scope not rotate node shape. for rotate it you need to move rotate to shape's options. For illustration, test \begin{scope}[rotate=\iangle] \node (circle) [draw, circle, minimum size=2cm, yshift=1cm] at (mid) {}; \draw[fill=yellow] (circle.south) circle (1mm); \end{scope} and compare with \node (circle) [draw, circle, minimum size=2cm, rotate=\iangle, yshift=1cm] at (mid) {}; \draw[fill=yellow] (circle.south) circle (1mm);. – Zarko May 9 '17 at 19:18

If there is no content (eg. text) that should be rotated, you can use a calculated border anchor to position the circle node. Then there is no need to know the size of this node.

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0,0);
\coordinate (A) at (5,4);
\draw
let \p1=(O), \p2=(A),
\n1={atan2(\y2-\y1,\x2-\x1)},
\n2={ifthenelse(abs(\n1)<=90,\n1-90,\n1+90}
in  (O)--(A)
node[pos=.5,draw,fill=yellow,minimum width=2cm,circle,anchor={\n2},outer sep=0pt]{}
;
\end{tikzpicture}
\end{document}


Transformations in scopes do not apply to nodes automatically. But you can enable this transformations for shapes too: add transform shape to the scope options.

\documentclass[border=1cm]{standalone}
\usepackage{tikz}
\begin{document}

\begin{tikzpicture}
\def\iangle{atan(4/5)}
\coordinate (O) at (0, 0);
\coordinate (A) at (5, 4);
\draw (O)--coordinate[pos=0.5] (mid) (A);

\begin{scope}[rotate=\iangle,transform shape]
\node[draw, circle, minimum size=2cm,yshift=1cm] at (mid) {};
\end{scope}
\end{tikzpicture}
\end{document}

• Use atan2(\y2-\y1,\x2-\x1) instead of atan((\y2-\y1)/(\x2-\x1))... – Paul Gaborit May 9 '17 at 22:48
• @PaulGaborit Done, but what is the problem with atan? – esdd May 9 '17 at 22:53
• @PaulGaborit Ok, division by 0 if I use (0,4) for A. – esdd May 9 '17 at 23:28
• Yes. My example was bad... ;-) – Paul Gaborit May 9 '17 at 23:33
• But it helped me to understand the problem ;-) – esdd May 9 '17 at 23:37