TikZ:绘制底部有孔的圆柱体

TikZ:绘制底部有孔的圆柱体

我正在尝试绘制类似这样的圆柱体:有水通过一个孔流出的圆柱体。这是我的尝试:

    \documentclass{article}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usetikzlibrary{snakes,shapes,decorations.text}

    \begin{document}

    \begin{center}
    \begin{tikzpicture}
   %\draw (-4,-4) grid (4,4);

   \draw (0,0) node[cylinder,draw=black,thick,aspect=1.4,
    minimum height=3cm,minimum width=2.5cm,
    shape border rotate=90,
    cylinder uses custom fill,
    cylinder body fill=blue!30,
    cylinder end  fill=blue!10, opacity=.4,anchor=north]
   (A) {};

    \draw [dashed] (1.23,-2.87) arc[x radius=1.24, y radius=1/3, start angle=0, end angle=180];

    \draw [dashed] (0,-2.8) ellipse[x radius=0.3, y radius=1/12, start angle=0, end angle=180];
    \end{tikzpicture}
    \end{center}

    \end{document}

产生这。沿底部绘制的弧线与圆柱体的顶部并不完全匹配,中间的虚线椭圆也不完全匹配。我怎样才能更好地匹配?我怎样才能添加流体从孔中流出的效果?

在此处输入图片描述

答案1

我不使用预定义的cylinder形状,而是使用圆弧和一组Mark Wibrow 的 droplets对于水:

在此处输入图片描述

代码:

\documentclass[tikz,border=4pt]{standalone}

\pgfdeclareradialshading[droplet color]{droplet}{\pgfqpoint{-10bp}{-10bp}}{%
 color(0bp)=(droplet color!50!white);
 color(9bp)=(droplet color!75!white);
 color(18bp)=(droplet color!85!black);
 color(25bp)=(droplet color);
 color(50bp)=(droplet color!50!white)}

\colorlet{droplet color}{blue!50!cyan!80}
\tikzset{%
  raindrop/.pic={
    code={\tikzset{scale=1/10}
 \shade [shading=droplet]
 (0,0)  .. controls ++(0,-1) and ++(0,1) .. (1,-2)
 arc (360:180:1)
 .. controls ++(0,1) and ++(0,-1) .. (0,0) -- cycle;
  }}}

\begin{document}

\begin{tikzpicture}[line join=round]
\begin{scope}[yshift=-6pt]
\foreach \Coord in {{(2,0)},{(2.3,-0.25)},{(2.2,-0.3)},{(2.2,-0.4)}%,
  ,{(1.8,0)},{(1.7,-0.25)},{(2,-0.3)},{(1.8,-0.4)}%
  ,{(1.7,-0.2)},{(1.9,-0.5)},{(2,-0.4)},{(1.9,-0.3)}%
  ,{(2.3,-0.2)},{(2.1,-0.5)},{(2,-0.3)},{(2.1,-0.3)}%
  ,{(2.3,-0.1)},{(2.1,-0.2)},{(2,-0.15)},{(2.1,-0.05)}%
  ,{(1.7,-0.1)},{(1.9,-0.25)},{(2,-0.1)},{(1.9,-0.15)}%
  } 
  \path \Coord pic {raindrop};
\end{scope}
\begin{scope}[yshift=4pt]
\foreach \Coord in {{(2,0)},{(2.3,-0.25)},{(2.2,-0.3)},{(2.2,-0.4)}%,
  ,{(1.8,0)},{(1.7,-0.25)},{(2,-0.3)},{(1.8,-0.4)}%
  ,{(1.7,-0.2)},{(1.9,-0.5)},{(2,-0.4)},{(1.9,-0.3)}%
  ,{(2.3,-0.2)},{(2.1,-0.5)},{(2,-0.3)},{(2.1,-0.3)}%
  ,{(2.3,-0.1)},{(2.1,-0.2)},{(2,-0.15)},{(2.1,-0.05)}%
  ,{(1.7,-0.1)},{(1.9,-0.25)},{(2,-0.1)},{(1.9,-0.15)}%
  ,{(2.2,0)},{(1.7,-0.1)},{(2,0)},{(1.9,-0.1)}%
  } 
  \path \Coord pic {raindrop};
\end{scope}
\filldraw[draw=black,ultra thick,fill=droplet color!20]
 (0,3) arc[x radius=2, y radius=0.4, start angle=180, end angle=0]
 (4,3) arc[x radius=2, y radius=0.4, start angle=0, end angle=-180];
\filldraw[ultra thick,fill=droplet color!70,opacity=1,fill opacity=0.7]
  (0,3) -- 
  (0,0) 
  arc[x radius=2, y radius=0.4, start angle=-180, end angle=0] --
   (4,3)
  arc[x radius=2, y radius=0.4, start angle=0, end angle=-180];
\draw[dashed] 
  (0,0) arc[x radius=2, y radius=0.4, start angle=180, end angle=0]
  (1.5,0) arc[x radius=0.5, y radius=0.12, start angle=180, end angle=0]
  (1.5,0) arc[x radius=0.5, y radius=0.12, start angle=-180, end angle=0];
\end{tikzpicture}

\end{document}

答案2

当您指定宽度和高度时,(在本例中)y 半径的默认值似乎是一个常数 0.125cm。然后按宽高比参数缩放。

圆柱方面

    \documentclass[border=.1in]{standalone}
    \usepackage{graphicx}
    \usepackage{tikz}
    \usetikzlibrary{snakes,shapes,decorations.text}

    \begin{document}

    \begin{tikzpicture}
   %\draw (-4,-4) grid (4,4);

   \draw (0,0) node[cylinder,draw=black,thick,aspect=1.4,
    minimum height=3cm,minimum width=2.5cm,
    shape border rotate=90,
    cylinder uses custom fill,
    cylinder body fill=blue!30,
    cylinder end  fill=blue!10, opacity=.4,anchor=north]
   (A) {};

    \draw [dashed] (1.25,-2.825) arc[x radius=1.25, y radius=.175, start angle=0, end angle=180];

    \draw [dashed] (0,-2.825) ellipse[x radius=0.3, y radius=.042, start angle=0, end angle=180];

    %demo
    \draw (4,0) node[cylinder,draw=black,thick,aspect=1,
    minimum height=3cm,minimum width=2.5cm,
    shape border rotate=90,
    cylinder uses custom fill,
    cylinder body fill=blue!30,
    cylinder end  fill=blue!10, opacity=.4,anchor=north]
   {};
  \draw (4,0) node[cylinder,draw=black,thick,
    minimum height=1cm,minimum width=1cm,
    shape border rotate=90,
    cylinder uses custom fill,
    cylinder body fill=blue!30,
    cylinder end  fill=blue!10, opacity=.4,anchor=north]
   {};
  \draw (4,0) node[draw=red,
    minimum height=3cm,minimum width=2.5cm,
    shape border rotate=90,anchor=north]
   {aspect demo};
  \draw[green] (4,0) -- (4,-.25) (2.75,-.125) -- (5.25,-.125);

    \end{tikzpicture}
    \end{document}

相关内容