# How to draw rotating lines with the axis of rotation shifted to an other coordinate (using tikz)?

i'm trying to generate an animation using tikz.

The animation should show a fixed coordinate system placed at an arbitrary position (x,y) on the current page. Additionally a rotating line should be animated with the axis of rotation also placed at the position (x,y). i wrote the following code

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\usepackage{ifthen}

\begin{document}

\begin{frame}
\begin{tikzpicture}[remember picture, overlay, shift={(current page.center)}]
%draw coordinate system at the center of current page
\draw[thick, color=black, -latex] (-3,0) -- (3,0) node[right]{$x$};
\draw[thick, color=black, -latex] (0,-3) -- (0,3) node[above]{$y$};
\end{tikzpicture}

\begin{animateinline}[poster=first,controls]{8}%
% draw rotating line
\multiframe{11}{rt=0+0.1,icount=1+1}{%
\begin{tikzpicture}[scale=.75]
\ifthenelse{\icount > 0}%
{\draw[thick, color=red!50] ({0},{0}) -- ({cos(\rt)*5}, {sin(\rt)*5});}{}
\end{tikzpicture}%
}
\end{animateinline}
\end{frame}

\end{document}


The animation doesn't do what i wish.

1. How do i shift the axis of rotation to position (x,y)?

shift={(current page.center)}somehow doesn't work with animateinline

1. The line doesn't rotate as i wish (starting from a horizontal position and rotating counterclockwise)?

I'm grateful for any help!

PS: Does anyone know a way to hold the lines which are drawn on the previous frames such that on the first frame, there will only be one line, on the second frame there would be the line from the first frame plus the new drawn line and for the following frames respectively?

Are there any particular reasons for having two environments (one for the axes and one for the rotating plot)?

If you plot the axes inside the the same tikzpicture it's easy to get your desired animation.

As for your second question, the reason for the misbehaving was the fact that the size of the image changed during the animation. You also used the step 0.1°, this is very small so I increased it. I added two "phantom nodes" at (5,5) and (-5,-5) to get a none moving animation.

I also removed your \ifthenelse-condition, due to it not having any effect as you've written it. I also changed the scaling to using a \resizebox (I had some troubles creating the gif with scale=.75)

The code:

\documentclass{beamer}
\usepackage{tikz}
\usepackage{animate}
\begin{document}
\begin{frame}
\begin{animateinline}[poster=first,controls]{8}
% draw rotating line
\multiframe{36}{rt=0+10}{%
\resizebox{!}{.9\textheight}{\begin{tikzpicture}
\draw[thick, color=red!50] (0,0) -- ({cos(\rt)*5}, {sin(\rt)*5});
\draw[thick, color=black, -latex] (-3,0) -- (3,0) node[right]{$x$};
\draw[thick, color=black, -latex] (0,-3) -- (0,3) node[above]{$y$};
\node at (5,5) {};
\node at (-5,-5) {};
\end{tikzpicture}}%
}
\end{animateinline}
\end{frame}
\end{document}


The result:

• Thanks for the code. Its exactly what i'm looking for. As to the question why i used two environments: I tried using one environment before, but i always got error regarding to the first frame having zero width or height in the multiframe operation. So i separated the static part and the moving part in two environments. Jun 24 '15 at 10:48
• @JoeJay Glad I could help. I see. If this is a valid answer, would you mind accepting it?
– user49901
Jun 24 '15 at 11:37
• sorry for the late reply. I was new to this forum and didn't know there is a button for accepting the answer. I just clicked on it :) . Thanks a lot by the way. Jul 17 '15 at 14:09