条件运动

条件运动

请帮我:

在 \Delta t = 10 秒内,女孩必须做出以下动作:

  1. 在 \Delta t =[0,4[ 秒内从 x=0 移动到 x=40
  2. 停留在 x=40 处,耗时 \Delta t = [4,6] 秒
  3. 在 \Delta t = ]6,10] 中回到 x=0

我的困难在于应用条件:

\whiledo{\NOT{\tempo < 0} \AND \NOT{\tempo > 4}}{\pgfmathsetmacro{\posicaox}{10*\tempo}}

\whiledo{ \tempo > 4 \AND \NOT{\tempo > 6}}{\pgfmathsetmacro{\posicaox}{40}}

\whiledo{ \tempo > 6 \AND \NOT{\tempo > 10}}{\pgfmathsetmacro{\posicaox}{100-10*\tempo}}

位置 1

位置 2

位置 3

位置 4

    \documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage[export]{animate}
%\usepackage{animate}

\begin{document}

\tikzset{
    contadores/.style={
    draw=olive,
    text=red,        
    thick,
    fill=olive!20, 
    rounded corners=2mm, 
    draw, 
    rectangle, 
    align=center, 
    minimum height=0.5cm, 
    minimum width=1.5cm, 
    text width=2.2cm, 
    inner sep=0, 
    thick, 
    outer sep=0
}}

\tikzset{pics/.cd,
    menina/.style={
    code={
    \path[draw={rgb,255:red,240;green,191; blue,186}] (3.0mm,8.0mm) -- (3.0mm,3.8mm) -- (2.0mm,0.0mm) -- (1.0mm,0.0mm);
    \path[draw={rgb,255:red,240;green,191; blue,186}] (3.0mm,3.8mm) -- (4.0mm,0.0mm) -- (5.0mm,0.0mm);
    \path[draw={rgb,255:red,240;green,191; blue,186}] (1.2mm,6.2mm) -- (1.8mm,5.8mm) -- (3.0mm,6.6mm) -- (4.2mm,5.8mm) -- (4.8mm,6.2mm);
    \path[fill={rgb,255:red,240;green,191; blue,186}] (3.0mm,8.0mm) ellipse (0.69mm and 0.59mm);
    \path[fill={rgb,255:red,255;green,000; blue,255}] (1.4mm,1.8mm) -- (2.0mm,4.0mm) -- (4.0mm,4.0mm) -- (4.6mm,1.8mm) -- cycle;
    \path[fill={rgb,255:red,255;green,000; blue,255}] (2.0mm,4.0mm) -- (4.0mm,4.0mm) -- (3.4mm,6.8mm) -- (2.6mm,6.8mm) -- cycle;
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=1.0pt] (2.0mm,4.0mm) -- (4.0mm,4.0mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=0.5pt] (3.0mm,8.7mm) -- (2.2mm,8.2mm) -- (2.2mm,7.2mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=0.5pt] (3.0mm,8.7mm) -- (3.8mm,8.2mm) -- (3.8mm,7.2mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=1.0pt] (1.0mm,0.0mm) -- (2.0mm,0.0mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=1.0pt] (4.0mm,0.0mm) -- (5.0mm,0.0mm);
}}}

\tikzset{pics/.cd,
    casa/.style={
    code={
    \path[fill={rgb,255:red,255;green,200; blue,000}] (0.0mm,0.0mm) -- (6.0mm,0.0mm) -- (6.0mm,4.0mm) -- (0.0mm,4.0mm) -- cycle;
    \path[fill={rgb,255:red,255;green,000; blue,000}] (0.0mm,4.0mm) -- (6.0mm,4.0mm) -- (3.0mm,8.0mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (2.5mm,0.0mm) -- (3.5mm,0.0mm) -- (3.5mm,2.5mm) -- (2.5mm,2.5mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (0.5mm,1.0mm) -- (2.0mm,1.0mm) -- (2.0mm,2.5mm) -- (0.5mm,2.5mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (4.0mm,1.0mm) -- (5.5mm,1.0mm) -- (5.5mm,2.5mm) -- (4.0mm,2.5mm) -- cycle;
}}}

\begin{animateinline}[poster=first,loop,autoplay]{5}
\multiframe{51}{rt=0.0+0.2}{%
\resizebox{0.75\textwidth}{!}{%
\begin{tikzpicture}

    \filldraw[fill={rgb,255:red,072;green,148; blue,000}, draw={rgb,255:red,072;green,148; blue,000}] (-1.6cm,-1.0cm) rectangle (12.4cm,4.0cm  );
    \filldraw[fill={rgb,255:red,072;green,211; blue,225}, draw={rgb,255:red,072;green,211; blue,225}] (-1.6cm, 2.0cm) rectangle (12.4cm,4.0cm  );
    \node[cloud, cloud puffs=25.7, cloud ignores aspect, minimum width=50mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (5cm, 3cm) {};
    \node[cloud, cloud puffs=10.7, cloud ignores aspect, minimum width=30mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (1cm, 3cm) {};
    \node[cloud, cloud puffs=12.7, cloud ignores aspect, minimum width=30mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (9cm, 3cm) {};

\pgfmathsetmacro\tempo{1*\rt}
\pgfmathsetmacro{\posicaox}{10*\tempo} %this line will be removed and replaced by the following

%\whiledo{\NOT{\tempo < 0} \AND \NOT{\tempo >  4}}{\pgfmathsetmacro{\posicaox}{10*\tempo}}
%\whiledo{     \tempo > 4  \AND \NOT{\tempo >  6}}{\pgfmathsetmacro{\posicaox}{40}}
%\whiledo{     \tempo > 6  \AND \NOT{\tempo > 10}}{\pgfmathsetmacro{\posicaox}{100-10*\tempo}}

\coordinate (P1) at (\posicaox/10,0); 
\draw (00.0mm,10.0mm) pic{casa};
\draw (40.0mm,10.0mm) pic{casa};
\draw (P1) pic{menina};

\node[  contadores,
        xshift=0.3cm, 
        yshift=3.1cm] at (P1) {$t=\SI[round-mode=places,round-precision=1]{\tempo}{\second}$};

\node[  contadores,
        xshift=0.3cm, 
        yshift=2.5cm] at (P1) {$x=\SI[round-mode=places,round-precision=1]{\posicaox}{\metre}$};

\end{tikzpicture}}} 
\end{animateinline}
\end{document}

答案1

您无需执行复杂的WHILEDO操作,只需为该位置声明一个函数并让 TiZ 做数学运算。这个函数可以理解为

\tikzset{declare function={posg(\t)=ifthenelse(\t<=4,10*\t,ifthenelse(\t<6,40,40-(\t-6)*10));}}

完整 MWE 和结果:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage[export]{animate}
%\usepackage{animate}

\begin{document}

\tikzset{
    contadores/.style={
    draw=olive,
    text=red,        
    thick,
    fill=olive!20, 
    rounded corners=2mm, 
    draw, 
    rectangle, 
    align=center, 
    minimum height=0.5cm, 
    minimum width=1.5cm, 
    text width=2.2cm, 
    inner sep=0, 
    thick, 
    outer sep=0
}}

\tikzset{pics/.cd,
    menina/.style={
    code={
    \path[draw={rgb,255:red,240;green,191; blue,186}] (3.0mm,8.0mm) -- (3.0mm,3.8mm) -- (2.0mm,0.0mm) -- (1.0mm,0.0mm);
    \path[draw={rgb,255:red,240;green,191; blue,186}] (3.0mm,3.8mm) -- (4.0mm,0.0mm) -- (5.0mm,0.0mm);
    \path[draw={rgb,255:red,240;green,191; blue,186}] (1.2mm,6.2mm) -- (1.8mm,5.8mm) -- (3.0mm,6.6mm) -- (4.2mm,5.8mm) -- (4.8mm,6.2mm);
    \path[fill={rgb,255:red,240;green,191; blue,186}] (3.0mm,8.0mm) ellipse (0.69mm and 0.59mm);
    \path[fill={rgb,255:red,255;green,000; blue,255}] (1.4mm,1.8mm) -- (2.0mm,4.0mm) -- (4.0mm,4.0mm) -- (4.6mm,1.8mm) -- cycle;
    \path[fill={rgb,255:red,255;green,000; blue,255}] (2.0mm,4.0mm) -- (4.0mm,4.0mm) -- (3.4mm,6.8mm) -- (2.6mm,6.8mm) -- cycle;
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=1.0pt] (2.0mm,4.0mm) -- (4.0mm,4.0mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=0.5pt] (3.0mm,8.7mm) -- (2.2mm,8.2mm) -- (2.2mm,7.2mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=0.5pt] (3.0mm,8.7mm) -- (3.8mm,8.2mm) -- (3.8mm,7.2mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=1.0pt] (1.0mm,0.0mm) -- (2.0mm,0.0mm);
    \path[draw={rgb,255:red,000;green,000; blue,000},line width=1.0pt] (4.0mm,0.0mm) -- (5.0mm,0.0mm);
}}}

\tikzset{pics/.cd,
    casa/.style={
    code={
    \path[fill={rgb,255:red,255;green,200; blue,000}] (0.0mm,0.0mm) -- (6.0mm,0.0mm) -- (6.0mm,4.0mm) -- (0.0mm,4.0mm) -- cycle;
    \path[fill={rgb,255:red,255;green,000; blue,000}] (0.0mm,4.0mm) -- (6.0mm,4.0mm) -- (3.0mm,8.0mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (2.5mm,0.0mm) -- (3.5mm,0.0mm) -- (3.5mm,2.5mm) -- (2.5mm,2.5mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (0.5mm,1.0mm) -- (2.0mm,1.0mm) -- (2.0mm,2.5mm) -- (0.5mm,2.5mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (4.0mm,1.0mm) -- (5.5mm,1.0mm) -- (5.5mm,2.5mm) -- (4.0mm,2.5mm) -- cycle;
}}}

\tikzset{declare function={posg(\t)=ifthenelse(\t<=4,10*\t,ifthenelse(\t<6,40,40-(\t-6)*10));}}
\begin{animateinline}[poster=first,loop,autoplay]{5}
\multiframe{51}{rt=0.0+0.2}{%
\resizebox{0.75\textwidth}{!}{%
\begin{tikzpicture}

    \filldraw[fill={rgb,255:red,072;green,148; blue,000}, draw={rgb,255:red,072;green,148; blue,000}] (-1.6cm,-1.0cm) rectangle (12.4cm,4.0cm  );
    \filldraw[fill={rgb,255:red,072;green,211; blue,225}, draw={rgb,255:red,072;green,211; blue,225}] (-1.6cm, 2.0cm) rectangle (12.4cm,4.0cm  );
    \node[cloud, cloud puffs=25.7, cloud ignores aspect, minimum width=50mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (5cm, 3cm) {};
    \node[cloud, cloud puffs=10.7, cloud ignores aspect, minimum width=30mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (1cm, 3cm) {};
    \node[cloud, cloud puffs=12.7, cloud ignores aspect, minimum width=30mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (9cm, 3cm) {};

\pgfmathsetmacro\tempo{1*\rt}
\pgfmathsetmacro{\posicaox}{posg(\tempo)} %this line will be removed and replaced by the following

\coordinate (P1) at (\posicaox/10,0); 
\draw (00.0mm,10.0mm) pic{casa};
\draw (40.0mm,10.0mm) pic{casa};
\draw (P1) pic{menina};

\node[  contadores,
        xshift=0.3cm, 
        yshift=3.1cm] at (P1) {$t=\SI[round-mode=places,round-precision=1]{\tempo}{\second}$};

\node[  contadores,
        xshift=0.3cm, 
        yshift=2.5cm] at (P1) {$x=\SI[round-mode=places,round-precision=1]{\posicaox}{\metre}$};

\end{tikzpicture}}} 
\end{animateinline}
\end{document}

在此处输入图片描述

然而,我不禁觉得这是一个 XY 问题,你真的想要一个 Ti哇喔。;-)

\documentclass{standalone}
\usepackage{tikzlings}
\usetikzlibrary{shapes}
\usepackage[output-decimal-marker={,}]{siunitx}
\usepackage[export]{animate}
%\usepackage{animate}

\begin{document}

\tikzset{
    contadores/.style={
    draw=olive,
    text=red,        
    thick,
    fill=olive!20, 
    rounded corners=2mm, 
    draw, 
    rectangle, 
    align=center, 
    minimum height=0.5cm, 
    minimum width=1.5cm, 
    text width=2.2cm, 
    inner sep=0, 
    thick, 
    outer sep=0
}}

\tikzset{pics/.cd,
    casa/.style={
    code={
    \path[fill={rgb,255:red,255;green,200; blue,000}] (0.0mm,0.0mm) -- (6.0mm,0.0mm) -- (6.0mm,4.0mm) -- (0.0mm,4.0mm) -- cycle;
    \path[fill={rgb,255:red,255;green,000; blue,000}] (0.0mm,4.0mm) -- (6.0mm,4.0mm) -- (3.0mm,8.0mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (2.5mm,0.0mm) -- (3.5mm,0.0mm) -- (3.5mm,2.5mm) -- (2.5mm,2.5mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (0.5mm,1.0mm) -- (2.0mm,1.0mm) -- (2.0mm,2.5mm) -- (0.5mm,2.5mm) -- cycle;
    \path[fill={rgb,255:red,000;green,000; blue,000}] (4.0mm,1.0mm) -- (5.5mm,1.0mm) -- (5.5mm,2.5mm) -- (4.0mm,2.5mm) -- cycle;
}}}

\tikzset{declare function={posg(\t)=ifthenelse(\t<=4,10*\t,ifthenelse(\t<6,40,40-(\t-6)*10));}}
\begin{animateinline}[poster=first,loop,autoplay]{5}
\multiframe{51}{rt=0.0+0.2}{%
\resizebox{0.75\textwidth}{!}{%
\begin{tikzpicture}

    \filldraw[fill={rgb,255:red,072;green,148; blue,000}, draw={rgb,255:red,072;green,148; blue,000}] (-1.6cm,-1.0cm) rectangle (12.4cm,4.0cm  );
    \filldraw[fill={rgb,255:red,072;green,211; blue,225}, draw={rgb,255:red,072;green,211; blue,225}] (-1.6cm, 2.0cm) rectangle (12.4cm,4.0cm  );
    \node[cloud, cloud puffs=25.7, cloud ignores aspect, minimum width=50mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (5cm, 3cm) {};
    \node[cloud, cloud puffs=10.7, cloud ignores aspect, minimum width=30mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (1cm, 3cm) {};
    \node[cloud, cloud puffs=12.7, cloud ignores aspect, minimum width=30mm, minimum height=15mm, align=center, draw=white,fill=white] (cloud) at (9cm, 3cm) {};

\pgfmathsetmacro\tempo{1*\rt}
\pgfmathsetmacro{\posicaox}{posg(\tempo)} %this line will be removed and replaced by the following

\coordinate (P1) at (\posicaox/10,0); 
\draw (00.0mm,10.0mm) pic{casa};
\draw (40.0mm,10.0mm) pic{casa};
\pgfmathtruncatemacro{\mystep}{5*\rt+0.1}
\ifodd\mystep
\marmot[leftstep,whiskers,teeth,shift={([xshift=3mm]P1)},scale=0.4];
\else
\marmot[rightstep,whiskers,teeth,shift={([xshift=3mm]P1)},scale=0.4];
\fi

\node[  contadores,
        xshift=0.3cm, 
        yshift=3.1cm] at (P1) {$t=\SI[round-mode=places,round-precision=1]{\tempo}{\second}$};

\node[  contadores,
        xshift=0.3cm, 
        yshift=2.5cm] at (P1) {$x=\SI[round-mode=places,round-precision=1]{\posicaox}{\metre}$};

\end{tikzpicture}}} 
\end{animateinline}
\end{document}

在此处输入图片描述

相关内容