\DocumentMetadata{}
%% $Id: pst-gears-doc.tex 1185 2025-12-15 15:43:57Z herbert $
\documentclass[fontsize=11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false,
   headings=small, headinclude=false,footinclude=false,twoside]{pst-doc}
\usepackage{pst-gears}
\let\pstGearsFV\fileversion
\usepackage{pst-plot}
\usepackage{pst-slpe,animate}
\definecolor{woodcolor}{rgb}{0.95 0.84 0.5}
\definecolor{darkcolorwood}{rgb}{0.75 0.4 0}
%\definecolor{chassis}{rgb}{0.95 0.9 0.8}
\definecolor{chassis}{RGB}{182 142 10}

\def\image#1#2{%
\begin{pspicture}[showgrid=false](-6.28,-15)(6.28,5)
% the crank
  \rput{#1}{\pscustom[fillstyle=solid,fillcolor=gray!50]{%
    \psarc(0,0){0.5}{210}{150}
    \psline(-0.433,0.25)(-2.5,0.25)
    \psarc(-2.5,0){0.25}{90}{-90}
    \psline(-2.5,-0.25)(-0.433,-0.25)}%
  \pscircle[fillstyle=solid,fillcolor=gray!25](-2.5,0){0.15}}%
% the chassis
  \pscustom[fillstyle=solid,fillcolor=chassis]{%
    \psline(0,4.75)(-1,4.75)(-1,4)(-1,-2)
    \psarc(0.5,-4){2.5}{126.87}{233.13}
    \psline(!-1 -4 2.5 233.13 sin mul add)(-1,-13)
    \psarcn(-2,-13){1}{0}{-90}
    \psline(-2,-14)(-4.5,-14)
    \psarc(-4.5,-14.5){0.5}{90}{180}
    \psline(-5,-14.5)(-5,-15)(5,-15)(5,-14.5)
    \psarc(4.5,-14.5){0.5}{0}{90}
    \psline(4.5,-14)(2,-14)
    \psarcn(2,-13){1}{-90}{180}
    \psline(1,-13)(!1 -4 2.5 233.13 sin mul add)
    \psarc(-0.5,-4){2.5}{-53.13}{53.13}
    \psline(1,-2)(1,4)(1,4.75)(0,4.75)}
  \psline(-4.5,-14)(4.5,-14)
% arm connecting the crank axle. the small wheel
  \rput{#1}{\pscustom[fillstyle=solid,fillcolor=gray!50]{%
    \psarc(0,0){0.5}{30}{-30}
    \psline(0.433,-0.25)(1.8,-0.25)
    \psarc(1.8,0){0.25}{-90}{90}
    \psline(1.8,0.25)(0.433,0.25)}}%	
  \pscircle*{0.2}
  % to color the two gears differently
  %\pstgears[Z1=36,Z2=18,m=0.2,wheelrotation=0,linewidth=0.025,int,fillstyle=solid,circles=false,polarangle=#1,clockwork,color1=woodcolor,drawWheels=1 0]
  %\pstgears[Z1=36,Z2=18,m=0.2,wheelrotation=0,linewidth=0.025,int,fillstyle=solid,circles=false,polarangle=#1,clockwork,color1=darkcolorwood,drawWheels=0 1]
  \pstgears[Z1=72,Z2=36,m=0.1,wheelrotation=0,linewidth=0.025,int,
    fillstyle=solid,circles=false,polarangle=#1,clockwork,color1=woodcolor]
  \psdot[dotstyle=o,linecolor=red](!0 3.6 #1\space sin mul)%
  \pscircle[fillstyle=solid,fillcolor=darkcolorwood](!0 3.6 #1\space sin mul){0.2}
  \pscircle[fillcolor=blue!25,fillstyle=solid](!0 3.6 #1\space sin mul){0.1}
  \pscircle[fillstyle=solid,fillcolor={[rgb]{0.5 0 0}}](!0 3.6 #1\space sin mul 10 sub){0.1}
  \psframe[fillstyle=solid,fillcolor=darkcolorwood](-0.6,-4.2)(-0.5,-14)
  \psframe[fillstyle=solid,fillcolor=darkcolorwood](0.6,-4.2)(0.5,-14)
  \psframe[fillstyle=solid,fillcolor=woodcolor,opacity=0.5](-0.6,-4.2)(0.6,-14)
  \parametricplot[algebraic,plotpoints=360,linecolor=red,linewidth=2.5\pslinewidth]{-6.28}{6.28}{t|3.6*sin(t+#2)-10}
  % the piston
  \psframe[fillstyle=slope,slopeangle=0,slopebegin=\psbordercolor,slopeend=\psshadowcolor]%
          (!-0.1 3.6 #1\space sin mul)(!0.1 3.6 #1\space sin mul 10 sub)
  \psframe[fillstyle=solid,fillcolor=darkcolorwood](!-0.6 3.6 #1\space sin mul 10.2 sub)(!0.6 3.6 #1\space sin mul 10 sub)
%%%
  % cylinder-piston fixings
  \psframe[fillstyle=slope,slopeangle=0,slopebegin=\psbordercolor,slopeend=darkcolorwood](-1.2,-4.2)(1.2,-4.6)
  \psframe[fillstyle=slope,slopeangle=0,slopebegin=\psbordercolor,slopeend=darkcolorwood](-1.2,-14)(1.2,-13.6)
  \psline(-0.6,-4.6)(-0.6,-4.2)\psline(0.6,-4.6)(0.6,-4.2)
  \pscircle*(-0.9,-4.4){0.1}\pscircle*(0.9,-4.4){0.1}
  \psline(-0.6,-14)(-0.6,-13.6)\psline(0.6,-14)(0.6,-13.6)
  \pscircle*(-0.9,-13.8){0.1}\pscircle*(0.9,-13.8){0.1}
  % fixing the big wheel
  \psframe[fillstyle=slope,slopeangle=-90,slopebegin=darkcolorwood,
   slopeend=\psbordercolor](-0.6,4.3)(0.6,3.9)
%\psframe[fillstyle=solid,fillcolor={[rgb]{1 0.8 0.5}}](-0.6,4.3)(0.6,3.9)
\pscircle*(0,4.2){0.1}
\rput{70}(-1.2,-4){\psframe[fillstyle=slope,slopeangle=0,
   slopebegin=darkcolorwood,
   slopeend=\psbordercolor](-0.4,0.4)(0.3,0)
\pscircle*(-0.1,0.2){0.1}}
\rput{110}(1.2,-4){\psframe[fillstyle=slope,slopeangle=0,
   slopebegin=darkcolorwood,
   slopeend=\psbordercolor](0.3,-0.4)(-0.4,0)
\pscircle*(-0.1,-0.2){0.1}}
\end{pspicture}}

\renewcommand\bgImage{\psscalebox{0.75}{\begin{pspicture}(-4,-4)(6,6)
\rput{45}{\pstgears[Z1=24,Z2=12,m=0.25,linewidth=0.025,circles,fillstyle=solid,
		dash=10pt 2pt 1pt 2pt]}%
\end{pspicture}}}

\addbibresource{\jobname.bib}

\begin{document}

\title{\texttt{pst-gears}}
\subtitle{Gears; v.\pstGearsFV}
\author{Manuel Luque \\ Herbert Voß}
\docauthor{}
\date{\today}
\settitle


The macro \Lcs{pstgears}\Largs{Options}\Largb{x,y} allows you to draw a gear consisting of two external gears
whose profile is an involute arc. It adheres to the standard conventions for this type of gear. 
The optional parameters, whose default values 
are indicated, are as follows:

\begin{enumerate}
  \item \Lkeyword{Z1}\texttt{=20}: number of teeth on gear \#1;
  \item \Lkeyword{Z2}\texttt{=10}: number of teeth on gear \#2;
  \item \Lkeyword{m}\texttt{=0.5}: gear module;
  \item \Lkeyword{ap}\texttt{=20}: pressure angle in degrees.
  \item \Lkeyword{Rarct}\texttt{=0.1}: allows you to adjust the radius of the connection 
   		between the teeth and the root circle, as a fraction of the
		root circle radius.
  \item \Lkeyword{drawWheels}\texttt{=1 1}: Draws both wheels if the argument is \texttt{[1 1]} 
   (default), draws only wheel 1 if \texttt{[drawWheels=1 0]}, and draws only wheel 2 
   if \texttt{[drawWheels=0 1]}. This parameter replaces the boolean \texttt{[notdrawWheel1]} 
   from previous versions, which only allowed drawing wheel 1.
\end{enumerate}


The macro has 4 booleans:

\begin{enumerate}
  \item  \Lkeyset{int=false}: Selects the gear type, external (default) or internal. In the latter case, 
  		simply write \Lkeyword{int} in the options.
  \item \Lkeyset{circles=false}: Draws the basic and primitive circles.
  \item \Lkeyset{key=true}:  To draw or not draw the key for each wheel.
  \item \Lkeyset{clockwork=false}: Draws the gears in clockwork style.
\end{enumerate}

For gear rotation, useful for an animation (see the corresponding files):

\begin{itemize}
  \item \texttt{[wheelrotation=0]}:value in degrees (positive or negative) of wheel 1; the rotation angle of wheel 2 is deduced by the macro. 
\end{itemize}

For the drawing, the wheel colors can be chosen using the following parameters:

\begin{enumerate}
  \item \texttt{[color1=\{[rgb]\{0.625 0.75 1\}\}]};
  \item \texttt{[color2=\{[rgb]\{0.75 1 0.75\}\}]}.
\end{enumerate}

By default, the wheels are not filled. To color the inside of external gears or the ring gear,
for internal gears, you must activate the PSTricks option: \Lkeyset{fillstyle=solid}.

The color and thickness of the wheel outline are chosen using the usual PSTricks 
options: \Lkeyword{linecolor} and \Lkeyword{linewidth}. The PSTricks option 
\Lkeyset{linestyle=none} remains valid.

The drawing, in dotted lines, of the The basic and primitive circles can be refined using two options:
\begin{enumerate}
  \item The PSTricks parameter \Lkeyword{dash}\texttt{=\ldots},
  \item The color with the parameter: \Lkeyset{colorcircles=red}.
\end{enumerate}


The drawing is centered at the point \texttt{(x,y)} on the pinion axis 
(the first wheel). If this detail is omitted, the wheel is
centered at the origin. To position the second wheel at an angle, 
there are two ways:

\begin{enumerate}
  \item Use the PSTricks command 
     \Lcs{rput}\Largb{angle}\Largb{\Lcs{pstgears}\Largs{otions}};

   \item Or the optional parameter \Lkeyset{polarangle=value}, 
   	specifying the value in degrees of the chosen angle.
\end{enumerate}

This makes it very easy to draw a 3-wheel gear train, as in the example below, by
specifying not to redraw wheel 1 with the option \texttt{[drawWheels=1 0]}:

\begin{exampleM}{Color and polar angle}
\begin{pspicture}[showgrid](-5,-4)(8,7)
\pstgears[Z1=30,Z2=15,m=0.25,linewidth=0.025,fillstyle=solid,polarangle=120]%
\pstgears[Z1=30,Z2=18,m=0.25,linewidth=0.025,fillstyle=solid,polarangle=0,color2=red!50,drawWheels=0 1]%
\end{pspicture}
\end{exampleM}


\begin{exampleM}{Rotated}
\begin{pspicture}[showgrid](-4,-4)(6,6)
\rput{45}{\pstgears[Z1=24,Z2=12,m=0.25,linewidth=0.025,fillstyle=solid,
    circles,dash=10pt 2pt 1pt 2pt]}%
\end{pspicture}
\end{exampleM}

\begin{exampleM}{Wheel inside wheel}
\begin{pspicture}[showgrid](-5,-5)(5,5)
\rput{-45}{\pstgears[Z1=36,Z2=18,m=0.2,wheelrotation=25,linewidth=0.0001,int,
			fillstyle=solid,circles]}
\end{pspicture}
\end{exampleM}

See also \url{https://en.wikipedia.org/wiki/Tusi_couple}.


\begin{exampleM}{polarangle}
\begin{pspicture}[showgrid](-5,-5)(5,5)
\pstgears[Z1=36,Z2=18,m=0.2,wheelrotation=25,linewidth=0.025,int,fillstyle=solid,
			circles,polarangle=120]
\end{pspicture}
\end{exampleM}

\begin{exampleM}{Complex example}
\begin{pspicture}(-13,-3)(4,3)
\psset{m=0.08,linewidth=0.025,fillstyle=solid,ap=15,clockwork}
\pstgears[Z1=60,Z2=8,wheelrotation=0,color2={[rgb]{0.625 0.75 1}}]
\rput{180}{\pstgears[Z1=8,Z2=64,wheelrotation=0,color1={[rgb]{0.75 1 0.75}}]}
% entraxe1 = (8+64)*0.08/2 = 2.88
\rput{180}{\pstgears[Z1=20,Z2=60,wheelrotation=0,color2=gray,color1=gray](2.88,0)}
% entraxe2 = (20+60)*0.08/2 = 3.2 + entraxe1
\rput{180}{\pstgears[Z1=16,Z2=64,wheelrotation=0,color1=blue!50,color2=blue!50](6.08,0)}
\psgrid[subgriddiv=0,gridcolor=lightgray,griddots=10,gridlabels=8pt]%
\end{pspicture}
\end{exampleM}

\bigskip
Study of a clock gear train, inspired by the remarkable work of 
Tavmjong Bah on the website:
\url{http://tavmjong.free.fr/INKSCAPE/DRAWINGS/clock.svg} (see also \parencite{tavm}).

A version with gears more suited to clockmaking has been created; see the page:
\url{ http://pstricks.blogspot.fr/2013/05/horloge-pstricks-une-animation-au.html}.


\newpage
\begin{exampleM}{Principle of the spirograph}
\begin{pspicture}(-7,-7)(7,7)
\pstgears[Z1=120,Z2=24,m=0.1,wheelrotation=0,ap=20,linewidth=0.025,int,fillstyle=solid,polarangle=0]
\parametricplot[plotpoints=360,algebraic,linestyle=dotted,linecolor=red,
     linewidth=0.1]{0}{6.28}{1.2*(4*cos(t)+cos(4*t)) | 1.2*(4*sin(t)-sin(4*t))}
\end{pspicture}
\end{exampleM}

\newpage
\pagestyle{empty}

\begin{codeblockA}[title=4 Wheels inside a big one]% default lang is latex
\psset{unit=0.25cm,fillstyle=solid}
\begin{animateinline}[poster=last, controls, palindrome, width=0.7\linewidth,
  begin={\begin{pspicture}(-16,-16)(16,16)},
  end={\end{pspicture}}]{12}% 
\multiframe{180}{iA=0+1}{%
  \pstgears[Z1=12, Z2=24, color1=yellow, polarangle=\iA, color2=blue]%
  \pstgears[Z1=12, Z2=24, polarangle=\iA\space 120 add, color1=yellow,
            color2={[rgb]{0 0.75 0}}, drawWheels=0 1]%
  \pstgears[Z1=12, Z2=24, polarangle=\iA\space 240 add, color2=red, drawWheels=0 1]%
  \pstgears[Z1=60, Z2=24, int, color1=yellow, color2=blue,
              wheelrotation=15 -\iA\space 1.2 mul add, polarangle=\iA](0,0)}
\end{animateinline}
\end{codeblockA}


\begin{center}
\psset{unit=0.25cm,fillstyle=solid}
\begin{animateinline}[poster=last, controls, palindrome, width=0.7\linewidth,
  begin={\begin{pspicture}(-18,-18)(18,18)},
  end={\end{pspicture}}]{12}% 
\multiframe{180}{iA=0+1}{%
  \pstgears[Z1=12, Z2=24, color1=yellow,polarangle=\iA, color2=blue]%
  \pstgears[Z1=12, Z2=24, polarangle=\iA\space 120 add, color1=yellow,
            color2={[rgb]{0 0.75 0}}, drawWheels=0 1]%
  \pstgears[Z1=12, Z2=24, polarangle=\iA\space 240 add, color2=red, drawWheels=0 1]%
  \pstgears[Z1=60, Z2=24, int, color1=yellow, color2=blue,
              wheelrotation=15 -\iA\space 1.2 mul add, polarangle=\iA](0,0)}
\end{animateinline}
\end{center}



\begin{center}
\begin{animateinline}[poster=last, controls, palindrome]{12}%
\multiframe{180}{iR=0+2, r=0.0+0.0349066}{\image{\iR}{\r}}%
\end{animateinline}%
\end{center}

\newpage
\nocite{*}
\printbibliography

\printindex

\end{document}
