如何用 TikZ 绘制两个滚动的圆圈?

如何用 TikZ 绘制两个滚动的圆圈?

我尝试绘制左边的图画,但对右边的图画却无能为力。

好像是涉及齿轮传动领域。

如果有热心朋友能做个动画就好了。

在此处输入图片描述

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usetikzlibrary{patterns,patterns.meta,decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}
\draw (0,1) circle [radius=1];
\draw (0,3) circle [radius=1];
\draw[-stealth] (-0.65,1.3) arc (-200:-260:0.6);
\draw[-stealth] (-0.65,2.7) arc (200:260:0.6);
\draw[{Circle[open, length=1mm]}-Stealth] (0,1) -- (0,0);
\draw[{Circle[open, length=1mm]}-Stealth] (0,3) -- (0,2);
\path[pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}] (-1.5,0) edge[thick] ++(3,0) 
rectangle ++ (3,-0.2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

答案1

使用以下方式编译渐近线

图片1

unitsize(1cm);
import patterns;

path c1=circle((0,1),1),c2=circle((0,3),1);
path arc1=arc((0,1),0.7,-200,-250);
path arc2=arc((0,3),0.7,200,250);

draw(c1^^c2);
draw(arc1,Arrow(size=3));
draw(arc2,Arrow(size=3));
draw((0,1)--(0,0),Arrow());
dot((0,1),FillDraw(white));
draw((0,3)--(0,2),Arrow());
dot((0,3),FillDraw(white));

add("yourpattern",hatch(2mm,dir(45)));
fill(box((-1.5,-0.2),(1.5,0)),pattern("yourpattern"));
draw((-1.5,0)--(1.5,0),0.7bp+black);
shipout(bbox(2mm,invisible));

在此处输入图片描述

图片2

unitsize(1cm);
import patterns;
import graph;
path c1=circle((0,1),1),c2=circle((0,3),1);

draw(c1^^c2);

draw((0,1)--(0,1)+dir(-150),Arrow); 
draw((0,3)--(0,3)+dir(-30),Arrow); 
dot((0,1),FillDraw(white));
dot((0,3),FillDraw(white));

path arc1=arc((0,1),1,210,270), arc2=arc((0,1),1,30,90), arc3=arc((0,3),1,270,330);
path line1=(0,0)--(-length(arc1),0);

add("yourpattern",hatch(2mm,dir(45)));
fill(box((-1.5,-0.2),(1.5,0)),pattern("yourpattern"));
draw((-1.5,0)--(1.5,0),0.6bp+black);
draw(arc1^^line1,0.8bp+red);
draw(arc2^^arc3,0.8bp+blue);
shipout(bbox(2mm,invisible));

在此处输入图片描述

动画片。 (糟糕的代码

import animate;
import patterns;
settings.tex="pdflatex"; 

animation Ani;
unitsize(1cm);
real t=6.284; // arclength(circle((0,1),1))=6.28406679229544
for(real a=0.0; a <= t; a=a+t/50)
{
save();
draw(circle((0+a,1),1)^^circle((0+a,3),1));

draw((0+a,1)--(0+a,1)+dir(-90-a*180/pi),Arrow());
draw((0+a,1)--(0+a,1)+dir(180+-90-a*180/pi),dashed+blue); 
draw((0+a,3)--(0+a,3)+dir(-90+a*180/pi),Arrow());
dot((0+a,1),FillDraw(white));
dot((0+a,3),FillDraw(white));

// L=alpha*pi*r/180 (wikipedia)

path arc1=(a != 0.0) ? arc((0+a,1),1,-90,-90-a*180/pi) : nullpath, // r=1
     arc2=(a != 0.0) ? arc((0+a,1),1,90,90-a*180/pi) : nullpath,
     arc3=(a != 0.0) ? arc((0+a,3),1,-90,-90+a*180/pi) : nullpath;
path line1=(a != 0.0) ? (0,0)--(a,0) : nullpath;

add("yourpattern",hatch(2mm,dir(45)));
fill(box((-1,-0.2),(1+t,0)),pattern("yourpattern"));
draw((-1,0)--(1+t,0),0.6bp+black);
draw(arc2^^arc3,0.8bp+blue);
draw(arc1^^line1,0.8bp+red);

if (a == t){
draw(circle((a,3),1),0.8bp+blue);
draw(circle((a,1),1),0.8bp+red);
}
Ani.add();
restore();
}
erase();
Ani.movie(BBox(2mm,invisible));

在此处输入图片描述

好的动画。受到推崇的

import animate;
import patterns;
settings.tex="pdflatex"; 

animation Ani;
unitsize(1cm);
real t=arclength(circle((0,1),1));
int iter=68;

for (int i=0; i <= iter; ++i)
{
save();
real a=i*t/iter;

draw((0+a,1)--(0+a,1)+dir(-90-a*180/pi),Arrow());
draw((0+a,1)--(0+a,1)+dir(180+-90-a*180/pi),dashed+blue); 
draw((0+a,3)--(0+a,3)+dir(-90+a*180/pi),Arrow());
dot((0+a,1),FillDraw(white));
dot((0+a,3),FillDraw(white));
add("yourpattern",hatch(2mm,dir(45)));
fill(box((-1,-0.2),(1+t,0)),pattern("yourpattern"));
draw((-1,0)--(1+t,0),0.6bp+black);

if (i == 0){
draw(circle((a,3),1));
draw(circle((a,1),1));
}
else if (i < iter){
draw(circle((a,3),1));
draw(circle((a,1),1));
// L=alpha*pi*r/180 (wikipedia)
path arc1=arc((0+a,1),1,-90,-90-a*180/pi), // r=1
     arc2=arc((0+a,1),1,90,90-a*180/pi),
     arc3=arc((0+a,3),1,-90,-90+a*180/pi);
path line1=(0,0)--(a,0);
draw(arc2^^arc3,0.6bp+blue);
draw(arc1^^line1,0.8bp+red);
}
else {
draw(circle((a,3),1),0.6bp+blue);
draw(circle((a,1),1),0.6bp+red);
draw((0,0)--(a,0),0.8bp+red);
}
Ani.add();
restore();
}
erase();
Ani.movie(BBox(2mm,invisible));

https://ezgif.com/pdf-to-gif

在此处输入图片描述

答案2

这里有一个钛合金解决方案是 OP 的稍微增强版本,并使用

转换 -延迟 5 -循环 0 -密度 200 -背景白色 -alpha 删除文件.pdf 文件.gif

生产:

在此处输入图片描述

为了从 MWE 中获得这一点,我们首先修改代码,允许箭头处于任意角度,这样我们就有了

在此处输入图片描述

以下是tikzpicture根据 MWE 修改后的结果:

  \foreach \ang [evaluate=\ang as \dist using {(\ang-270)*pi/180}] in {270,265,...,-85} {%
    \begin{tikzpicture}
      \useasboundingbox (-3.2, -0.3) rectangle (3.2, 4.2);
      \draw (0,1) circle [radius=1];
      \draw (0,3) circle [radius=1];
      \draw[-stealth,red] (-0.65,1.3) arc (-200:-260:0.6);
      \draw[-stealth,blue] (-0.65,2.7) arc (200:260:0.6);
      \path[pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}]
             (-3,0) edge[thick] ++(6,0) rectangle ++ (6,-0.2);
      \draw[-Stealth]  (0,3)node[axel]{} -- ++({180-\ang}:1);
      \draw[-Stealth]  (0,1)node[axel]{} -- ++(\ang:1);
      \draw[red,thick] (0,0) -- ++ (\dist, 0);
      \draw[blue,thick](0,2) arc (270:540-\ang:1);
      \draw[blue,thick](0,2) arc (90:\ang-180:1);
      \draw[red,thick] (0,0) arc (270:\ang:1);
    \end{tikzpicture}%
  }

静止版本看起来有点分散注意力,但它已经包含了使图片滚动所需的一切。静止版本和滚动版本之间的主要区别在于,我们需要将x大多数节点的 - 坐标移动\dist。以下是最终代码:

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usetikzlibrary{patterns,patterns.meta,decorations.pathmorphing}

\tikzset{
  axel/.style = {circle, minimum width=1mm,inner sep=0pt, draw, fill=white}
}

\begin{document}
  \foreach \ang [evaluate=\ang as \dist using {(270-\ang)*pi/180}] in {270,265,...,-85} {%
    \begin{tikzpicture}
      \useasboundingbox (-2, -0.3) rectangle (8, 4.2);
      \draw (\dist,1) circle [radius=1];
      \draw (\dist,3) circle [radius=1];
      \draw[-stealth,red] (\dist-0.65,1.3) arc (-200:-260:0.6);
      \draw[-stealth,blue] (\dist-0.65,2.7) arc (200:260:0.6);
      \path[pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}]
             (-1,0) edge[thick] ++(8,0) rectangle ++ (8,-0.2);
      \draw[-Stealth]  (\dist,3)node[axel]{} -- ++({180-\ang}:1);
      \draw[-Stealth]  (\dist,1)node[axel]{} -- ++(\ang:1);
      \draw[red,thick] (0,0)--(\dist,0);
      \draw[blue,thick](\dist,2) arc (270:540-\ang:1);
      \draw[blue,thick](\dist,2) arc (90:\ang-180:1);
      \draw[red,thick] (\dist,0) arc (270:\ang:1);
    \end{tikzpicture}%
  }
\end{document}

答案3

移动观察者的视角,用 TiZ。

\documentclass{standalone}
%\documentclass[dvisvgm]{standalone}
%\documentclass[export]{standalone}

\usepackage{tikz}
\usetikzlibrary{calc,patterns.meta,arrows.meta}

\usepackage{animate}
\usepackage{xsavebox} % xlrbox

\begin{document}
  \begin{xlrbox}{ground}
    \begin{tikzpicture}
      \path[pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}]
             (-1,0) edge[thick] ++(8,0) rectangle ++ (8,-0.2);
    \end{tikzpicture}%
  \end{xlrbox}%
%
  \begin{animateinline}[controls,loop]{20}
    \multiframe{181}{iAngle=270+-2}{
      \pgfmathsetmacro\dist{(270-\iAngle)*pi/180}%
      \begin{tikzpicture}
        \path[use as bounding box, clip] (\dist-2,-0.3) rectangle (\dist+2,4.2);
        \draw (\dist,1) circle [radius=1];
        \draw (\dist,3) circle [radius=1];
        \draw[-stealth,red] ($(\dist,1)+(\iAngle-110:0.65)$) arc (\iAngle-110:\iAngle-170:0.65);
        \draw[-stealth,blue] ($(\dist,3)+(110-\iAngle:0.65)$) arc (110-\iAngle:170-\iAngle:0.65);
        \node [anchor=north west, inner sep=0pt] at (-1,0) {\theground};
        \draw[dashed,blue] (\dist,1) -- ++(\iAngle-180:1);
        \draw[-Stealth] (\dist,1) -- ++(\iAngle:1);
          \filldraw[fill=white] (\dist,1) circle (0.5mm);
        \draw[-Stealth] (\dist,3) -- ++(180-\iAngle:1);
          \filldraw[fill=white] (\dist,3) circle (0.5mm);
        \draw[red,thick] (0,0)--(\dist,0);
        \draw[blue,thick](\dist,2) arc (-90:180-\iAngle:1);
        \draw[blue,thick](\dist,2) arc (90:\iAngle-180:1);
        \draw[red,thick] (\dist,0) arc (270:\iAngle:1);
      \end{tikzpicture}%
    }
  \end{animateinline}
\end{document}

答案4

像这样吗?没有动画。

\documentclass[tikz,margin=3mm]{standalone}
\usepackage{tikz-cd}
\usetikzlibrary{calc}
\usetikzlibrary{patterns,patterns.meta,decorations.pathmorphing}

\begin{document}
\begin{tikzpicture}
\draw (0,1)coordinate(D) circle [radius=1];
\draw (0,3)coordinate(U) circle [radius=1];

\draw[{Circle[open, length=1mm]}-Stealth] (D) --++ (-150:1);
\draw[{Circle[open, length=1mm]}-Stealth] (U) --++ (-20:1);
\draw[densely dashed, blue] (D) --++ (30:1);
\draw [very thick, red] ([yshift=-1cm]D)coordinate(DD) arc (-90:-150:1);
\draw [very thick, blue] ([yshift=1cm]D) arc (90:30:1);
\draw [very thick, blue] ([yshift=-1cm]U) arc (-90:-20:1);

\path[pattern={Lines[angle=45,distance={4pt/sqrt(2)}]}] (-1.5,0) edge[thick] ++(3,0) rectangle ++ (3,-0.2);
\draw [very thick, red] (DD)--++(180:0.9);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容