旋转 Tikz 图使尺寸可变

旋转 Tikz 图使尺寸可变

我正在尝试为一个里面有一些正方形的圆圈制作动画。我希望整个圆圈围绕其中心旋转。不知何故,圆圈的缩放比例会根据角度值而变化。我读过几篇帖子以及动画和旋转手册。有人能帮帮我吗?

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[autoplay,loop,nomouse]{animate}
\usepackage{rotating}

\newcommand{\obj}[1]{
\begin{turn}{#1}
\begin{tikzpicture}%[scale = 1]
%% Large circle
\draw (0,0) circle [radius=2.25in,very thick];
\node at (0,0) [rectangle,minimum size=1cm,fill=black,draw=black,shift={(3.5cm,3.5cm)},rotate=45] () {};
\node at (0,0) [rectangle, minimum size=.5cm,fill=black,draw=black,shift={(3cm,2cm)},rotate=25] () {};
\node at (0,0) [rectangle, minimum size=.25cm,fill=black,draw=black,shift={(1.75cm,1.5cm)},rotate=80] () {};
\end{tikzpicture}
\end{turn}
}

\begin{document}

\begin{animateinline}[controls]{72}%
\multiframe{72}{iAngle=0+5}{%
%iAngle = 80, 90, ..., 360 degrees
\obj{\iAngle}
}%
\end{animateinline}%

\end{document}

答案1

这确实有点棘手,因为旋转一个圆圈会改变边界框。所以我添加了一个显式边界框。然后你不需要旋转包,你可以用 Ti 旋转Z 但需要添加变换形状才能获得所需的效果。

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[autoplay,loop,nomouse]{animate}

\newcommand{\obj}[1]{
\begin{tikzpicture}
%% Large circle
\path[use as bounding box] (-2.5in,-2.5in) rectangle (2.5in,2.5in) ;
\begin{scope}[rotate=#1,transform shape]
\draw (0,0) circle [radius=2.25in,very thick];
\node at (3.5cm,3.5cm) [rectangle,minimum size=1cm,fill=black,draw=black,rotate=45] () {};
\node at (3cm,2cm) [rectangle, minimum size=.5cm,fill=black,draw=black,rotate=25] () {};
\node at (1.75cm,1.5cm) [rectangle, minimum size=.25cm,fill=black,draw=black,rotate=80] () {};
\end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{animateinline}[controls]{72}%
\multiframe{72}{iAngle=0+5}{%
%iAngle = 80, 90, ..., 360 degrees
\obj{\iAngle}
}%
\end{animateinline}%

\end{document}

结果

在此处输入图片描述

使用获得这个答案,即通过添加export动画选项,然后将多页 pdf 转换为动画 gif。

如果你只想旋转盒子的位置,而不是它们的方向,请尝试

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\usepackage[autoplay,loop,nomouse]{animate}

\newcommand{\obj}[1]{
\begin{tikzpicture}
%% Large circle
\path[use as bounding box] (-2.5in,-2.5in) rectangle (2.5in,2.5in) ;
\begin{scope}[rotate=#1]
\draw (0,0) circle [radius=2.25in,very thick];
\node at (3.5cm,3.5cm) [rectangle,minimum size=1cm,fill=black,draw=black,rotate=45] () {};
\node at (3cm,2cm) [rectangle, minimum size=.5cm,fill=black,draw=black,rotate=25] () {};
\node at (1.75cm,1.5cm) [rectangle, minimum size=.25cm,fill=black,draw=black,rotate=80] () {};
\end{scope}
\end{tikzpicture}
}

\begin{document}

\begin{animateinline}[controls]{72}%
\multiframe{72}{iAngle=0+5}{%
%iAngle = 80, 90, ..., 360 degrees
\obj{\iAngle}
}%
\end{animateinline}%

\end{document}

在此处输入图片描述

相关内容