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

turtlelibrary (or a fork of it) where you specify the radii and the macros/libraries/keys calculate the needed distance ((r_1 + r_2)/2). Inner gears need more calculations and stuff or can be added later. What you draw at these points is another exercise (can be simple circles or any funny gear stuff). With a\matrixyou hardly can access positions arranged in such an un-matrix-like pattern. Could you add the input one wants to specify? – Qrrbrbirlbel Apr 09 '13 at 03:57