我有一个矢量a
,它只能在x-y
平面内移动,其大小为球体的半径。有没有办法让它变成动画a
。动画是指它在x-y
平面内旋转,角度也随之变化。
\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}
有可能吗TikZ
?
答案1
这很容易这个答案。
\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}
如果要在整个平面上旋转它,请使用
\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}
请注意,我的代码用于导出动画。如果您不想导出它,而只是将其合并到您的 pdf 文档中,请注释掉该块
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\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
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
动画将显示在选定的查看器上,例如 acroread。