I've had these problems over and over and I ended up fixing them by additional white lines. Sam Carter taught me to use \path commands instead. In your case this amounts to adding \path(0, 4) -- (3, 4);. And one can then do some nice animations. I am adding an example that illustrates the possibilities.
\documentclass{beamer}
\usepackage{animate}
\usepackage{tikz}
%from https://tex.stackexchange.com/a/67588/121799
\tikzset{RPY/.code args={#1,#2,#3}{
% roll, pitch, yaw
\pgfmathsetmacro{\rollangle}{#1}%
\pgfmathsetmacro{\pitchangle}{#2}%
\pgfmathsetmacro{\yawangle}{#3}%
% to what vector is the x unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newxx}{cos(\yawangle)*cos(\pitchangle)}
\pgfmathsetmacro{\newxy}{sin(\yawangle)*cos(\pitchangle)}
\pgfmathsetmacro{\newxz}{-sin(\pitchangle)}
\path (\newxx,\newxy,\newxz);
\pgfgetlastxy{\nxx}{\nxy};
% to what vector is the y unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newyx}{cos(\yawangle)*sin(\pitchangle)*sin(\rollangle)-sin(\yawangle)*cos(\rollangle)}
\pgfmathsetmacro{\newyy}{sin(\yawangle)*sin(\pitchangle)*sin(\rollangle)+ cos(\yawangle)*cos(\rollangle)}
\pgfmathsetmacro{\newyz}{cos(\pitchangle)*sin(\rollangle)}
\path (\newyx,\newyy,\newyz);
\pgfgetlastxy{\nyx}{\nyy};
% to what vector is the z unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newzx}{cos(\yawangle)*sin(\pitchangle)*cos(\rollangle)+ sin(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzy}{sin(\yawangle)*sin(\pitchangle)*cos(\rollangle)-cos(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzz}{cos(\pitchangle)*cos(\rollangle)}
\path (\newzx,\newzy,\newzz);
\pgfgetlastxy{\nzx}{\nzy};
\pgfkeysalso{%
/tikz/x={(\nxx,\nxy)},
/tikz/y={(\nyx,\nyy)},
/tikz/z={(\nzx,\nzy)}
}
}
}
\newcommand{\savedx}{0}
\newcommand{\savedy}{0}
\newcommand{\savedz}{0}
%
\newcommand{\rotateRPY}[4][0/0/0]% point to be saved to \savedxyz, roll, pitch, yaw
{ \pgfmathsetmacro{\rollangle}{#2}
\pgfmathsetmacro{\pitchangle}{#3}
\pgfmathsetmacro{\yawangle}{#4}
% to what vector is the x unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newxx}{cos(\yawangle)*cos(\pitchangle)}% a
\pgfmathsetmacro{\newxy}{sin(\yawangle)*cos(\pitchangle)}% d
\pgfmathsetmacro{\newxz}{-sin(\pitchangle)}% g
\path (\newxx,\newxy,\newxz);
\pgfgetlastxy{\nxx}{\nxy};
% to what vector is the y unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newyx}{cos(\yawangle)*sin(\pitchangle)*sin(\rollangle)-sin(\yawangle)*cos(\rollangle)}% b
\pgfmathsetmacro{\newyy}{sin(\yawangle)*sin(\pitchangle)*sin(\rollangle)+ cos(\yawangle)*cos(\rollangle)}% e
\pgfmathsetmacro{\newyz}{cos(\pitchangle)*sin(\rollangle)}% h
\path (\newyx,\newyy,\newyz);
\pgfgetlastxy{\nyx}{\nyy};
% to what vector is the z unit vector transformed, and which 2D vector is this?
\pgfmathsetmacro{\newzx}{cos(\yawangle)*sin(\pitchangle)*cos(\rollangle)+ sin(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzy}{sin(\yawangle)*sin(\pitchangle)*cos(\rollangle)-cos(\yawangle)*sin(\rollangle)}
\pgfmathsetmacro{\newzz}{cos(\pitchangle)*cos(\rollangle)}
\path (\newzx,\newzy,\newzz);
\pgfgetlastxy{\nzx}{\nzy};
% transform the point given by #1
\foreach \x/\y/\z in {#1}
{ \pgfmathsetmacro{\transformedx}{\x*\newxx+\y*\newyx+\z*\newzx}
\pgfmathsetmacro{\transformedy}{\x*\newxy+\y*\newyy+\z*\newzy}
\pgfmathsetmacro{\transformedz}{\x*\newxz+\y*\newyz+\z*\newzz}
\xdef\savedx{\transformedx}
\xdef\savedy{\transformedy}
\xdef\savedz{\transformedz}
}
}
\begin{document}
\definecolor{darkgreen}{rgb}{0.0, 0.6, 0.2}
\newcount\myangle
\newcommand{\somedrawing}%
{ \coordinate (a) at (-2,0,0);
\coordinate (b) at (-2,4,0);
\coordinate (c) at (2,4,0);
\coordinate (d) at (2,0,0);
\draw[fill=gray,opacity=0.3] (a)--(b)--(c)--(d)--(a);
}
\begin{frame}
\frametitle{Orbifold pillow}
\label{frm:Pillow}
\animate<5-50>
\animatevalue<5-52>{\myangle}{0}{180}
\transduration<5-50>{0.4}
\begin{overlayarea}{\textwidth}{\textheight}
\begin{tikzpicture}[scale=0.9,odot/.style={inner sep=3pt,outer sep=2pt,minimum
width=0.2cm,circle,line width=2pt}]
\path (-5,-4,0)--(-5,4,0);
\draw[fill=gray!70] (-2,-4,0)--(6,-4,0)--(6,4,0)--(-2,4,0)--(-2,-4,0);
\only<2>{
\draw[color=blue,line width=0.1cm] (-2,-4,0) -- (6,-4,0);
\draw[color=blue,line width=0.1cm] (-2,4,0) -- (6,4,0);
\draw[color=darkgreen,line width=0.1cm] (-2,-4,0) -- (-2,4,0);
\draw[color=darkgreen,line width=0.1cm] (6,-4,0) -- (6,4,0);
}
\pause
\only<3-4>{
\draw[fill=gray,opacity=0.3] (-2,-4,0)--(2,-4,0)--(2,4,0)--(-2,4,0)--(-2,-4,0);
\draw[->,line width=5pt,red] (0.5,0.2,0) arc[radius=1.5cm, start angle=180, end angle=0];
% \node at (2,2.2,0){\ROT{$\Z2$}};
}
\pause
\only<4>{
\node[odot,fill=blue,draw=red] (n1) at (-2,-4,0) {};
\node[odot,fill=blue,draw=red] (n2) at (2,-4,0) {};
\node[odot,fill=blue,draw=red] (n3) at (-2,0,0) {};
\node[odot,fill=blue,draw=red] (n4) at (2,0,0) {};
}
\pause
\only<5->{
\draw[fill=gray,opacity=0.3] (-2,-4,0)--(2,-4,0)--(2,0,0)--(-2,0,0)--(-2,-4,0);
\begin{scope}[RPY={\the\myangle,0,0},scale=1.11] %% blue plane
\somedrawing
\end{scope}
}
\node at (6.8,-3.8){\hyperlink{frm:Pillow}{\beamergotobutton{back}}};
\end{tikzpicture}
\end{overlayarea}
\end{frame}
\end{document}

\draw[white](0, 4) -- (3, 4);) – Jan 28 '18 at 15:08