两行之间填充

两行之间填充

我正在尝试使用 Tikz 创建一个图形。图形的一部分看起来像这样。

\documentclass[11pt, a4paper]{article}
\usepackage{textgreek}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
%Outer lining of the tube.
\draw {[rounded corners=0.2cm] (6.3,1.0) -- (6.3,-1.0) -- (8.3,-1.0) -- (8.3,-4.0)};
\draw {[rounded corners=0.2cm] (6.0,1.0) -- (6.0,-1.3) -- (8.0,-1.3) -- (8.0,-4.0)};
\draw {[rounded corners=0.2cm] (9.3,-4.0) -- (9.3,-1.0) -- (11.6,-1.0) -- (11.6,0.0)};
\draw {[rounded corners=0.2cm] (9.6,-4.0) -- (9.6,-1.3) -- (11.9,-1.3) -- (11.9,0.0)};

%Round bend which also needs to be filled with a color.
\def\arca {(8.3,-4.0) arc (180:0:0.5 and -0.5)}
\def\arcb {(8.0,-4.0) arc (180:0:0.8 and -0.8)}
\path [draw=black] \arca;
\path [draw=black] \arcb;

%Lines that are indicating a level. Space under these lines needs to be colored.
\draw (8.0,-2.5) -- (8.3,-2.5);
\draw [dashed] (8.3,-2.5) -- (10.3,-2.5);
\draw (9.3,-3.5) -- (9.6,-3.5);
\draw [dashed] (9.6,-3.5) -- (10.3,-3.5);
\draw [thick, <->] (10.2,-2.5) -- (10.2,-3.5);
\draw (10.6,-3.0) node {\begin{small}$\Delta P$\end{small}};
\end{tikzpicture}
\end{figure}
\end{document}

这将创建下图: 管子无着色

现在我想填充表示水平的线(用 $\Delta P$ 标记的线)下方的空间。所以最后它应该看起来像这样(只是填充得很好,不像这张图片中那样草率)。 管子在水平线下有颜色

我读了很多其他(类似)问题的例子,但我仍然不知道该怎么做。有人能给出一个简单的解决方案吗(你可能也看到了,我对 Latex 或 Tikz 不是很熟悉)。

提前致谢!

答案1

正如评论中提到的,您可以从已定义的用于填充的弧线创建路径。我只是稍微重新定义了你的arca

\documentclass[11pt, a4paper]{article}
\usepackage{textgreek}
\usepackage{amsmath}
\usepackage{graphicx}
\usepackage{tikz}

\begin{document}
\begin{figure}
\centering
\begin{tikzpicture}
%Outer lining of the tube.
\draw {[rounded corners=0.2cm] (6.3,1.0) -- (6.3,-1.0) -- (8.3,-1.0) -- (8.3,-4.0)};
\draw {[rounded corners=0.2cm] (6.0,1.0) -- (6.0,-1.3) -- (8.0,-1.3) -- (8.0,-4.0)};
\draw {[rounded corners=0.2cm] (9.3,-4.0) -- (9.3,-1.0) -- (11.6,-1.0) -- (11.6,0.0)};
\draw {[rounded corners=0.2cm] (9.6,-4.0) -- (9.6,-1.3) -- (11.9,-1.3) -- (11.9,0.0)};

%Round bend which also needs to be filled with a color.
\def\arca {(9.3,-4.0) arc (180:0:-0.5 and -0.5)}
\def\arcb {(8.0,-4.0) arc (180:0:0.8 and -0.8)}
% constructing, drawing and filling path
\path[draw,fill=red] (8,-2.5) -- (8,-4) -- \arcb -- (9.6,-4) -- (9.6,-3.5) -- (9.3,-3.5) -- (9.3,-4)  -- \arca  -- (8.3,-4) -- (8.3,-2.5) -- cycle;

%Lines that are indicating a level. Space under these lines needs to be colored.
\draw [dashed] (8.3,-2.5) -- (10.3,-2.5);
\draw [dashed] (9.6,-3.5) -- (10.3,-3.5);
\draw [thick, <->] (10.2,-2.5) -- (10.2,-3.5);
\draw (10.6,-3.0) node {\begin{small}$\Delta P$\end{small}};
\end{tikzpicture}
\end{figure}
\end{document}

在此处输入图片描述

答案2

另一种方法是使用double线条。double distance定义管道宽度和double=...填充颜色,默认情况下为白色。这意味着在非白色背景上,管道不透明。

\documentclass[tikz,border=2mm]{standalone}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}[pipe/.style={draw, double, double distance=3mm, rounded corners=2mm},
    pipefull/.style={pipe, double=red}]

%Outer lining of the tube.
\draw[pipe] (6,1) |- ++(2,-2) -- ++(0,-3) coordinate (aux1) arc(-180:-0:0.6) coordinate (aux2) |-++(2,3)--++(0,2);

\draw[pipefull] ([yshift=2cm]aux1) coordinate(top) -- (aux1) arc(-180:-0:0.6) -- ([yshift=1cm]aux2) coordinate(bottom) ;

\draw[dashed] (top)--++(0:20mm) coordinate (aux3);
\draw[dashed] (bottom) -- (aux3|-bottom) coordinate (aux4);
\draw[<->,thick] ([xshift=-2mm]aux3)-- node[right, font=\small]{$\Delta P$} ([xshift=-2mm]aux4);

\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容