齿轮链带

齿轮链带

我想画成这样

在此处输入图片描述

我基于以下创建的齿轮rpapa 的代码

\documentclass{article}
\usepackage[dvipsnames,svgnames]{xcolor}
\usepackage{tikz}
\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}

  \foreach \zz in{1,2,...,\Zb}{
    \draw[DarkSlateGray!70!Sepia]
    ({(\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)});
  }
}

\begin{document}

\centering
\begin{tikzpicture}[scale=0.05]
\gear{3}{32}{20}
\path[fill=DarkSlateGray!70!Sepia] circle(40);
\draw[thick,double distance=2pt,fill=white] circle(20) ;
\begin{scope}[xshift=100cm,rotate=180/16]
\gear{3}{16}{20}
\path[fill=DarkSlateGray!70!Sepia] circle(17.5);
\draw[thick,double distance=2pt,fill=white] circle(8);
\end{scope}
\end{tikzpicture} 

\end{document}

我该如何画腰带?

答案1

tangent使用坐标系统和mathcalc和库的示例decorationtangent坐标系统需要节点,因此我猜想在具有更多花哨轮子的“正确”应用程序中,它们需要以不可见的方式创建。

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{calc,math,decorations}
\pgfkeys{/pgf/decoration/links/.initial=50}
\pgfdeclaredecoration{chain links}{start}{
\state{start}[width=0pt, next state=draw,
  persistent precomputation={
    \pgfmathsetlengthmacro{\linklength}%
      {\pgfdecoratedpathlength/(\pgfkeysvalueof{/pgf/decoration/links})}%
  }]{}
\state{draw}[width=\linklength]{
  \draw [fill=gray!50] (-\linklength/4,-\linklength/4) 
  arc (270:90:\linklength/4)
  .. controls ++(\linklength/8,0) and ++(-\linklength/8,0)
  .. (0,\linklength/6)
  .. controls ++(\linklength/8,0) and ++(-\linklength/8,0)
  .. (\linklength/4, \linklength/4)
  arc (90:-90:\linklength/4)
  .. controls ++(-\linklength/8,0) and ++(\linklength/8,0)
  .. (0,-\linklength/6)
  .. controls ++(-\linklength/8,0) and ++(\linklength/8,0)
  .. (-\linklength/4, -\linklength/4);
  \draw 
    (-\linklength/4,0) circle [radius=\linklength/8]
    (\linklength/4,0) circle [radius=\linklength/8];
}
}
\begin{document}
\begin{tikzpicture}[wheel/.style={fill=gray!70, circle, minimum size=#1*2cm}]
\tikzmath{%
  coordinate \p;
  \p1 = (0,0); \p2 = (4,0);
  \r1 = 2; \r2 = 1;
  {
    \node [wheel=\r1] (big) at (\p1) {};
    \node [wheel=\r2] (little) at (\p2) {};
  }; 
  \p3 = (tangent cs:node=big, point={(little.north)});
  \a = atan2(\py3-\py1, \px3-\px1);  
}
\draw [decoration={chain links, links=40}, decorate] 
  ($(\p1)+(\a:\r1)$)  arc (\a:360-\a:\r1) --
  ($(\p2)+(-\a:\r2)$) arc (-\a:\a:\r2)    -- cycle;
\end{tikzpicture}
\end{document}

在此处输入图片描述

作为对 John Kormylo 出色回答的后续,这里有一个 gears pic。请注意,规范pic使用无单位数字表示齿轮尺寸(直径)和 xy 坐标,以延迟转换为点。这有助于避免当坐标有单位但尺寸没有单位(反之亦然)时出现数学溢出或意外输出。

\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{math,calc}
\tikzset{%
  set gear dots/.style={
    gear dots/.style={dash pattern=on 4pt off 4pt, dash phase=#1}},
  set gear dots=0pt,
  pics/gears/.style args={size #1 at (#2,#3) and size #4 at (#5,#6)}{code={
\tikzmath{%
  \r1 = #1/2; \r2 = #4/2;
  \gm = atan2(#3-#6, #2-#5);
  \th = acos((\r1 == \r2) ? 0 : (\r2-\r1) / veclen(#5-#2, #6-#3));
  coordinate \c, \t;
  \c1 = (#2, #3); \t1 = (\c1) + (360-\th+\gm:\r1);
  \c2 = (#5, #6); \t2 = (\c2) + (\th+\gm:\r2);
}
\draw [black!80, thick, fill=gray!25] (\c1) circle [radius=\r1];
\draw [black!80, thick, fill=gray!25] (\c2) circle [radius=\r2];
\draw [gray, ultra thick, postaction={draw=gray!50, gear dots, ultra thick}] 
  (\t2) arc (\th+\gm:360-\th+\gm:\r2) -- 
  (\t1) arc (360-\th+\gm:360+\th+\gm:\r1) -- cycle;
  }}}
\begin{document}
\foreach \i in {0,...,7}{
\tikz[set gear dots=\i]{
  \pic {gears={size 1 at (1,-1) and size 2 at (3,2)}};
  \pic {gears={size 1 at (-1,0) and size 1 at (-1,3)}};
  \pic {gears={size 0.5 at (-1,3) and size 1 at (3,2)}};
  \pic {gears={size 0.5 at (-1,0) and size 0.25 at (1,-1)}};
}}
\end{document}

在此处输入图片描述

答案2

几何课

上述 tikzpicture 的源代码是:

\begin{tikzpicture}[every node/.style={inner sep=1pt}]
\footnotesize
\draw (0,0) circle[radius=1];
\draw (3,0) circle[radius=.5];
\draw[red] (0,0) -- (3,0) node[midway,above] {$b$}
   -- (6,0)node[midway,above] {$a$} node[right]{P};
\draw[red] (3.2,0) arc[radius=0.2,start angle=0,end angle=80.4]
  node[midway,above right=-1pt] {$\theta$};
\coordinate (A1) at ({cos(80.4)},{sin(80.4)});
\coordinate (A2) at ({cos(80.4)},{-sin(80.4)});
\coordinate (B1) at ({3+0.5*cos(80.4)}, {0.5*sin(80.4)});
\coordinate (B2) at ({3+0.5*cos(80.4)},{-0.5*sin(80.4)});
\draw[red] (A1) -- (0,0) node[midway,left] {$r_2$} -- (A2);
\draw[red] (B1) -- (3,0) node[midway,left] {$r_1$} -- (B2) -- (6,0) -- cycle;
\draw[blue,thick] (B2) arc[radius=0.5,start angle=-80.4,end angle=80.4] -- (A1)
  arc[radius=1,start angle=80.4,end angle=279.6] -- cycle;
\end{tikzpicture}

答案3

这是一个元帖子函数生成必要的“传动带”路径。给定两个任意圆,它会返回由两个相互切线和相关圆弧组成的路径。

prologues := 3;
outputtemplate := "%j%c.eps";

% given two circular paths return the "drive belt" around them
vardef drive_belt(expr a,b) = 
  save R,r,d,t,p; numeric R,r,d,t,p;
  R = length (point 0 of a - center a);
  r = length (point 0 of b - center b);
  d = length (center b - center a);
  t = angle  (center b - center a);
  if R=r:
    p = 2;
  else:
    p = (angle (r, d*(r/(R-r)) +-+ r ))/45;
    if r>R: p:=4-p; fi
  fi
  subpath(p,8-p) of a rotatedabout(center a, t) --
  subpath(0-p,p) of b rotatedabout(center b, t) -- cycle
enddef;

beginfig(1);
  path A, B; 

  A = fullcircle scaled 55;
  B = fullcircle scaled 21 shifted (89,34);
  fill A withcolor .8[blue, white];
  fill B withcolor .8[red, white];
  label("A", center A);
  label("B", center B);

  draw drive_belt(A,B);

endfig;

end.

在此处输入图片描述

如果一个圆圈包含在另一个圆圈内,您将收到来自 MP 的错误。

相关内容