动画和 TikZ-变形?

动画和 TikZ-变形?

我正在为演示文稿制作动画 - 网格变形并重新形成。我拼凑了一个快速动画,可以实现我想要的效果,但出于某种原因,它也会缩小绘图。这是一个已知问题吗?有人知道如何防止这种缩小吗?

为了简单起见,除了 MWE 之外,我还添加了一张显示第一帧和最后一帧的图像。请注意,在整个动画过程中,网格两端的线条应该以完全相同的坐标结束: 形变

\documentclass{article}
\usepackage{tikz}
\usepackage{animate}

\begin{document}
\begin{animateinline}[controls,palindrome]{10}
  \multiframe{10}{i=0+1}{%
\begin{tikzpicture}
\clip (0,0.3)..controls + (.075*\i,-2.5) and +(-.075*\i,2.5) .. (0,-6.3)--
    (-0.3,-6)..controls + (2.5,-.075*\i) and +(-2.5,.075*\i) .. (6.3,-6)--
    (6,-6.3)..controls + (-.075*\i,2.5) and +(.075*\i,-2.5) .. (6,.3)--
    (6.3,0)..controls + (-2.5,.075*\i) and + (2.5,-.075*\i) .. (-.3,0);
  \foreach \x in {0,...,6}{
    \draw (\x,0.3)..controls + (.075*\i,-2.5) and +(-.075*\i,2.5) .. (\x,-6.3);
    \draw (-0.3,-\x)..controls + (2.5,-.075*\i) and +(-2.5,.075*\i) .. (6.3,-\x);
}
\end{tikzpicture}}
\end{animateinline}
\end{document}

答案1

TikZ 根据环境所包含的对象计算环境的边界框tikzpicture。此自动计算的边界框可能因动画帧而异。使用 pkg animate,所有帧都会缩放以适应第一个动画帧定义的尺寸,如果 BBox 尺寸与第一帧不同,这可能会导致帧的挤压和/或拉伸。为了解决这个问题,强制所有帧使用一个公共边界框:

\useasboundingbox (...,...) rectangle (...,...);

完整示例:

\documentclass{article}
\usepackage{tikz}
\usepackage{animate}

\begin{document}
\begin{animateinline}[controls,palindrome]{10}
  \multiframe{10}{i=0+1}{%
    \begin{tikzpicture}
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \useasboundingbox (-0.3,0.3) rectangle (6.3,-6.3);
      %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
      \clip (0,0.3)..controls + (.075*\i,-2.5) and +(-.075*\i,2.5) .. (0,-6.3)--
        (-0.3,-6)..controls + (2.5,-.075*\i) and +(-2.5,.075*\i) .. (6.3,-6)--
        (6,-6.3)..controls + (-.075*\i,2.5) and +(.075*\i,-2.5) .. (6,.3)--
        (6.3,0)..controls + (-2.5,.075*\i) and + (2.5,-.075*\i) .. (-.3,0);
      \foreach \x in {0,...,6}{
        \draw (\x,0.3)..controls + (.075*\i,-2.5) and +(-.075*\i,2.5) .. (\x,-6.3);
        \draw (-0.3,-\x)..controls + (2.5,-.075*\i) and +(-2.5,.075*\i) .. (6.3,-\x);
      }
    \end{tikzpicture}}
\end{animateinline}
\end{document}

相关内容