# The belt for chain of gears

I want to draw like this

Gears I created based on rpapa's codes.

\documentclass{article}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\newcommand{\gear}[3]{%
\def\modu{#1}
\def\Zb{#2}
\def\AngleA{#3}

\pgfmathsetmacro{\Rpr}{\Zb*\modu/2}
\pgfmathsetmacro{\Rb}{\Rpr*cos(\AngleA)}
\pgfmathsetmacro{\Rt}{\Rpr+\modu}
\pgfmathsetmacro{\Rp}{\Rpr-1.25*\modu}
\pgfmathsetmacro{\AngleT}{pi/180*acos(\Rb/\Rt)}
\pgfmathsetmacro{\AnglePr}{pi/180*acos(\Rb/\Rpr)}
\pgfmathsetmacro{\demiAngle}{180/\Zb}
\pgfmathsetmacro{\Angledecal}{(\demiAngle-2*\AnglePr)/2}

\foreach \zz in{1,2,...,\Zb}{
\draw[DarkSlateGray!70!Sepia]
({(\zz))/\Zb*360-\Angledecal}:\Rb)
-- (\zz/\Zb*360-\Angledecal:\Rp)
to[bend right=\demiAngle]
(\zz/\Zb*360+\Angledecal:\Rp)
--
plot[domain=-0:\AngleT,smooth,variable=\t]
({{180/pi*(-\t+tan(180/pi*\t)) +\zz/\Zb*360+\Angledecal}:\Rb/cos(180/pi*\t)})
%
to[bend right=\demiAngle]
({{180/pi*(\AngleT+tan(180/pi*-\AngleT)) +(\zz+1)/\Zb*360-\Angledecal}:
\Rb/cos(180/pi*-\AngleT)})
%
plot[domain=-\AngleT:-0,smooth,variable=\t]
({{180/pi*(-\t+tan(180/pi*\t)) +(\zz+1)/\Zb*360-\Angledecal}:\Rb/cos(180/pi*\t)});
}
}

\begin{document}

\centering
\begin{tikzpicture}[scale=0.05]
\gear{3}{32}{20}
\path[fill=DarkSlateGray!70!Sepia] circle(40);
\draw[thick,double distance=2pt,fill=white] circle(20) ;
\begin{scope}[xshift=100cm,rotate=180/16]
\gear{3}{16}{20}
\path[fill=DarkSlateGray!70!Sepia] circle(17.5);
\draw[thick,double distance=2pt,fill=white] circle(8);
\end{scope}
\end{tikzpicture}

\end{document}


How do I draw the belt?

• What's the problem? Note that user-uploaded images are currently invisible to me. They'll come back in a bit, I expect - they usually do - but, meanwhile, it would help if you said what your question is. (When I say user-uploaded, I mean everything - including my own, your avatar. When they disappear, they don't do things by halves.) – cfr Jul 7 '15 at 1:05
• How do I draw the belt? (edited) – kalakay Jul 7 '15 at 2:00
• Sorry, does it relate to an internet connection? – kalakay Jul 7 '15 at 2:07
• I don't think so. Just all of a sudden my browser becomes convinced that all user-uploaded images have dimensions 0x0 pixels. So they disappear. Although this can't be quite right as it actually shows me alternative text if available. (I always provide this when uploading images for my own posts.) And then, a bit later, they all come back again. But my connection is fine. Other sites are fine. Other aspects of this site (e.g. non-user-uploaded images) are fine. – cfr Jul 7 '15 at 2:11
• The teeth of gears and the teeth of sprockets are different: chain-guide.com/basics/2-1-2-engagement-with-sprockets.html – Paul Gaborit Jul 7 '15 at 4:44

An example using the tangent coordinate system and the math, calc and decoration libraries. The tangent coordinate system requires nodes, so I guess in a "proper" application with more fancy wheels they would need to be created invisibly.

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc,math,decorations}
\state{start}[width=0pt, next state=draw,
persistent precomputation={
}]{}
\draw
}
}
\begin{document}
\begin{tikzpicture}[wheel/.style={fill=gray!70, circle, minimum size=#1*2cm}]
\tikzmath{%
coordinate \p;
\p1 = (0,0); \p2 = (4,0);
\r1 = 2; \r2 = 1;
{
\node [wheel=\r1] (big) at (\p1) {};
\node [wheel=\r2] (little) at (\p2) {};
};
\p3 = (tangent cs:node=big, point={(little.north)});
\a = atan2(\py3-\py1, \px3-\px1);
}
($(\p1)+(\a:\r1)$)  arc (\a:360-\a:\r1) --
($(\p2)+(-\a:\r2)$) arc (-\a:\a:\r2)    -- cycle;
\end{tikzpicture}
\end{document}


And just a follow-up to John Kormylo's excellent answer, here is a gears pic. Note, that the pic specification uses unit-less numbers for gear size (diameter) and x-y coordinates to delay the conversion to points. This helps to avoid math overflow or unexpected output when the coordinates have units but the size does not (or vice versa).

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{math,calc}
\tikzset{%
set gear dots/.style={
gear dots/.style={dash pattern=on 4pt off 4pt, dash phase=#1}},
set gear dots=0pt,
pics/gears/.style args={size #1 at (#2,#3) and size #4 at (#5,#6)}{code={
\tikzmath{%
\r1 = #1/2; \r2 = #4/2;
\gm = atan2(#3-#6, #2-#5);
\th = acos((\r1 == \r2) ? 0 : (\r2-\r1) / veclen(#5-#2, #6-#3));
coordinate \c, \t;
\c1 = (#2, #3); \t1 = (\c1) + (360-\th+\gm:\r1);
\c2 = (#5, #6); \t2 = (\c2) + (\th+\gm:\r2);
}
\draw [black!80, thick, fill=gray!25] (\c1) circle [radius=\r1];
\draw [black!80, thick, fill=gray!25] (\c2) circle [radius=\r2];
\draw [gray, ultra thick, postaction={draw=gray!50, gear dots, ultra thick}]
(\t2) arc (\th+\gm:360-\th+\gm:\r2) --
(\t1) arc (360-\th+\gm:360+\th+\gm:\r1) -- cycle;
}}}
\begin{document}
\foreach \i in {0,...,7}{
\tikz[set gear dots=\i]{
\pic {gears={size 1 at (1,-1) and size 2 at (3,2)}};
\pic {gears={size 1 at (-1,0) and size 1 at (-1,3)}};
\pic {gears={size 0.5 at (-1,3) and size 1 at (3,2)}};
\pic {gears={size 0.5 at (-1,0) and size 0.25 at (1,-1)}};
}}
\end{document}


• Question Why aren't there any comments? Answer Because we are speechless. – Manuel Jul 8 '15 at 19:20
• @markwibrow The object/tool gears needs to be one of the tikz libraries. Is there one devoted to mechanical engineering or physics items. And the accepted answer for tex.stackexchange.com/questions/14901/… should also be in that library. – R. Schumacher Jul 8 '15 at 21:12

The source code for the above tikzpicture is:

\begin{tikzpicture}[every node/.style={inner sep=1pt}]
\footnotesize
\draw[red] (0,0) -- (3,0) node[midway,above] {$b$}
-- (6,0)node[midway,above] {$a$} node[right]{P};
node[midway,above right=-1pt] {$\theta$};
\coordinate (A1) at ({cos(80.4)},{sin(80.4)});
\coordinate (A2) at ({cos(80.4)},{-sin(80.4)});
\coordinate (B1) at ({3+0.5*cos(80.4)}, {0.5*sin(80.4)});
\coordinate (B2) at ({3+0.5*cos(80.4)},{-0.5*sin(80.4)});
\draw[red] (A1) -- (0,0) node[midway,left] {$r_2$} -- (A2);
\draw[red] (B1) -- (3,0) node[midway,left] {$r_1$} -- (B2) -- (6,0) -- cycle;
\draw[blue,thick] (B2) arc[radius=0.5,start angle=-80.4,end angle=80.4] -- (A1)
\end{tikzpicture}

• I am, of course, open to correction, but I think that your code requires \usetikzlibrary{intersections}'. – sgmoye Jul 7 '15 at 11:25
• @sgmove - For the original answer, yes (sorry about that). For the revised answer, no. – John Kormylo Jul 7 '15 at 16:24

Here's a Metapost function to produce the necessary "drive belt" path. Given two arbitrary circles it returns the path consisting of the two mutual tangents and the relevant arcs.

prologues := 3;
outputtemplate := "%j%c.eps";

% given two circular paths return the "drive belt" around them
vardef drive_belt(expr a,b) =
save R,r,d,t,p; numeric R,r,d,t,p;
R = length (point 0 of a - center a);
r = length (point 0 of b - center b);
d = length (center b - center a);
t = angle  (center b - center a);
if R=r:
p = 2;
else:
p = (angle (r, d*(r/(R-r)) +-+ r ))/45;
if r>R: p:=4-p; fi
fi
subpath(p,8-p) of a rotatedabout(center a, t) --
subpath(0-p,p) of b rotatedabout(center b, t) -- cycle
enddef;

beginfig(1);
path A, B;

A = fullcircle scaled 55;
B = fullcircle scaled 21 shifted (89,34);
fill A withcolor .8[blue, white];
fill B withcolor .8[red, white];
label("A", center A);
label("B", center B);

draw drive_belt(A,B);

endfig;

end.
`

You'll get an error from MP if one circle is contained within the other.