4

I have a vector a which can only move in x-y plane and has magnitude of the radius of the sphere. Is there a way to make this a animated. Animated in the sense that it rotates within the x-y plane and the angle changes accordingly.

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\begin{document}
\begin{tikzpicture}

    % Define radius
    \def\r{3}

    % Bloch vector
    \draw (0,0) node[circle,fill,inner sep=1] (orig) {} -- (\r/5,-\r/3) node[circle,fill,inner sep=0.7,label=above:$\vec{a}$] (a) {};

    % Sphere
    \draw (orig) circle (\r);
    \draw[dashed] (orig) ellipse (\r{} and \r/3);

    % Axes
    \draw[->] (orig) -- ++(-\r/5,-\r/3) node[below] (x1) {$x$};
    \draw[->] (orig) -- ++(\r,0) node[right] (x2) {$y$};
    \draw[->] (orig) -- ++(0,\r) node[above] (x3) {$z$};

    %Angles
    \pic [draw=gray,text=gray,->,"$\phi$"] {angle = x1--orig--phi};
    \pic [draw=gray,text=gray,<-,"$\theta$"] {angle = a--orig--x3};

\end{tikzpicture}
\end{document} 

Is it possible in TikZ?

Shamina
  • 1,078

1 Answers1

3

This is easy with this answer.

\documentclass{article}

\usepackage{animate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[active,tightpage]{preview}
\makeatletter
\def\@anim@@newframe{\@ifstar\@anim@newframe\@anim@newframe}
\def\@anim@newframe{\end{preview}\begin{preview}}
\renewenvironment{animateinline}[2][]{%
  \let\newframe\@anim@@newframe%
  \let\multiframe\@anim@multiframe%
  \begin{preview}}{%
  \end{preview}}
\makeatother

\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\begin{document}
\begin{animateinline}[autoplay,loop]{2}
\multiframe{21}{i=0+1}{\pgfmathsetmacro{\myangle}{-4*\i}

\begin{tikzpicture}

    % Define radius
    \def\r{3}

    % Bloch vector
    \coordinate[label=above:$\vec{a}$] (a) at (\myangle:{\r} and {\r/3});
    \coordinate (orig) at (0,0);
    \draw (orig) circle(0.1);
    \draw[-latex] (orig) -- (a);

    % Sphere
    \draw (orig) circle (\r);
    \draw[dashed] (orig) ellipse (\r{} and \r/3);

    % Axes
    \draw[->] (orig) -- ++(-\r/5,-\r/3) node[below] (x1) {$x$};
    \draw[->] (orig) -- ++(\r,0) node[right] (x2) {$y$};
    \draw[->] (orig) -- ++(0,\r) node[above] (x3) {$z$};

    %Angles
    \pic [draw=gray,text=gray,->,"$\phi$"] {angle = x1--orig--a};
    \pic [draw=gray,text=gray,<-,"$\theta$"] {angle = a--orig--x3};

\end{tikzpicture}}
\end{animateinline}
\end{document} 

enter image description here

If you want to rotate it over the full plane, use

\documentclass{article}

\usepackage{animate}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[active,tightpage]{preview}
\makeatletter
\def\@anim@@newframe{\@ifstar\@anim@newframe\@anim@newframe}
\def\@anim@newframe{\end{preview}\begin{preview}}
\renewenvironment{animateinline}[2][]{%
  \let\newframe\@anim@@newframe%
  \let\multiframe\@anim@multiframe%
  \begin{preview}}{%
  \end{preview}}
\makeatother

\usepackage{tikz}
\usetikzlibrary{angles,quotes}

\begin{document}
\begin{animateinline}[autoplay,loop]{2}
\multiframe{91}{i=0+1}{\pgfmathsetmacro{\myangle}{-4*\i}

\begin{tikzpicture}

    % Define radius
    \def\r{3}

    % Bloch vector
    \coordinate[label={\myangle+90}:$\vec{a}$] (a) at (\myangle:{\r} and {\r/3});
    \coordinate (orig) at (0,0);
    \draw (orig) circle(0.1);
    \draw[-latex] (orig) -- (a);

    % Sphere
    \draw (orig) circle (\r);
    \draw[dashed] (orig) ellipse (\r{} and \r/3);

    % Axes
    \draw[->] (orig) -- ++(-\r/5,-\r/3) node[below] (x1) {$x$};
    \draw[->] (orig) -- ++(\r,0) node[right] (x2) {$y$};
    \draw[->] (orig) -- ++(0,\r) node[above] (x3) {$z$};

    %Angles
    \pic [draw=gray,text=gray,->,"$\phi$"] {angle = x1--orig--a};
    \pic [draw=gray,text=gray,<-,"$\theta$"] {angle = a--orig--x3};

\end{tikzpicture}}
\end{animateinline}
\end{document} 

enter image description here

Notice that my code is for exporting the animation. If you do not want to export it, but just incorporate it in your pdf document, comment out the block

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage[active,tightpage]{preview}
\makeatletter
\def\@anim@@newframe{\@ifstar\@anim@newframe\@anim@newframe}
\def\@anim@newframe{\end{preview}\begin{preview}}
\renewenvironment{animateinline}[2][]{%
  \let\newframe\@anim@@newframe%
  \let\multiframe\@anim@multiframe%
  \begin{preview}}{%
  \end{preview}}
\makeatother
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The animation will then show on selected viewers such as acroread.