# TikZ: Drawing a cylinder with a hole the bottom

I am trying to draw something like this cylinder: . Here is my attempt:

    \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) {};

\end{tikzpicture}
\end{center}

\end{document}


which produces. The arc drawn along the bottom doesn't exactly match the top of the cylinder, and neither does the dashed ellipse in the middle. How can I match this better? How would I be able to add the effect of fluid flowing out of the hole?

• By specifying the height and width, aspect is used instead to modify the default short radius. So in this case the y radius should be 1.4(.125cm) where .125cm was the default used in all my test runs. – John Kormylo Jul 15 '15 at 16:45
• Very refreshing to see someone who has actually tried to draw the thing! Well done, nice question, and we should refer other users to this :) – cmhughes Jul 15 '15 at 19:20

Instead of using the predefined cylinder shape, I 'd just use arcs and an army of Mark Wibrow's droplets for the water:

The code:

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

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}
(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]
\filldraw[ultra thick,fill=droplet color!70,opacity=1,fill opacity=0.7]
(0,3) --
(0,0)
(4,3)
\draw[dashed]
\end{tikzpicture}

\end{document}

• Sorry that my own drawing was very unclear, but I am trying to draw a cylinder. I like the way your tikZ image looks and I will play with this code. Thank you. – julesjanker Jul 15 '15 at 15:42
• @julesjanker You're welcome. No problem. I added a version with a cylinder. – Gonzalo Medina Jul 15 '15 at 15:46

When you specify the width and height, the default value for the (in this case) y radius appears to be a constant 0.125cm. This is then scaled by the aspect parameter.

    \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) {};

%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}