我正在尝试在 中创建一个机架和 pignon 布置tikz
。我找到了一个允许绘制 pignon 的代码。我试图添加一个机架以便进行布置。我写了这个代码
\documentclass[11pt]{scrartcl}
\usepackage{tikz}
% #1 number of teeths
% #2 radius intern
% #3 radius extern
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first
\newcommand{\gear}[5]{%
\foreach \i in {1,...,#1} {%
[rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=1.5pt]
-- (#4+#5:#3) arc (#4+#5:360/#1-#5:#3)} -- (360/#1:#2)
}}
\begin{document}
\begin{tikzpicture}
\def\a {5}
\def\b {4}
\def\c {0.8}
\draw[line width=0.5mm] \gear{10}{2}{2.9}{10}{8.5};
\draw [line width=0.5mm, rounded corners=13.5pt] (\c*0-\a,1-\b) -- (\c*1-\a,1-\b) -- (\c*1-\a,2-\b) -- (\c*2-\a,2-\b) -- (\c*2-\a,1-\b)
-- (\c*3-\a,1-\b) -- (\c*3-\a,2-\b) -- (\c*4-\a,2-\b) -- (\c*4-\a,1-\b) -- (\c*5-\a,1-\b)
-- (\c*5-\a,2-\b) -- (\c*6-\a,2-\b) -- (\c*6-\a,1-\b) -- (\c*7-\a,1-\b) -- (\c*7- \a,2-\b)
-- (\c*8-\a,2-\b) -- (\c*8-\a,1-\b) -- (\c*9-\a,1-\b) -- (\c*9-\a,2-\b) -- (\c*10-\a,2-\b)
-- (\c*10-\a,1-\b) --(\c*11-\a,1-\b) -- (\c*11-\a,2-\b) -- (\c*12-\a,2-\b) -- (\c*12-\a,1-\b)
-- (\c*13-\a,1-\b) -- (\c*13-\a,0-\b) -- (\c*0-\a,0-\b) --cycle;
;% -- (2,2) -- (2,1) -- cycle;
\end{tikzpicture}
\end{document}
我该如何改进此代码以获得更好的图形。我该如何添加一些注释?
答案1
一个肮脏的解决方案。一些值需要手动调整。
\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
% #1 number of teeths
% #2 radius intern
% #3 radius extern
% #4 angle from start to end of the first arc
% #5 angle to decale the second arc from the first
\newcommand{\gear}[5]{%
\foreach \i in {1,...,#1} {%
\draw[line width=0.5mm,xshift=-5mm] [rotate=(\i-1)*360/#1] (0:#2) arc (0:#4:#2) {[rounded corners=1.5pt]
-- (#4+#5:#3) arc (#4+#5:360/#1-#5:#3)} -- (360/#1:#2);
}}
\newcommand{\pinion}[3]{%
\foreach \j [count=\i from -#1] in {1,...,#1} {%
\draw [line width=0.5mm,yshift=-#3cm,rounded corners=1.5pt](\i+\j/2,0)coordinate(\j)--++(0:#2)--++(80:1)--++(0:#2)--++(-80:1)--++(0:#2)coordinate(A);
}
\draw [line width=0.5mm](A)--++(-90:2)coordinate(C)(1)--++(-90:2)coordinate(D);
\draw [line width=0.5mm](C)--(D);
}
\begin{document}
\begin{tikzpicture}
\gear{10}{2}{2.9}{10}{8.5};
% #1 Number of teeth
% #2 Width of teeth
% yshift of rack from
\pinion{7}{0.55}{3.1};
\end{tikzpicture}
\end{document}