哟
\begin{tikzpicture}
\draw (0,0) -- (0,3cm);
\draw (0.5cm,0) -- (0.5cm,3cm);
\draw (3cm,0) -- (3cm,3cm);
\draw (3.5cm,0) -- (3.5cm,3cm);
\draw (0,0) arc (0:180:-1.75cm);
\draw (0.5cm,0) arc (0:180:-1.25cm);
\draw [fill=blue,blue] (0,0) rectangle (0.5cm,1cm);
\draw [fill=blue,blue] (3cm,0) rectangle (3.5cm,2.5cm);
\draw[dashed] (0.5cm,1cm) -- (4.5cm,1cm);
\draw[dashed] (3.5cm,2.5cm) -- (4.5cm,2.5cm);
\draw[<->] (4.5cm,1cm) -- (4.5cm,2.5cm) node[midway,right] {$\Delta h$};
\def\Radius{1.75cm}
\def\radius{1.25cm}
\begin{scope}[even odd rule]
\clip circle[radius=\Radius];
\clip[rotate=0] (0,0) -- (0:\Radius) arc (0:-180:\Radius)--cycle;
\fill[blue]
circle[radius=\Radius]
circle[radius=\radius]
;
\end{scope}
\end{tikzpicture}
出于某种原因,尽管我已将所有线设置为从 (0,0) 开始,但范围并不位于其他线的上方。关于如何实现这一点,有什么建议吗?
答案1
这不是答案,只是评论。你可以更轻松地做到这一点。(编辑:修复了左侧的水位,抱歉,没有注意。)
\documentclass[border=3.14mm,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\draw [double distance=0.5cm] (0.25,3) -- (0.25,0) arc(0:180:-1.5cm)
-- (3.25,3);
\draw [blue,line width=0.5cm] (0.25,1) -- (0.25,0) arc(0:180:-1.5cm)
-- (3.25,2.5);
\draw[dashed] (0.5cm,1cm) -- (4.5cm,1cm);
\draw[dashed] (3.5cm,2.5cm) -- (4.5cm,2.5cm);
\draw[<->] (4.5cm,1cm) -- (4.5cm,2.5cm) node[midway,right] {$\Delta h$};
\end{tikzpicture}
\end{document}
答案2
这是因为您使用 绘制第一个形状arc
,而通过绘制一个圆圈绘制第二个形状。圆圈围绕其中心绘制,您已将其隐式定义为(0,0)
,因此发生了偏移。您可以将范围移动 1.75 厘米以使其适合其他形状。
\documentclass[border=5pt,tikz]{standalone}
\begin{document}
\begin{tikzpicture}
\fill[blue] (0,0) rectangle (0.5cm,1cm);
\fill[blue] (3cm,0) rectangle (3.5cm,2.5cm);
\def\Radius{1.75cm}
\def\radius{1.25cm}
\begin{scope}[xshift=1.75cm,even odd rule]
\clip (0,0) -- (0:\Radius) arc (0:-180:\Radius) -- cycle;
\fill[blue] circle[radius=\Radius] circle[radius=\radius];
\end{scope}
\draw (0,0) -- (0,3cm);
\draw (0.5cm,0) -- (0.5cm,3cm);
\draw (3cm,0) -- (3cm,3cm);
\draw (3.5cm,0) -- (3.5cm,3cm);
\draw (0,0) arc (0:180:-1.75cm);
\draw (0.5cm,0) arc (0:180:-1.25cm);
\draw[dashed] (0.5cm,1cm) -- (4.5cm,1cm);
\draw[dashed] (3.5cm,2.5cm) -- (4.5cm,2.5cm);
\draw[<->] (4.5cm,1cm) -- (4.5cm,2.5cm) node[midway,right] {$\Delta h$};
\end{tikzpicture}
\end{document}
编辑:我重新排列了形状,使蓝色形状位于线条后面。这样,线条就会清晰可见。
输出如下:
答案3
稍微修改一下有趣的代码土拨鼠的“评论”(+1)。它利用了double
路径选项的更多可能性。用于练习:-)
\documentclass[tikz, margin=3mm]{standalone}
\begin{document}
\begin{tikzpicture}[DS/.style={double distance=5mm, semithick, double=#1}]
\draw [DS=white] (0,3) -- (0,0)
(3,2.5) -- (3,3);
\draw [DS=blue!50] (0,0) arc(0:180:-1.5cm) -- (3,2.5);
%
\draw[densely dashed] (0.25,0.0) -- (4.45,0.0)
(3.25,2.5) -- (4.45,2.5);
\draw[<->] (4.35,0) -- node[right] {$\Delta h$} (4.35,2.5) ;
\end{tikzpicture}
\end{document}