使用蓝色填充颜色创建半圆柱形水箱

使用蓝色填充颜色创建半圆柱形水箱

我想要创建这个:

1

这是我的 MWE 以及我一直在手动尝试的操作:

\documentclass[tikz]{standalone}

\begin{document}
    \begin{tikzpicture}
        
        \draw (3,0) arc (360:180:1.5 and 1.5);% bottom half circle
        
        \draw (0,0) -- (3,3);% upper left line
        \draw (3,0) -- (6,3);% upper right line
        \draw (0,0) -- (3,0);% upper front line
        \draw (3,3) -- (6,3);% upper back line
        
        \draw (-1.25,1.5) node {$\phi$};
        
        \draw [fill=blue, fill opacity=.15] (0.2,-0.3) -- (3.2,2.7) -- (6.1,2.7) -- (3.1,-0.3) -- cycle;
        \draw [fill=blue, fill opacity=.35] (0.2,-0.6) -- (2.8,-0.6) -- (2.73,-0.8) -- (0.26,-0.8) -- cycle;
        \draw [fill=blue, fill opacity=.35] (2.8,-0.6) -- (2.73,-0.8) -- (6.2,2.6) -- (6.1,2.7) -- cycle;
        
        \draw [fill=blue, fill opacity=.15] (2.88,-0.3) arc (360:180:1.36 and 1.2);
        
    \end{tikzpicture}
\end{document}

2

答案1

在此处输入图片描述

该绘图使用了包tikz-3dplot;它提供了非常有用的选项canvas is xy plane at z=...

评论

  • 我重新定义了坐标系(个人喜好问题)。可以通过修改经度和/或纬度来改变视角(见下图)如果观察者停留在第一象限,即她的纬度和经度包含在区间内,则绘图是一致的(0,90)
  • 组成水箱的元素是从背景(负片)中添加的值)朝向前景(z=0)。
  • 我无法从问题的图纸中弄清楚前部条带是否应作为一层延伸到水中。如有必要,可以使用相同的技术构建该层。
  • 我没有画右边的剖面图;我想这是一张简单的平面图。顺便说一下,我使用的三维坐标“识别平面与屏幕的交点。因此,平面截面是通过取具有z=0

在此处输入图片描述

代码

\documentclass[11pt, margin=23pt]{standalone}
\usepackage{tikz}
\usepackage{tikz-3dplot}
\usetikzlibrary{math, calc}
\begin{document}

\tikzset{%
  view/.style 2 args={% longitude / latitude
    z={({-sin(#1)}, {-cos(#1)*sin(#2)})},
    x={({cos(#1)}, {-sin(#1)*sin(#2)})},
    y={(0, {cos(#2)})},
    evaluate={%
      \tox={sin(#1)*cos(#2)};
      \toy={sin(#2)};
      \toz={cos(#1)*cos(#2)};
    }
  },
  w/.style={% water
    draw=cyan!40, fill=cyan!30, opacity=1, fill opacity=.9
  },
  w light/.style={% water, top face
    draw=cyan!35, fill=cyan!20, opacity=1, fill opacity=.95
  },
  tank/.style={% tank
    draw=blue!60!black, very thick, opacity=.95, line join=round
  },
  l/.style={draw=blue!50!gray, fill=blue!50!gray!40}
}
\tikzmath{
  real \r, \t, \aRG, \rw, \aw, \dl, \rl1, \rl2, \al1, \al2;
  \r = 2; % radius
  \t = 5*\r; % tank's length
  \rw = .3*\r; % controls the water's level
  \aw = {asin(\rw/\r)};
  \dl = 0.6*\r; % for the lebels
  \rl1 = .4*\r; % controls the layer's top level
  \rl2 = .55*\r; % controls the layer's bottom level
  \al1 = {asin(\rl1/\r)};
  \al2 = {asin(\rl2/\r)};
}
\begin{tikzpicture}[view={30}{11}, % latitude longitude
  every node/.style={scale=.8, text=black, text opacity=1},
  evaluate={\aRG = {atan2(-\tox, \toy)};}] % critical ruling's angle

  % tank / back side
  \path[tank, canvas is xy plane at z=-\t] (180: \r) arc (180: 360: \r);
  \path[tank] ({\r*cos(\aRG)}, {\r*sin(\aRG)}, 0)
  -- ({\r*cos(\aRG)}, {\r*sin(\aRG)}, -\t);

  % water
  \path[w, canvas is xy plane at z=0]
  ({180 +\aw}: \r) arc ({180 +\aw}: {360 -\aw}: \r) -- cycle;
  \path[w light, canvas is zx plane at y={-\rw}]
  (0, -{\r*cos(\aw)}) -- (0, {\r*cos(\aw)})
  -- (-\t, {\r*cos(\aw)}) -- (-\t, -{\r*cos(\aw)}) -- cycle;
  \path[w] ({\r*cos(-\aw)}, {\r*sin(-\aw)}, 0)
  {%
    [canvas is xy plane at z=0]
    -- ({-\aw}: \r) arc ({-\aw}: {\aRG}: \r)
  }{%
    [canvas is xy plane at z=-\t]
    -- ({\aRG}: \r) arc ({\aRG}: {-\aw}: \r)
  } -- cycle;

  % layer
  \path[l, canvas is xy plane at z=0]
  ({180 +\al1}: \r) arc ({180 +\al1}: {180 +\al2}: \r)
  -- ({-\al2}: \r) arc ({-\al2}: {-\al1}: \r) -- cycle;
  
  % tank / top and front side
  \path[tank, canvas is zx plane at y=0]
  (0, -\r) -- (0, \r) -- (-\t, \r) -- (-\t, -\r) -- cycle;
  \path[tank, canvas is xy plane at z=0] (180: \r) arc (180: 360: \r);
  
  \draw[gray, line width=.5pt, canvas is xy plane at z=0]
  (0, -\r) -- ++(-\dl -\r, 0) node (T0) {}
  ({180 +\aw}: \r) -- ++(-.5*\dl, 0) node (W1) {}
  ++(0, -\r +\rw) node (W0) {}
  (-\r, 0) -- ++(-\dl, 0) node (T1) {};
  \draw[gray, line width=.5pt, canvas is xy plane at z=-\t]
  (-\r, 0) -- ++(-\dl, 0) node (T2) {};
  \path[canvas is zx plane at y=0]
  (T1) edge[gray, <->, line width=.5pt] node[pos=.5, fill=white] {$50$} (T2)
  edge[gray, <->, line width=.5pt] node[pos=.5, fill=white] {$10$} (T0)
  (W1) edge[gray, <->, line width=.5pt] node[pos=.5, fill=white] {$?$} (W0);
\end{tikzpicture}

\end{document}

相关内容