I need some help to modify the \gear macro of this answer in order to be able to fill the drawn gear with a solid color.
I've tried to move the \draw command outside the loop, but it does not work as expected (missing semicolon???):
\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}
\draw[fill=black!20] \foreach \zz in{1,2,...,\Zb}{
({(\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)})
} -- cycle;
}
Edit: add missing fill color
\drawis already outside of the loop? Does replacing\drawwith\fillor\filldrawnot work? – Qrrbrbirlbel Jan 28 '13 at 12:12\drawwith\fill(draw)or just addfill=<color>to its optional argument? Okay, scratch that, I’ve just tested it, of course it doesn’t work with sepearate\drawcommands. – Qrrbrbirlbel Jan 28 '13 at 12:20\foreachloop and use it later, i.e.\draw\savedPath;… – Qrrbrbirlbel Jan 28 '13 at 12:32\foreachloop encloses its content in a group, so you will need the global variants\gapptoand\xappto. – Qrrbrbirlbel Jan 28 '13 at 13:18