在三维中绘制 U 形管道

在三维中绘制 U 形管道

如何在 tikz 中绘制这样的 U 形管道?

在此处输入图片描述

这是我到目前为止尝试过的非常基本的:

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  %Inner Radius
  \pgfmathsetmacro{\rI}{0.7}

  %Height
  \pgfmathsetmacro{\h}{7}

  %Diameter of the pipe
  \pgfmathsetmacro{\d}{1}

  %Outer Radius
  \pgfmathsetmacro{\rO}{\rI + \d}

  \pgfmathsetmacro{\s}{2}

  %%Inner Part
  \draw (0,0) -- (0,-\h) coordinate (I1); 
  \draw[shift=(I1),xshift=\rI cm] plot[domain=270:90] ({\rI*sin(\x)},{\rI*cos(\x)}) coordinate (I2);
  \draw (I2) -- ++(0,\h);

  %% Outer Part
  \draw (-\d,0) -- ++(0,-\h) coordinate (O1);
  \draw[shift=(O1),xshift=\rO cm] plot[domain=270:90] ({\rO*sin(\x)},{\rO*cos(\x)}) coordinate (O2);
  \draw (O2) -- ++(0,\h);

  %% l Line
  \draw (-\d/2.0,-0.5*\h+\s) -- ++(0,-0.5*\h-\s) coordinate (L1);
  \pgfmathsetmacro{\rl}{\rO - 0.5*\d}
  \draw[shift=(L1),xshift=\rl cm] plot[domain=270:90] ({\rl*sin(\x)},{\rl*cos(\x)}) node[below=1.2cm,pos=0.5]{$l$} coordinate (L2);
  \draw (L2) -- ++(0,0.5*\h-\s);

  \draw[->] (-3,-\h-\rO) -- (-3,0) node[left]{\small Ort $y$};
  \draw (-3.1,-0.5*\h) node[left]{$0$} -- ++(0.2,0);
\end{tikzpicture}

\end{document}

输出:

在此处输入图片描述

我不知道该如何给它上色,也不知道如何让它看起来有 3D 效果(我猜 3D 效果可能比我最初发布的图片更好,因为那里的管道底部看起来是 2D 效果)。而且我的方法似乎不太优雅。

答案1

您已经完成了所有艰苦的工作。要添加蓝色填充颜色,您只需再次绘制已有的线条,宽度要更大。要添加椭圆,您可以这样做\draw (-\d/2.0,-0.5*\h+\s) ellipse (0.5 and 0.1);

\documentclass{standalone}
\usepackage{tikz}

\begin{document}

\begin{tikzpicture}
  %Inner Radius
  \pgfmathsetmacro{\rI}{0.7}

  %Height
  \pgfmathsetmacro{\h}{7}

  %Diameter of the pipe
  \pgfmathsetmacro{\d}{1}

  %Outer Radius
  \pgfmathsetmacro{\rO}{\rI + \d}

  \pgfmathsetmacro{\s}{2}

  %%Inner Part
  \draw (0,0) -- (0,-\h) coordinate (I1); 
  \draw[shift=(I1),xshift=\rI cm] plot[domain=270:90] ({\rI*sin(\x)},{\rI*cos(\x)}) coordinate (I2);
  \draw (I2) -- ++(0,\h);

  %% Outer Part
  \draw (-\d,0) -- ++(0,-\h) coordinate (O1);
  \draw[shift=(O1),xshift=\rO cm] plot[domain=270:90] ({\rO*sin(\x)},{\rO*cos(\x)}) coordinate (O2);
  \draw (O2) -- ++(0,\h);

  % NEW
  \draw[blue!20!white, line width=28pt] (-\d/2.0,-0.5*\h+\s) -- ++(0,-0.5*\h-\s) coordinate (L1);
  \draw[fill=blue!40!white] (-\d/2.0,-0.5*\h+\s) ellipse (0.5 and 0.1);


  %% l Line
  \draw (-\d/2.0,-0.5*\h+\s) -- ++(0,-0.5*\h-\s) coordinate (L1);
  \pgfmathsetmacro{\rl}{\rO - 0.5*\d}
  \draw[shift=(L1),xshift=\rl cm] plot[domain=270:90] ({\rl*sin(\x)},{\rl*cos(\x)}) node[below=1.2cm,pos=0.5]{$l$} coordinate (L2);
  \draw (L2) -- ++(0,0.5*\h-\s);



  \draw[->] (-3,-\h-\rO) -- (-3,0) node[left]{\small Ort $y$};
  \draw (-3.1,-0.5*\h) node[left]{$0$} -- ++(0.2,0);
\end{tikzpicture}

\end{document}

在此处输入图片描述

相关内容