21

I intend to define the first circle set at x = 0 and y = 0 and the other circles depending on it.

enter image description here

I will have to change the diameters of these circles a few times, so the centers of these will change.

\documentclass{article}
\usepackage{tikz}
\begin{document}
    \begin{tikzpicture}
    \draw[very thick] (0mm,0mm) circle (10mm/2);
    \draw[very thick] (20mm,0mm) circle (30mm/2);
    \draw[very thick] (43mm,0mm) circle (25mm/2);
    \draw[very thick] (43mm,0mm) circle (16mm/2);   
    \draw[very thick] (66.5mm,0mm) circle (22mm/2);
    \end{tikzpicture}
\end{document}

What would be the best way to optimize this drawing?

  • 1
    I would recommend to look into tikzmath. Note tikzmath converts all units into pt. Tikzpicture on the other hand uses cms as default. If you want to make it a macro, suggest to use pgf keys. – berkus Jul 10 '17 at 20:28
  • 3
    My apologies if this comment offends any LaTeX/tikz enthusiast: for a technical drawing like this I would always use a proper CAD software, export the drawing (to PDF) and insert the graphic in the document. I wouldn't bother trying to typset the standartised annotations and dimensions correctly... – Mace Jul 10 '17 at 22:28
  • 2
    I teach SolidWorks in Brazil and have been working with CAD softwares for 20 years. Here I am a mere apprentice. It's always good to learn. By coincidence, the tecnical drawing I available I created in SolidWorks. – Luciano Jul 11 '17 at 9:31
16

First version

Just for fun.

\documentclass{standalone}
\usepackage{tikz}
\tikzset{
  % gear with same center
  gearbox/s/.code n args={3}{% prevdiameter, diameter, style 
    \path[#3] (c) circle (#2/2);
  },
  % gear on the right
  gearbox/r/.code n args={3}{% prevdiameter, diameter, style
    \path (c) ++({#1/2 + #2/2},0) coordinate (c);
    \path[#3] (c) circle (#2/2);
  },
  % a styled chain of gears
  gearbox/chain/.code 2 args={% start point, list of gears
    \coordinate (c) at #1;
    \foreach \diameter/\typeofgear/\mystyle
    [remember=\diameter as \prevdiameter (initially 0)] in {#2}{
      \tikzset{gearbox/\typeofgear={\prevdiameter}{\diameter}{\mystyle}}
    }
  },
}
\begin{document}
\begin{tikzpicture}
  \tikzset{s1/.style={draw,thick},s2/.style={draw=red,thick},s3/.style={draw=blue,thick,dashed}}
  \tikzset{
    gearbox/chain={(0,0)}{10mm/s/s1,30mm/r/s1,16mm/r/s1,25mm/s/s1,22mm/r/s1},
    gearbox/chain={(0,3cm)}{30mm/s/s2,9mm/r/s3,25mm/s/s1,13mm/r/s3,22mm/s/s1,30mm/r/s2},
  }
\end{tikzpicture}
\end{document}

enter image description here

New version

A new version with annotations and layers.

\documentclass{standalone}
\usepackage{tikz}
\pgfdeclarelayer{a}
\pgfdeclarelayer{b}
\pgfsetlayers{b,a,main}
\usepackage{amssymb}
\tikzset{
  % draw gear with diameter
  gearbox/gear with diameter/.code n args={4}{% diameter, angle, style, layer
    \pgfmathsetmacro{\r}{#1 mm/2};
    \begin{pgfonlayer}{\layer}
      \path[#3] (c) circle (\r pt);
    \end{pgfonlayer}
    \draw[gray!50!black,-latex] (c) +(#2:\r pt+1.5cm) -- node[pos=.2,above,sloped]{$\varnothing #1$} +(#2:\r pt);
    \draw[gray!50!black] (c) +(#2:\r pt) -- +(180+#2:\r pt);
    \draw[gray!50!black,-latex] (c) +(180+#2:\r pt+5mm) -- +(180+#2:\r pt);
    \draw[gray!50,dashed] (c)
    +(0:\r pt + 1cm) -- +(180:\r pt)
    +(90:20mm) -- +(-90:20mm);
  },
  % gear with same center
  gearbox/s/.code n args={4}{% prevdiameter, diameter, style, layer
    \tikzset{gearbox/gear with diameter={#2}{110}{#3}{#4}}
  },
  % gear on the right
  gearbox/r/.code n args={4}{% prevdiameter, diameter, style, layer
    \pgfmathsetmacro{\gearpos}{\gearpos+#1/2+#2/2}
    \global\let\gearpos\gearpos
    \draw[-latex] ([yshift=-20mm]c) -- ++({#1 mm/2 + #2 mm/2},0);
    \path (c) ++({#1 mm/2 + #2 mm/2},0) coordinate (c);
    \tikzset{gearbox/gear with diameter={#2}{70}{#3}{#4}}
    \path ([yshift=-20mm]c) node[below=1mm,fill=white,inner sep=.1em]{\gearpos};

  },
  % a styled chain of gears
  gearbox/chain/.code 2 args={
    \pgfmathsetmacro{\gearpos}{0};
    \coordinate (c) at #1;
    \foreach \diameter/\typeofgear/\mystyle/\layer
    [remember=\diameter as \prevdiameter (initially 0)] in {#2}{
      \tikzset{gearbox/\typeofgear={\prevdiameter}{\diameter}{\mystyle}{\layer}}
    }
  },
}

\begin{document}
\begin{tikzpicture}
  \tikzset{
    s1/.style={draw,thick,fill=white},
    s2/.style={draw=red,thick,fill=red!10},
    s3/.style={draw=blue,thick,fill=blue!10},
  }
  \tikzset{
    gearbox/chain={(0,0)}{10/s/s1/a,30/r/s1/a,16/r/s1/a,25/s/s1/b,22/r/s1/a},
    gearbox/chain={(0,6cm)}{30/s/s2/a,8/r/s2/a,25/s/s1/b,22/r/s1/b,13/s/s3/a,30/r/s3/a},
  }
\end{tikzpicture}
\end{document}

enter image description here

|improve this answer|||||
17

You can use coordinates for the centers of the circles. You can use quite a lot of derivations when defining those. Here I have defined some diameters for the circles that can be changed. It is not the complete picture but might be a good start.

\documentclass[border=5mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc}
\begin{document}
\begin{tikzpicture}[x=1mm,y=1mm,>=latex]
  \newcommand\Di{10}  %% Diamater of left circle
  \newcommand\Dii{30}  %% Diameter of next circle
  \newcommand\Diiia{16}  %% Diamater of inner circle
  \newcommand\Diiib{25} %% Diameter of outer circle
  \newcommand\Div{22}  %% Diameter of right circle
  \coordinate (C1) at (0,0);
  \coordinate (C2) at (\Di/2+\Dii/2,0);
  \coordinate (C3) at ($(C2)+(\Dii/2+\Diiia/2,0)$);
  \coordinate (C4) at ($(C3)+(\Diiib/2+\Div/2,0)$);
  %% 
  \draw[thick] (C1) circle (\Di/2);
  \draw[thick] (C3) circle (\Diiia/2);
  \draw[thick] (C3) circle (\Diiib/2);
  \draw[fill=white,thick] (C2) circle (\Dii/2);
  \draw[thick] (C4) circle (\Div/2);
  %% 
  \draw[gray!70] ($(C1)+(0,-30)$) -- +(0,30+\Di/2+3) node[pos=0,left,rotate=90,black]{0};
  \pgfmathparse{\Di/2+\Dii/2}\edef\res{\pgfmathresult}
  \draw[gray!70] ($(C2)+(0,-30)$) -- +(0,30+\Dii/2+3) node[pos=0,left,rotate=90,black]{\res};
  \pgfmathparse{\res+\Dii/2+\Diiia/2}\edef\res{\pgfmathresult}
  \draw[gray!70] ($(C3)+(0,-30)$) -- +(0,30+\Diiib/2+3) node[pos=0,left,rotate=90,black]{\res};
  \pgfmathparse{\res+\Diiib/2+\Div/2}\edef\res{\pgfmathresult}
  \draw[gray!70] ($(C4)+(0,-30)$) -- +(0,30+\Div/2+3) node[pos=0,left,rotate=90,black]{\res};
  \draw[gray!70] ($(C1)+(-\Di/2-3,0)$) -- ($(C4)+(\Div/2+3,0)$);
  %%
  \draw (C1 |- {(0,-28)}) circle (1pt);
  \draw[->] (C1 |- {(0,-28)}) -- (C2 |- {(0,-28)});
  \draw[->] (C2 |- {(0,-28)}) -- (C3 |- {(0,-28)});
  \draw[->] (C3 |- {(0,-28)}) -- (C4 |- {(0,-28)});
\end{tikzpicture}
\end{document}

enter image description here

Edit

To add the diameters load \usepackage{wasysym} and append the following to the picture:

  \newcommand\DrawDiameter[3]{% {<center>}{<angle>}{<diameter>}
    \ifnum#2<90\relax
      \draw[->] (#1) +(#2:#3/2+15) -- +(#2:#3/2) node[anchor=south east,pos=0,rotate=#2]{\diameter#3};
    \else
      \draw[->] (#1) +(#2:#3/2+15) -- +(#2:#3/2) node[anchor=south west,pos=0,rotate=180+#2]{\diameter#3};
    \fi
    \draw[gray!70] (#1) +(#2:#3/2) -- +(180+#2:#3/2);
    \draw[<-] (#1) ++(180+#2:#3/2) -- +(180+#2:5);
  }
  \DrawDiameter{C1}{110}{\Di}  
  \DrawDiameter{C2}{110}{\Dii}  
  \DrawDiameter{C3}{110}{\Diiia}  
  \DrawDiameter{C3}{70}{\Diiib}
  \DrawDiameter{C4}{110}{\Div}

enter image description here

|improve this answer|||||

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.