7

I can draw individuals gears like the following but I was unable to align them in the following manner. Could you help?

\documentclass{standalone}
\usepackage{tikz}
\usepackage{amsmath,  latexsym, amscd, amsthm}

\newcommand{\gear}[5]{%
\foreach \i in {1,...,#1} {%
  [rotate=(\i-1)*360/#1]  (0:#2)  arc (0:#4:#2) {[rounded corners=1.5pt]
             -- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
}}      

\begin{document}
\begin{tikzpicture}
    \draw[ultra thick] \gear{16}{1.6}{1.8}{10}{2};
     \end{tikzpicture}
\end{document}

enter image description here

16

This should get you started:

Code

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{arrows}

\newcommand{\gear}[5]{%
    \foreach \i in {1,...,#1}
    {   [rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=0.5pt] -- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
    }
}      

\begin{document}

% given
\pgfmathsetmacro{\rOne}{1.6}% inner radius
\pgfmathsetmacro{\nOne}{16}% num teeth
\pgfmathsetmacro{\nTwo}{24}
\pgfmathsetmacro{\toothHeight}{0.2}
\pgfmathsetmacro{\toothFall}{1}% degrees where radius drops from inner to outer
\pgfmathsetmacro{\aOneTwo}{120}% angle from first to second

% computed
\pgfmathsetmacro{\rTwo}{\rOne*\nTwo/\nOne}% via equating tooth lengths
\pgfmathsetmacro{\ROne}{\rOne+\toothHeight}% outer radius
\pgfmathsetmacro{\RTwo}{\rTwo+\toothHeight}
\pgfmathsetmacro{\dOne}{(360/\nOne-\toothFall)/2}% degrees for a tooth; here inner deg = outer deg
\pgfmathsetmacro{\dTwo}{(360/\nTwo-\toothFall)/2}
\pgfmathsetmacro{\distOneTwo}{\rOne+\rTwo+\toothHeight+0.05}

\begin{tikzpicture}
    \draw[thick] \gear{\nOne}{\rOne}{\ROne}{\dOne}{\toothFall};
    \draw[thick, shift={(\aOneTwo:\distOneTwo)}, rotate=5.5] \gear{\nTwo}{\rTwo}{\RTwo}{\dTwo}{\toothFall};
    \draw[-latex] (\aOneTwo:\rOne/2) -- (\aOneTwo:\rOne);
    \draw[-latex, shift={(\aOneTwo:\distOneTwo)}] (\aOneTwo+180:\RTwo/2) -- (\aOneTwo+180:\RTwo);
\end{tikzpicture}

\end{document}

Output

enter image description here


Edit 1: You can chain them together quite easily if you use coordinates to refer to the centers of the gears.

Code

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{arrows, calc}

\newcommand{\gear}[5]{%
    \foreach \i in {1,...,#1}
    {   [rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=0.5pt] -- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
    }
}      

\begin{document}

% given
\pgfmathsetmacro{\rOne}{1.6}% inner radius
\pgfmathsetmacro{\nOne}{17}% num teeth
\pgfmathsetmacro{\nTwo}{23}
\pgfmathsetmacro{\nThree}{19}
\pgfmathsetmacro{\toothHeight}{0.2}
\pgfmathsetmacro{\toothFall}{1}% degrees where radius drops from inner to outer
\pgfmathsetmacro{\aOneTwo}{120}% angle from first to second
\pgfmathsetmacro{\aTwoThree}{20}% angle from first to second

% computed
\pgfmathsetmacro{\rTwo}{\rOne*\nTwo/\nOne}% via equating tooth lengths
\pgfmathsetmacro{\rThree}{\rOne*\nThree/\nOne}% 
\pgfmathsetmacro{\ROne}{\rOne+\toothHeight}% outer radius
\pgfmathsetmacro{\RTwo}{\rTwo+\toothHeight}
\pgfmathsetmacro{\RThree}{\rThree+\toothHeight}
\pgfmathsetmacro{\dOne}{(360/\nOne-\toothFall)/2}% degrees for a tooth; here inner deg = outer deg
\pgfmathsetmacro{\dTwo}{(360/\nTwo-\toothFall)/2}
\pgfmathsetmacro{\dThree}{(360/\nThree-\toothFall)/2}
\pgfmathsetmacro{\distOneTwo}{\rOne+\rTwo+\toothHeight+0.05}
\pgfmathsetmacro{\distTwoThree}{\rTwo+\rThree+\toothHeight+0.05}

\begin{tikzpicture}
    \coordinate (A) at (0,0);
    \coordinate (B) at ($(A)+(\aOneTwo:\distOneTwo)$);
    \coordinate (C) at ($(B)+(\aTwoThree:\distTwoThree)$);  

    \draw[thick, rotate=9] node[align=center] {$\alpha$ \\ \nOne\ Teeth} \gear{\nOne}{\rOne}{\ROne}{\dOne}{\toothFall} ;
    \draw[thick, shift={(B)}, rotate=7] node[align=center] {$\beta$ \\ \nTwo\ Teeth} \gear{\nTwo}{\rTwo}{\RTwo}{\dTwo}{\toothFall};
    \draw[thick, shift={(C)}, rotate=8] node[align=center] {$\gamma$ \\ \nThree\ Teeth} \gear{\nThree}{\rThree}{\RThree}{\dThree}{\toothFall};

    \draw[-latex, very thick] (\aOneTwo:\rOne/2) -- (\aOneTwo:\rOne);
    \draw[-latex, very thick, shift={(B)}] (\aOneTwo+180:\rTwo/2) -- (\aOneTwo+180:\rTwo);

    \draw[-latex, very thick, shift={(B)}] (\aTwoThree:\rTwo/2) -- (\aTwoThree:\rTwo);
    \draw[-latex, very thick, shift={(C)}] (\aTwoThree+180:\rThree/2) -- (\aTwoThree+180:\rThree);
\end{tikzpicture}

\end{document}

Output

enter image description here


Edit 2: Just for fun, here's a little animation made from it. After producing the .pdf, it used ImageMagick to convert it: convert -loop 0 -delay 2 -density 250 -dispose previous richard.pdf gear.gif

Code

\documentclass[tikz, border=2mm]{standalone}
\usetikzlibrary{arrows, calc}

\newcommand{\gear}[5]{%
    \foreach \i in {1,...,#1}
    {   [rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=0.5pt] -- (#4+#5:#3)  arc (#4+#5:360/#1-#5:#3)} --  (360/#1:#2)
    }
}      

\begin{document}

% given
\pgfmathsetmacro{\rOne}{1.6}% inner radius
\pgfmathsetmacro{\nOne}{17}% num teeth
\pgfmathsetmacro{\nTwo}{23}
\pgfmathsetmacro{\nThree}{19}
\pgfmathsetmacro{\toothHeight}{0.2}
\pgfmathsetmacro{\toothFall}{1}% degrees where radius drops from inner to outer
\pgfmathsetmacro{\aOneTwo}{120}% angle from first to second
\pgfmathsetmacro{\aTwoThree}{20}% angle from first to second

\pgfmathtruncatemacro{\numFrames}{50}% number of individual pictures

% computed
\pgfmathsetmacro{\rTwo}{\rOne*\nTwo/\nOne}% via equating tooth lengths
\pgfmathsetmacro{\rThree}{\rOne*\nThree/\nOne}% 
\pgfmathsetmacro{\ROne}{\rOne+\toothHeight}% outer radius
\pgfmathsetmacro{\RTwo}{\rTwo+\toothHeight}
\pgfmathsetmacro{\RThree}{\rThree+\toothHeight}
\pgfmathsetmacro{\dOne}{(360/\nOne-\toothFall)/2}% degrees for a tooth; here inner deg = outer deg
\pgfmathsetmacro{\dTwo}{(360/\nTwo-\toothFall)/2}
\pgfmathsetmacro{\dThree}{(360/\nThree-\toothFall)/2}
\pgfmathsetmacro{\distOneTwo}{\rOne+\rTwo+\toothHeight+0.05}
\pgfmathsetmacro{\distTwoThree}{\rTwo+\rThree+\toothHeight+0.05}

\pgfmathsetmacro{\rotOne}{(360/\nOne/\numFrames}
\pgfmathsetmacro{\rotTwo}{(360/\nTwo/\numFrames}
\pgfmathsetmacro{\rotThree}{(360/\nThree/\numFrames}

\foreach \frame in {1,...,\numFrames}
{   \begin{tikzpicture}
        \coordinate (A) at (0,0);
        \coordinate (B) at ($(A)+(\aOneTwo:\distOneTwo)$);
        \coordinate (C) at ($(B)+(\aTwoThree:\distTwoThree)$);  

        \draw[white] (-4.5,-1.9) rectangle (4,7);

        \draw[thick, rotate=9+\frame*\rotOne] node[align=center] {$\alpha$ \\ \nOne\ Teeth} \gear{\nOne}{\rOne}{\ROne}{\dOne}{\toothFall} ;
        \draw[thick, shift={(B)}, rotate=7-\frame*\rotTwo] node[align=center] {$\beta$ \\ \nTwo\ Teeth} \gear{\nTwo}{\rTwo}{\RTwo}{\dTwo}{\toothFall};
        \draw[thick, shift={(C)}, rotate=8+\frame*\rotThree] node[align=center] {$\gamma$ \\ \nThree\ Teeth} \gear{\nThree}{\rThree}{\RThree}{\dThree}{\toothFall};

        \draw[-latex, very thick] (\aOneTwo:\rOne/2) -- (\aOneTwo:\rOne);
        \draw[-latex, very thick, shift={(B)}] (\aOneTwo+180:\rTwo/2) -- (\aOneTwo+180:\rTwo);

        \draw[-latex, very thick, shift={(B)}] (\aTwoThree:\rTwo/2) -- (\aTwoThree:\rTwo);
        \draw[-latex, very thick, shift={(C)}] (\aTwoThree+180:\rThree/2) -- (\aTwoThree+180:\rThree);
    \end{tikzpicture}
}

\end{document}

Output

enter image description here

  • 1
    You can also play around with it and animate it. – Tom Bombadil Oct 14 '15 at 12:32
  • There is a bulb on the upper right corner. – Artificial Hairless Armpit Oct 14 '15 at 15:26
  • 1
    @YasashiiEirian: That, unfortunately, is not due to my brilliance, but rather some feature of Adobe Reader. – Tom Bombadil Oct 15 '15 at 6:30
  • I can not draw this. Could you help to complete the figure? – Thumbolt Nov 4 '15 at 2:35
  • @Thumbolt: Yes. Please see the edit (in a few minutes). – Tom Bombadil Nov 4 '15 at 7:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.