答案1
如果不知道你的代码就很难说,但我假设你需要这样的东西:
\documentclass[border=2mm,tikz]{standalone}
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zz{sqrt(2/3)}
\tikzset{isometric/.style={x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0cm,\zz cm)}}}
\begin{document}
\begin{tikzpicture}[isometric,line join=round,line cap=round]
% cogs side walls (not all of them visible)
\foreach\i in{1,...,32}
\draw[fill=gray!50] (11.25*\i:2) -- (11.25*\i:1.5) --++ (0,0,0.25) --++ (11.25*\i:0.5) -- cycle;
% inner part
\draw[fill=gray!30] (135:1.5) foreach\i in {135,157.5,...,270}
{arc (\i:\i+11.25:1.5) --++ (0,0,0.25) arc (\i+11.25:\i+22.5:1.5) --++ (0,0,-0.25)}
arc (292.5:303.75:1.5) --++ (0,0,0.25) arc (303.75:315:1.5) --++ (0,0, 0.75)
arc (315:135:1.5) -- cycle;
% outer part
\draw[fill=gray!10] (-45:2) foreach\i in {-45,-22.5,...,101.25}
{arc (\i:\i+11.25:2) --++ (0,0,0.25) arc (\i+11.25:\i+22.5:2) --++ (0,0,-0.25)}
arc (112.5:123.75:2) --++ (0,0,0.25) arc (123.75:135:2) --++ (0,0, 0.75)
arc (135:-45:2) -- cycle;
% top part
\draw[even odd rule,fill=gray!20] (0,0,1) circle (2) (0,0,1) circle (1.5);
\end{tikzpicture}
\end{document}
我将中心角 (360) 分成 32 个部分,每个部分 11.25 度。然后我foreach
在内侧和外侧的齿轮之间移动。如您所见,这是具有等距透视的 3D 绘图,但可以使用椭圆以类似的方式在 2D 中完成。
编辑1:如果你只想绘制可见的齿轮,请将第一个替换\foreach
为
\foreach\i in{1,3,6,8,10,12,16,18,21,23,25,29,31} % only visible cogs
\draw[fill=gray!50] (11.25*\i:2) -- (11.25*\i:1.5) --++ (0,0,0.25) --++ (11.25*\i:0.5) -- cycle;
编辑2:另一个带有 24 个齿轮(已移除)的例子。
编辑3:更加可定制的版本:
\documentclass[border=2mm,tikz]{standalone}
% isometric axes
\pgfmathsetmacro\xx{1/sqrt(2)}
\pgfmathsetmacro\xy{1/sqrt(6)}
\pgfmathsetmacro\zz{sqrt(2/3)}
\tikzset{isometric/.style={x={(-\xx cm,-\xy cm)},y={(\xx cm,-\xy cm)},z={(0cm,\zz cm)}}}
% parameters
\def\nc{24} % number of cogs (multiple of 4, at least 8)
\def\H {1} % total height
\def\h {0.25} % cog height
\def\R {2} % outer radius
\def\r {1.5} % inner radius
\pgfmathtruncatemacro\nw{\nc/4} % number of cog walls per quadrant
\pgfmathsetmacro\a {180/\nc} % step angle
\pgfmathsetmacro\is{135+2*\a} % inner part step
\pgfmathsetmacro\il{315-4*\a} % inner part last iteration
\pgfmathsetmacro\os{-45+2*\a} % outer part step
\pgfmathsetmacro\ol{135-4*\a} % outer part last iteration
\tikzset
{
inner/.style={fill=blue!35},
outer/.style={fill=blue!15},
cogs/.style= {fill=blue!60},
top/.style= {fill=blue!20},
}
\begin{document}
\begin{tikzpicture}[isometric,line join=round,line cap=round]
% inner cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{4*\nw-\i}
\pgfmathsetmacro\k{6*\nw+\i}
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
\draw[cogs] (\a*\k:\R) -- (\a*\k:\r) --++ (0,0,\h) --++ (\a*\k:\R-\r) -- cycle;
}
% inner part
\draw[inner] (135:\r) foreach\i in {135,\is,...,\il}
{arc (\i:\i+\a:\r) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\r) --++ (0,0,-\h)}
arc (315-2*\a:315-\a:\r) --++ (0,0,\h) arc (315-\a:315:\r) --++ (0,0, \H-\h)
arc (315:135:\r) -- cycle;
% outer cogs side walls
\foreach\i in{-\nw,...,\nw}
{
\pgfmathsetmacro\j{-\i+2*\nw}
\draw[cogs] (\a*\i:\R) -- (\a*\i:\r) --++ (0,0,\h) --++ (\a*\i:\R-\r) -- cycle;
\draw[cogs] (\a*\j:\R) -- (\a*\j:\r) --++ (0,0,\h) --++ (\a*\j:\R-\r) -- cycle;
}
% outer part
\draw[outer] (-45:\R) foreach\i in {-45,\os,...,\ol}
{arc (\i:\i+\a:\R) --++ (0,0,\h) arc (\i+\a:\i+2*\a:\R) --++ (0,0,-\h)}
arc (135-2*\a:135-\a:\R) --++ (0,0,\h) arc (135-\a:135:\R) --++ (0,0,\H-\h)
arc (135:-45:\R) -- cycle;
% top part
\draw[even odd rule,top] (0,0,\H) circle (\R) (0,0,\H) circle (\r);
\end{tikzpicture}
\end{document}
答案2
这是一次尝试渐近线。
import solids;
currentprojection=orthographic(1,1,0.7);
currentlight.background = gray(.5)+green;
viewportmargin=(0.5cm,0.5cm);
picture pic2;
size(pic2,300);
path[] g = {box((4.5,0),(6,2.3)),box((4.5,.7),(6,2.3))};
pen[] colors={red,green,cyan, gray};
colors.cyclic=true;
// 36 cogs
for (int j=0; j<=35; ++j)
{
for(int i=0;i<length((j%2 == 0) ? g[0] : g[1]);++i)
{
path3 p=path3(subpath((j%2 == 0) ? g[0] : g[1],i,i+1),YZplane);
path3 p_=path3(box((4.5,0),(6,.7)),YZplane);
revolution R=revolution(p,Z,j*10,(j+1)*10);
draw(pic2,surface(R),colors[i]);
draw(pic2,rotate(j*10,Z)*surface(p_),pink);
}
}
add(pic2.fit());