17

I tried to draw the picture on the left, but there was nothing I could do about the picture on the right.

It seems to be involved in the field of gear transmission.

It would be great if a warm-hearted friend could make an animation.

enter image description here

\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}

enter image description here

D.Matthew
  • 385

4 Answers4

25

Compile with Asymptote.

picture 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));

enter image description here

picture 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));

enter image description here

Animation. (BAD CODE)

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-a180/pi),Arrow()); draw((0+a,1)--(0+a,1)+dir(180+-90-a180/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=alphapir/180 (wikipedia)

path arc1=(a != 0.0) ? arc((0+a,1),1,-90,-90-a180/pi) : nullpath, // r=1 arc2=(a != 0.0) ? arc((0+a,1),1,90,90-a180/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));

enter image description here

Good animation. (RECOMMENDED)

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-a180/pi),Arrow()); draw((0+a,1)--(0+a,1)+dir(180+-90-a180/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=alphapir/180 (wikipedia) path arc1=arc((0+a,1),1,-90,-90-a180/pi), // r=1 arc2=arc((0+a,1),1,90,90-a180/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

enter image description here

16

Here is a TiKZ solution that is a slightly enhanced version of the OP and is animated using

convert -delay 5 -loop 0 -density 200 -background white -alpha remove file.pdf file.gif

to produce:

enter image description here

To get this from the MWE we first modify the code to allow the arrows to be at arbitrary angles, so that we have

enter image description here

Here is the modified tikzpicture from the MWE that produces this:

  \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}%
  }

The stationary version is a little distracting to watch but it already contains everything that we need to make the picture roll. The main difference between the stationary and the rolling version is that we need to shift the x-coordinates of most of the nodes by \dist. Here is the final code:

\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); \drawblue,thick arc (270:540-\ang:1); \drawblue,thick arc (90:\ang-180:1); \draw[red,thick] (\dist,0) arc (270:\ang:1); \end{tikzpicture}% } \end{document}

  • +1. Interesting solution without animated package! is that code a cmd code for converting to gif? –  Sep 22 '20 at 05:39
  • Yes, you run this from the command line. The convert command is part of ImageMagick. I learned this trick from a post by marmot, or their sobriquet Schrodinger's cat, back in the good old days when they graced these pages. –  Sep 22 '20 at 06:32
15

The moving observers view, made with TikZ.

\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); \drawblue,thick arc (-90:180-\iAngle:1); \drawblue,thick arc (90:\iAngle-180:1); \draw[red,thick] (\dist,0) arc (270:\iAngle:1); \end{tikzpicture}% } \end{animateinline} \end{document}

AlexG
  • 54,894
  • +1 I toyed a little with using your animate package but as I'd never used it before, and since I should be doing other things, I didn't try. This is a nice tutorial:) –  Sep 23 '20 at 07:32
  • Oh, thank you, @Andrew. Interestingly, in order to get the hatched ground move left and out of the viewport, it is necessary to save it in a PDF XObject (using the xlrbox environment from one of my other packages). A standard LaTeX savebox isn't enough. For some reason, the hatching stands still, similar to the second Gif of your answer. – AlexG Sep 23 '20 at 08:10
12

Like this? No animation.

\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}

enter image description here