我正在学习如何在 LaTeX 中制作动画。经过对不同图片的一些尝试后,我想为下面的图片制作动画,并从 Marmot 在这个问题中给我提供的答案开始在三维空间中绘制简单平面。具体来说,我想将灰色矩形移动到 (0,0,0) 周围并将其抬起,以说明如果它开始与正象限相交会发生什么。以下 MWE 执行其他操作,因为它为矩形的尺寸设置了动画。我想我应该用平面来定义矩形,然后我将更改其斜率。我该怎么做?
\documentclass{beamer}
\usepackage{amsmath} % need for subequations
\usepackage{amsfonts}
\usepackage{tikz}
\usetikzlibrary{calc, shadings}
\usetikzlibrary{calc,intersections}
\usetikzlibrary{positioning,arrows.meta}
\usepackage{pgf,tikz,pgfplots}
\pgfplotsset{compat=1.15}
\usepackage{mathrsfs}
\usetikzlibrary{arrows}
\usepackage{animate}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d} %add it to draw the plane
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane
}
\makeatother
\let\oldemptyset\emptyset
\begin{document}
\begin{frame}
\tdplotsetmaincoords{105}{-30}
\begin{animateinline}[loop,poster=first,controls]{30}
\multiframe{36}{rt=0+10}
{
\begin{tikzpicture}[tdplot_main_coords,font=\small]
\tdplotsetrotatedcoords{00}{30}{0}
\begin{scope}[tdplot_rotated_coords]
\begin{scope}[canvas is xy plane at z=0]
\fill[blue!40,fill opacity=0.3] (-{cos(\rt)*5},-{sin(\rt)*5}) rectangle ({cos(\rt)*5},{sin(\rt)*5});
\draw[very thick] (-2,0) -- (2,0); %draws market line
\path (-150:2) coordinate (H) (-1.5,0) coordinate(X);
\pgflowlevelsynccm
\draw[very thick,-stealth,gray] (0,0) -- (-30:1.5); %draws ``projection'' of $\Phi$
\end{scope}
\draw[stealth-] (H) -- ++ (-1,0,0.2) node[pos=1.3]{$H$}; %draws arrow
\draw[stealth-] (X) -- ++ (0,1,0.2) node[pos=1.3]{$X$}; %draws arrow
\draw[very thick,-stealth] (0,0,0) coordinate (O) -- (0,0,3) node[right]{$\varphi$}; %draws vector
\end{scope}
\pgfmathsetmacro{\Radius}{1.5} %using a macro
\draw[-stealth] (O)-- (2.5*\Radius,0,0) node[pos=1.15] {spot $0$};
\draw[-stealth] (O) -- (0,3.5*\Radius,0) node[pos=1.15] {spot $2$};
\draw[-stealth] (O) -- (0,0,2.5*\Radius) node[pos=1.05] {spot $1$};
\end{tikzpicture}
}
\end{animateinline}
\end{frame}
\end{document}
答案1
这是用来旋转平面的东西(但我不知道这些是不是你所想的平面和旋转轴)。它还会调整边界框,使其与所有动画步骤紧密贴合。为此,这个答案已被使用,但您可能还感兴趣这个答案,我在这里没有尝试。请注意,您需要编译两次。动画 gif 是按照以下方式制作的此评论尤其是这个答案,并且该文件有注释说明您为了重新创建 gif 需要做什么。
%\documentclass[export]{standalone} % <- use for multipage pdf
\documentclass{beamer} % <- comment out for multipage pdf
\usepackage{animate}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{3d} %add it to draw the plane
\makeatletter
\tikzoption{canvas is xy plane at z}[]{%
\def\tikz@plane@origin{\pgfpointxyz{0}{0}{#1}}%
\def\tikz@plane@x{\pgfpointxyz{1}{0}{#1}}%
\def\tikz@plane@y{\pgfpointxyz{0}{1}{#1}}%
\tikz@canvas@is@plane
}
\def\ExportBB{\edef\figbb{(\xmin,\ymin) rectangle (\xmax,\ymax)}
\immediate\write\@mainaux{\xdef\string\figbb{\figbb}\relax}}
\makeatother
\let\oldemptyset\emptyset
\begin{document}
\begin{frame} % <- comment out for multipage pdf
\tdplotsetmaincoords{105}{-30}
\pgfmathsetmacro{\xmin}{0}
\pgfmathsetmacro{\xmax}{0}
\pgfmathsetmacro{\ymin}{0}
\pgfmathsetmacro{\ymax}{0}
\begin{animateinline}[loop,poster=first,controls]{30}
\multiframe{36}{rt=0+10}
{
\begin{tikzpicture}[tdplot_main_coords,font=\small]
\ifdefined\figbb\relax
\path \figbb;
\fi
% this is the stuff that gets rotated
\tdplotsetrotatedcoords{00}{\rt}{0}
\begin{scope}[tdplot_rotated_coords]
\begin{scope}[canvas is xy plane at z=0]
\fill[blue!40,fill opacity=0.3] (-5,-5) rectangle (5,5);
% (-{cos(\rt)*5},-{sin(\rt)*5}) rectangle ({cos(\rt)*5},{sin(\rt)*5});
\pgflowlevelsynccm
\draw[very thick,-stealth,gray] (0,0) -- (-30:1.5); %draws ``projection'' of $\Phi$
\end{scope}
\draw[very thick,-stealth] (0,0,0) coordinate (O) -- (0,0,3) node[right]{$\varphi$}; %draws vector
\end{scope}
\begin{scope}[canvas is xy plane at z=0]
\draw[very thick] (-2,0) -- (2,0); %draws market line
\path(-1.5,0) coordinate(X);
\path (-150:2) coordinate (H);
\end{scope}
\draw[stealth-] (X) -- ++ (0,1,0.2) node[pos=1.3]{$X$}; %draws arrow
\draw[stealth-] (H) -- ++ (-1,0,0.2) node[pos=1.3]{$H$}; %draws arrow
\pgfmathsetmacro{\Radius}{1.5} %using a macro
\draw[-stealth] (O)-- (2.5*\Radius,0,0) node[pos=1.15] {spot $0$};
\draw[-stealth] (O) -- (0,3.5*\Radius,0) node[pos=1.15] {spot $2$};
\draw[-stealth] (O) -- (0,0,2.5*\Radius) node[pos=1.05] {spot $1$};
\path let \p1=(current bounding box.south west),
\p2=(current bounding box.north east)
in \pgfextra{%
\pgfmathsetmacro{\xmin}{min(\x1,\xmin)}
\pgfmathsetmacro{\xmax}{max(\x2,\xmax)}
\pgfmathsetmacro{\ymin}{min(\y1,\ymin)}
\pgfmathsetmacro{\ymax}{max(\y2,\ymax)}
\xdef\xmin{\xmin pt}
\xdef\xmax{\xmax pt}
\xdef\ymin{\ymin pt}
\xdef\ymax{\ymax pt}
};
\end{tikzpicture}
\ExportBB
}
\end{animateinline}
\end{frame} % <- comment out for multipage pdf
\end{document}