我正在尝试使用 tikz 绘制两个同心圆柱体,以显示体积随半径的变化,而高度保持不变。下面左侧的插图是第一幅图,其中高度随半径固定而变化。此代码的大部分内容借鉴自 这里。右边的插图是我有疑问的地方。
1) 有没有办法遮蔽两个顶部底座之间的区域?我知道如何在区域之间使用 tikz 规则对常规 2-d 插图执行此操作,但我无法完全参考这两个独立的底座。
2) 显然,这个图并不理想,那么有没有更有效的方法来生成圆柱体看起来真正同心的图?也许可以手动在外圆柱内绘制一个类似的椭圆,然后尝试放置?
MWE 是:
\documentclass[border=5pt]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows,snakes,backgrounds,patterns,shapes.geometric,calc}
\begin{document}
\begin{tikzpicture}[scale=1]
\node [draw, cylinder, cylinder uses custom fill, cylinder body fill=lightgray!20,
cylinder end fill=lightgray!20, shape aspect=4, rotate=90, minimum width=3cm] (c1) at
(0,1.8){};
\coordinate(dhtop) at ($(c1.after top)!-1*.1!(c1.before top)$);
\coordinate(dhbot) at ($(c1.before bottom)!-1*.1!(c1.after bottom)$);
\coordinate(dhlabel) at ($(dhtop)!.5!(dhbot)$);
\draw[|-|] (dhbot)--(dhtop);
\path (dhlabel) node[right, outer sep = 2pt] {$dh$};
\node [draw, cylinder, shape aspect=4, rotate=90, minimum height=4cm, minimum
width=3cm] (c) {};
\coordinate(htop) at ($(c.before top)!-1*.1!(c.after top)$);
\coordinate(hbot) at ($(c.after bottom)!-1*.1!(c.before bottom)$);
\coordinate(hlabel) at ($(htop)!.5!(hbot)+(c.north)!.9!(c.center)$);
\draw[|-|] (hbot)--(htop);
\path (hlabel) node[left] {$h$}; %Modify height label here
\coordinate (center) at ($(c.before top)!0.5!(c.after top)$);
\filldraw (center) circle (1pt);
\coordinate (rlabel) at ($(center) !0.5!(c.after top)$);
\coordinate (rtop) at ($(center)!-1*.1!(c.after top)$);
\coordinate (rend) at ($(c.mid east)!0.5!(c.after top)$);
\draw[-, shorten >=-10] (center) -- (rend);
\path (rend) node[outer sep = 5pt, left] {$r$};
\end{tikzpicture}
\bigskip
\begin{tikzpicture}[scale=1]
\node [draw, cylinder, shape aspect=6, rotate=90, cylinder uses custom fill, cylinder
body fill=lightgray!20, minimum height=4cm, minimum width=4cm] (c1) at (0,0){};
\coordinate(htop) at ($(c1.after top)!-1*.1!(c1.before top)$);
\coordinate(hbot) at ($(c1.before bottom)!-1*.1!(c1.after bottom)$);
\coordinate(hlabel) at ($(htop)!.5!(hbot)$);
\draw[|-|] (hbot)--(htop);
\path (hlabel) node[right, outer sep = 2pt] {$h$};
\node [draw, cylinder, shape aspect=5, rotate=90, minimum height=3.9cm, minimum
width=3cm] (c) {};
\coordinate (center) at ($(c.before top)!0.5!(c.after top)$);
\filldraw (center) circle (1pt);
\coordinate (rlabel) at ($(center) !0.5!(c.after top)$);
\coordinate (rtop) at ($(center)!-1*.1!(c.after top)$);
\coordinate (rend) at ($(c.mid east)!0.5!(c.after top)$);
\draw[-, shorten >=-10] (center) -- (rend);
\path (rend) node[outer sep = 5pt, left] {$r$};
\end{tikzpicture}
\end{document}
答案1
在元帖子,您可以通过用阴影填充外圆,然后用背景填充内圆来为圆环添加阴影。这是您的图形尝试,可能会为您提供一个起点。
prologues := 3;
outputtemplate := "%j%c.eps";
beginfig(1);
path c, d, r, h;
p = 89; q = 34;
c = fullcircle xscaled p yscaled q;
d = c scaled 1.4;
fill d withcolor .9 white;
fill c withcolor white;
forsuffixes $=c,d:
draw $;
draw point 4 of $ -- subpath (4,8) of $ shifted (0,-p) -- point 0 of $;
draw subpath (0,4) of $ shifted (0,-p) dashed withdots scaled .4;
endfor
r = origin -- point 1 of c;
draw r; label.ulft(btex $r$ etex, point 0.5 of r);
fill c scaled 1/25;
h = (point 0 of d -- point 0 of d shifted (0,-p)) shifted 20 right;
ahangle := 180; ahlength := 3;
drawdblarrow h; label.rt(btex $h$ etex, point 0.5 of h);
endfig;
end.