Here is a starting point and just one of many ideas how to input the data.
The next gear
style takes its arguments in the form of
[<opt>:<text>]<abs angle>:<next gear’s radius>
where
:<text>
and
[<opt>:<text>]
are optional,
<abs angle>
denotes the absolute angle/direction of the next gear and
<next gear’s radius>
specifies the next gear’s radius.
The turtle
library is only used for its forward
style and the \tikz@lib@turtle@dir
macro. To be honest, this could have been coded without the library, but oh well …
Update
Well, hear is a new gear (\ngear[<options>](<point>)
) and a try on an output.
The combination of gears involves a little bit of math as number of teeth, the width of these teeth and the rotation are dependent of the previous gear and its rotation.
You can hijack the \qrr@tikz@do@nextgear@
and insert needed calculations for the next gear on your own.
(You can even re-define \ngear
to act as an front-end to one of the already defined \gear
macros on TeX.sx.)
Code
\documentclass[tikz,convert=false]{standalone}
\usepackage{tikz}
\usetikzlibrary{backgrounds,turtle}
\makeatletter
\newcommand*{\gearset}{\pgfqkeys{/gear}}
\newcommand*{\geargetvalue}[1]{\pgfkeysgetvalue{/gear/#1}}
\gearset{
outer radius/.initial=1cm,
outer height/.initial=5cm,
outer width/.initial=.5cm,
outer number/.initial=10,
outer rotate/.initial=0,
inner radius/.initial=,
inner rotate/.initial=0,
inner height/.initial=.2cm,
inner width/.initial=.2cm,
inner number/.initial=18,
height/.style={/gear/outer height={#1},/gear/inner height={#1}},
width/.style={outer width={#1},inner width={#1}},
% outer outer radius=.4pt, rounded corners?
% inner outer radius=.2pt,
% outer inner radius=.4pt,
% inner inner radius=.2pt,
/tikz/every gear/.style={draw,fill=none,even odd rule,rounded corners=.5pt},
% /tikz/every outer gear/.style={top color=blue, bottom color=green},
% /tikz/every inner gear/.style={draw=blue,fill=white},
}
\newcommand*{\ngear}[1][]{\begingroup\gearset{#1}\ngear@}
\def\ngear@(#1){%
\geargetvalue{outer radius}\qrr@gear@outerR
\geargetvalue{inner radius}\qrr@gear@innerR
\geargetvalue{outer number}\qrr@gear@outerN
\geargetvalue{inner number}\qrr@gear@innerN
\geargetvalue{outer height}\qrr@gear@outerH
\geargetvalue{inner height}\qrr@gear@innerH
\geargetvalue{outer width}\qrr@gear@outerW
\geargetvalue{inner width}\qrr@gear@innerW
\geargetvalue{outer rotate}\qrr@gear@outerRot
\geargetvalue{inner rotate}\qrr@gear@innerRot
\pgfmathsetmacro\qrr@gear@ooArc{(\qrr@gear@outerW)/(\qrr@gear@outerR+\qrr@gear@outerH)/pi*180}%
\pgfmathsetmacro\qrr@gear@ioArc{180/(\qrr@gear@outerN) - \qrr@gear@ooArc}%
\pgfmathsetmacro\qrr@gear@oiArc{(\qrr@gear@innerW)/(\qrr@gear@innerR+\qrr@gear@innerH)/pi*180}%
\pgfmathsetmacro\qrr@gear@iiArc{180/(\qrr@gear@innerN) - \qrr@gear@oiArc}%
\pgfmathtruncatemacro\qrr@gear@outerN{\qrr@gear@outerN-1}%
\pgfmathtruncatemacro\qrr@gear@innerN{\qrr@gear@innerN-1}%
\scope[shift={(#1)}]%
\path[every gear/.try, every outer gear/.try] ({\qrr@gear@outerRot}:{\qrr@gear@outerR+\qrr@gear@outerH})
\foreach \@tooth in {0,...,\qrr@gear@outerN} {
\pgfextra
\pgfmathsetmacro\qrr@gear@sa{\qrr@gear@outerRot+2*\@tooth*(\qrr@gear@ooArc+\qrr@gear@ioArc)}%
\endpgfextra
arc[radius={\qrr@gear@outerR+\qrr@gear@outerH}, start angle=\qrr@gear@sa, delta angle=\qrr@gear@ooArc]
-- (\qrr@gear@sa+\qrr@gear@ooArc:{\qrr@gear@outerR})
arc[radius={\qrr@gear@outerR}, start angle=\qrr@gear@sa+\qrr@gear@ooArc, delta angle=2*\qrr@gear@ioArc]
-- (\qrr@gear@sa+\qrr@gear@ooArc+2*\qrr@gear@ioArc:{\qrr@gear@outerR+\qrr@gear@outerH})
arc[radius={\qrr@gear@outerR+\qrr@gear@outerH}, start angle=\qrr@gear@sa+\qrr@gear@ooArc+2*\qrr@gear@ioArc, delta angle=\qrr@gear@ooArc]
}
\ifx\qrr@gear@innerR\pgfutil@empty\else
% ; % un-comment this and the next line to have two paths
% \path[every gear/.try, every inner gear]
(0:{\qrr@gear@innerR-\qrr@gear@innerH})
\foreach \@tooth in {0,...,\qrr@gear@innerN} {
\pgfextra
\pgfmathsetmacro\qrr@gear@sa{\qrr@gear@innerRot+2*\@tooth*(\qrr@gear@oiArc+\qrr@gear@iiArc)}%
\endpgfextra
arc[radius={\qrr@gear@innerR-\qrr@gear@innerH}, start angle=\qrr@gear@sa, delta angle=\qrr@gear@oiArc]
-- (\qrr@gear@sa+\qrr@gear@oiArc:{\qrr@gear@innerR})
arc[radius={\qrr@gear@innerR}, start angle=\qrr@gear@sa+\qrr@gear@oiArc, delta angle=2*\qrr@gear@iiArc]
-- (\qrr@gear@sa+\qrr@gear@oiArc+2*\qrr@gear@iiArc:{\qrr@gear@innerR-\qrr@gear@innerH})
arc[radius={\qrr@gear@innerR-\qrr@gear@innerH}, start angle=\qrr@gear@sa+\qrr@gear@oiArc+2*\qrr@gear@iiArc, delta angle=\qrr@gear@oiArc]
}
\fi
;
\endscope
\endgroup
}
\def\qrr@tikz@gear@current@radius{0pt}
\def\qrr@tikz@do@nextgear{\pgfutil@ifnextchar[\qrr@tikz@do@nextgear@{\qrr@tikz@do@nextgear@[]}}
\def\qrr@tikz@do@nextgear@[#1]#2:#3\@qrr@tikz@do@nextgear{%
\pgfmathsetmacro\qrr@tikz@gear@distance{\qrr@tikz@gear@current@radius+(#3)+\pgfkeysvalueof{/gear/outer height}}%
\pgfmathsetmacro\qrr@tikz@gear@current@radius{abs(#3)}%
\gdef\tikz@lib@turtle@dir{#2}%
\pgfkeysalso{/tikz/turtle/forward/.expanded=\qrr@tikz@gear@distance pt}
\pgfgetlastxy\pgf@gear@@x\pgf@gear@@y
\pgfkeysalso{/tikz/gear={#1, outer radius=\qrr@tikz@gear@current@radius pt}{\pgf@gear@@x,\pgf@gear@@y}}
}
\tikzset{
gear/.style 2 args={/tikz/insert path={\pgfextra{\ngear[#1](#2)}}},
turtle/next gear/.code=\qrr@tikz@do@nextgear#1\@qrr@tikz@do@nextgear
}
\begin{document}
\begin{tikzpicture}[show background grid,/gear/height=.3cm,every gear/.append style=thick]
\draw[dash pattern={on \pgflinewidth off 2\pgflinewidth},thin] (0,0) [turtle={
next gear/.list={
0:2cm,
{[outer rotate=-90,outer width=.18cm,outer number=10]90:2cm},
{[outer width=.49cm,outer number=14,outer rotate=0]30:3cm},
{[outer width=.2cm,outer rotate=18]120:2cm}
}}];
\end{tikzpicture}
\end{document}
Output
![enter image description here](https://i.stack.imgur.com/K4Llr.png)
I am definitely unfamiliar with both beamer
and tikz
(do not quite get what the \only
are supposed to do) but perhaps this could go in the direction you want:
\documentclass{beamer}
\usepackage{tikz}
\usetikzlibrary{chains}
\newcounter{count}
% helper macro:
\long\def\GobToSemiColon #1;{}
\newcommand\myPicture{
\begin{tikzpicture}
\begin{scope}[start chain = going below]
\ifnum\value{count}<1 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>3 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is between
1 and 3};
\ifnum\value{count}>-1 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only when counter is
negative};
\ifnum\value{count}<100 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>200 \expandafter\GobToSemiColon\fi
\node[draw, rectangle, on chain] {display only if counter is between
100 and 200};
\ifnum\value{count}<3 \expandafter\GobToSemiColon\fi
\ifnum\value{count}>20 \expandafter\GobToSemiColon\fi
\node[draw, circle, on chain] {only when counter is in the range 3 to 20};
\end{scope}
\end{tikzpicture}
}
\begin{document}
\begin{frame}
\only{\setcounter{count}{-3}\myPicture}
\only{\setcounter{count}{105}\myPicture}
\only{\setcounter{count}{39}\myPicture}
\only{\setcounter{count}{2}\myPicture}
\only{\setcounter{count}{5}\myPicture}
\end{frame}
\end{document}
![beamer](https://i.stack.imgur.com/h1oev.png)
Best Answer
An example using the
tangent
coordinate system and themath
,calc
anddecoration
libraries. Thetangent
coordinate system requires nodes, so I guess in a "proper" application with more fancy wheels they would need to be created invisibly.And just a follow-up to John Kormylo's excellent answer, here is a gears
pic
. Note, that thepic
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).