Animating a 3d plane

I'm learning how to produce animations in LaTeX. After some trials with different pictures, I would like to animate the following picture and start from the answer that Marmot provided me in this question Drawing a simple plane in 3D space. In particular, I would like to move the gray rectangle around (0,0,0) and lift it up, in order to illustrate what happens if it starts to intesect the positive orthant. The following MWE does something else, as it animates the dimensions of the rectangle. I think I should rather define the rectangle in terms of a plane and then I will change its slope. How can I do?

\documentclass{beamer}

\usepackage{amsmath}    % need for subequations
\usepackage{amsfonts}
\usepackage{tikz}

\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}

\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}

• Does \fill[blue!40,fill opacity=0.3] (-{cos(\rt)*5},-5,-{sin(\rt)*5}) -- (-{cos(\rt)*5},5,-{sin(\rt)*5}) -- ({cos(\rt)*5},5,{sin(\rt)*5}) -- ({cos(\rt)*5},-5,{sin(\rt)*5}) -- cycle;  outside the canvas is xy plane ... scope give you what you want? – user121799 Jun 26 '19 at 14:20
• Add a common bonding box (\useasboundingbox ( ... , ... ) rectangle ( ... , ... );) large enough to encompass all objects. – AlexG Jun 26 '19 at 14:35
• @AlexG Nice to see you! If you test such animations, how do you do it? I can only view the on acroread, which does however not seem to reload the file. So I compile, open acroread, find something that needs to be improved, close acroread, compile again etc. Is there a better way? – user121799 Jun 26 '19 at 14:48
• @marmot: Replace doc class with \documentclass[export]{standalone} and open PDF in the viewer of your choice. Then PgUp/PgDn. – AlexG Jun 26 '19 at 15:14
• @marmot : Even better: Replace doc class with \documentclass[dvisvgm]{article}\pagestyle{empty}, then latex+latex+dvisvgm --font-format=woff --exact --zoom=-1 and open SVG in Chromium. After changes to the sources and recompilation just click reload button in the web browser. – AlexG Jun 26 '19 at 15:20

This is something that rotates the plane (but I do not know if these are the planes and rotation axes you had in mind). It also adjusts the bounding box in such a way that it fits all animations steps fit tightly. To this end, a slight variation of this answer is used but you may also be interested in this answer, which I did not try out here. Please note that you need to compile twice. The animated gif is produced along the lines of this comment and, in particular, this answer, and the file has comments what you need to do in order to recreate the 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

\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}


• Thank you, @marmot, and sorry for the late reply. Your suggestion was good, and the code above does exactly what I wanted. However, if I understood correctly, I'd like the line $X$ not to move. – Nenne Jun 27 '19 at 6:59
• in fact your code is still a little difficult for me, so I ask you where I can find a very good reference about macros in LaTeX... I still do not understand completely how they work – Nenne Jun 27 '19 at 7:33
• @Nenne Done. Depending on what your aims are you may need to move the stuff with H to the rotated coordinates. – user121799 Jun 27 '19 at 20:40
• @Nenne I actually do not know a tutorial for that. Personally I learn most from examples. You can try texdoc texbytopic. – user121799 Jul 1 '19 at 13:17
• @Nenne Honestly, I do not know. I never printed out slides with animations. The only thing I know is that there are many options concerning the handout but I almost never used those. – user121799 Jul 3 '19 at 13:08