使用投影机叠加层将常见图像组件锚定在动态图像中

使用投影机叠加层将常见图像组件锚定在动态图像中

此代码

\documentclass{beamer}
\usepackage{tikz}
\begin{document}
\begin{frame}{Test}
  \begin{tikzpicture}
    \draw(0, 0) -- (3, 0);
    \only<2>{
      \draw[->](0, 0) -- (0,4);
    }
  \end{tikzpicture}
\end{frame}
\end{document}

产生输出

在此处输入图片描述

水平线是每张幻灯片中图像的共同点,我希望它在每张幻灯片中保持相同的位置。但是,添加垂直线导致水平线发生位移。

怎么解决?

答案1

在这种情况下,我会尝试更改图片的边界框。最简单的方法是在 处添加一个空节点(0,4)

\begin{frame}{Test}
  \begin{tikzpicture}
    \draw(0, 0) -- (3, 0);
    \node[inner sep=0pt] at (0,4){};
    \only<2>{
      \draw[->](0, 0) -- (0,4);
    }
  \end{tikzpicture}
\end{frame}

另一种方法是专门将边界框设置为(0,0) rectangle (3,4)。这将包括完整的坐标系。

\begin{frame}{Test}
  \begin{tikzpicture}
    \useasboundingbox (0,0) rectangle (3,4);
    \draw(0, 0) -- (3, 0);
    \only<2>{
      \draw[->](0, 0) -- (0,4);
    }
  \end{tikzpicture}
\end{frame}

更一般地说,当前边界框可以通过(0,4)以下点进行扩展。

\begin{frame}{Test}
  \begin{tikzpicture}
    \draw(0, 0) -- (3, 0);
    \useasboundingbox (current bounding box.south west) -- (current bounding box.north east) -- (0,4);
    \only<2>{
      \draw[->](0, 0) -- (0,4);
    }
  \end{tikzpicture}
\end{frame}

以上三个例子均得出以下结果:

在此处输入图片描述

答案2

我一次又一次遇到这些问题,最后只能通过增加白线来解决。Sam Carter 教我使用\path命令。对于你来说,这相当于添加\path(0, 4) -- (3, 4);。然后就可以制作一些漂亮的动画。我添加了一个示例来说明各种可能性。

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

在此处输入图片描述

相关内容