
여기에 제시된 애니메이션을 수정하려고 합니다.예: 사인 및 코사인 함수 애니메이션을 포함하므로 phase
회전은 매번 다른 각도에서 시작됩니다. 즉, phase =[0, 45 ,-45]
아래와 같이 foreach를 사용했으며 원본 애니메이션은 다음과 같습니다.예: 사인 및 코사인 함수 애니메이션, 하지만 코드가 작동하지 않았습니다(내가 받고 있는 오류를 확인하려면 애니메이션과 관련된 명령의 주석 처리를 제거하십시오).
\documentclass[tikz]{standalone}
\usepackage{tikz}
\begin{document}
%\newcounter{theangle}
%\setcounter{theangle}{0}
\begin{tikzpicture}
\def\angle{45};
\fill[fill=red] (0,0) -- plot [domain=0:pi/180*\angle] (\x,{sin(\x r)}) -- (pi/180*\angle,0) -- cycle;
\end{tikzpicture}
%\begin{animateinline}[loop, poster = first,controls]{40}
%
%\foreach \angle in {0,45,-45}
%\whiledo{\angle<359}{
\foreach \angle in {0,10,...,360}
{
\begin{tikzpicture}
%\fill[blue!50] (-1,0) arc (0:\angle:1) -- (-2,0) -- cycle;
%\fill[blue!50] plot[smooth,domain=0:\angle] (pi/180*\x,{sin(\x)}) |- (0,0);
\def\radangle{pi/180*\angle};
\fill[blue!50] (-1,0) arc (0:\angle:1) -- (-2,0) -- cycle;
%\fill[fill=red] (0,0) -- plot [domain=0:\radangle] (\x,{sin(\x r)}) -- (\radangle,0) -- cycle;
\draw (-2,0) +(\angle:1) circle (2pt) -- (pi/180*\angle,{sin(\angle)}) circle (2pt);
\draw (-3.5,0) -- (7,0);
\foreach \deg in {90, 180, 270, 360}
\draw (pi/180*\deg,2pt) -- (pi/180*\deg,-2pt) node[below] {$\deg^\circ$};
\draw (0,-1.2) -- (0,1.2);
\foreach \y in {-1,-0.5,0.5,1}
\draw (2pt,\y) -- (-2pt,\y) node[left] {$\y$};
\draw plot[smooth,domain=0:360] (pi/180*\x,{sin(\x)});
\draw (-2,0) circle (1);
\end{tikzpicture}
%
% \stepcounter{theangle}
% \ifthenelse{\theangle<359}{\newframe}{
% \end{animateinline}}
}
\end{document}
답변1
\clist_map_inline:nn
이 예 에서는 TikZ 대신 LaTeX3을 사용하여 \foreach
쉼표로 구분된 위상 변이 목록을 반복합니다. 어떤 이유로 \foreach
내부에서는 작동하지 않습니다 animateinline
.
일부 일시정지( \newframe*
)는 적절한 애니메이션 지점에 배치됩니다. 계속하려면 재생 버튼이나 애니메이션 위젯을 클릭하세요.
(SVG 버전을 보시려면 Firefox가 조금 느리기 때문에 Chromium 기반 브라우저를 권장합니다.)
\documentclass{standalone}
\usepackage[T1]{fontenc}
\usepackage{tikz,animate}
\ExplSyntaxOn
\let\clistMap\clist_map_inline:nn
\ExplSyntaxOff
\newcommand{\drawit}[2]{% #1 angle (0<=#1<=360)
\begin{tikzpicture} % #2 phase shift
\pgfmathsetmacro\angleRad{pi/180*(#1+#2)}
\pgfmathsetmacro\angleDeg{#1+#2}
\pgfmathsetmacro\unshiftedRad{pi/180*(#1)}
\fill[blue!50] (-2,0) -- ++(#2:1) arc (#2:\angleDeg:1) -- cycle;
\draw (-2,0) +(\angleDeg:1) circle (2pt) -- (\unshiftedRad,{sin(\angleDeg)}) circle (2pt);
\draw (-3.5,0) -- (7,0);
\foreach \deg in {90, 180, 270, 360}
\draw (pi/180*\deg,2pt) -- (pi/180*\deg,-2pt) node[below] {$\deg^\circ$};
\draw (0,-1.2) -- (0,1.2);
\foreach \y in {-1,-0.5,0.5,1}
\draw (2pt,\y) -- (-2pt,\y) node[left] {$\y$};
\draw plot[smooth,domain=0:360] (pi/180*\x,{sin(\x+#2)});
\draw (-2,0) circle (1);
\node [anchor=north east] at (current bounding box.north east) {$\varphi=#2^\circ$};
\end{tikzpicture}%
}
\begin{document}
\begin{animateinline}[controls]{30}
\clistMap{0,45,-45}{%
\drawit{0}{#1}
\newframe*
\multiframe{360}{i=1+1}{\drawit{\i}{#1}}%
\ifthenelse{#1=-45}{}{\newframe*}%
}
\end{animateinline}
\end{document}