2

I am trying to draw the diagram below in Tikz. I have been unable to do so, I need the minimalist and a 3D representation.

Mixing Problem unequal flow rates

4
  • 9
    Can you include your code of the failed version here too?
    – percusse
    Aug 17, 2014 at 0:21
  • 4
    Questions about how to draw specific graphics that just post an image of the desired result are really not reasonable questions to ask on the site. Please post a minimal compilable document showing that you've tried to produce the image and then people will be happy to help you with any specific problems you may have. See minimal working example (MWE) for what needs to go into such a document.
    – cfr
    Aug 17, 2014 at 0:49
  • 3
    If you are in a hurry, I recommend including your graphics using the graphicx \includegraphics{} since you clearly have the image available as an external image and TikZ may take a little while to learn. (You don't say how far you got in your attempts.)
    – cfr
    Aug 17, 2014 at 0:54
  • 5
    It is against our community guidelines as it is of the type "Do this for me" (even without the "please"). We should be consistent with this and close the question.
    – Ingo
    Aug 18, 2014 at 8:38

3 Answers 3

24
\documentclass[tikz,border=5]{standalone}
\usetikzlibrary{decorations.pathmorphing}
\usepackage[detect-all]{siunitx}

\tikzset{
   ragged border/.style={ decoration={random steps, segment length=1mm, amplitude=0.5mm},
           decorate,
   }
}

\begin{document}
  \begin{tikzpicture}
  \fill[cyan!30]
        decorate[ragged border]{
        (0,2) -- (6,2)
        }
        -- (6,1) -- (6.5,1) -- (6.5,0.5) -- (6,0.5) --(6,0) -- (0,0) -- cycle;
  \fill[cyan!30] (-0.5,2.5) -- (0,2.5) to[in=120,out=0](0.7,1.9)-- (1.4,1.9)
                  to[out=120,in=0] (0,3) -- (-0.5,3) -- cycle;
  \draw (-0.5,2.5) -- (0,2.5) -- (0,0) -- (6,0) -- (6,0.5) -- (6.5,0.5);
  \draw (-0.5,3) -- (0,3) -- (0,3.5) -- (6,3.5) -- (6,1) -- (6.5,1);
  \draw[|-|] (-0.2,0) --
        node[fill=white,font=\footnotesize,inner ysep=2pt,inner
                xsep=0]{$V_{0}$}(-0.2,2);
  \draw[stealth-] (-0.5,2.75) -- (-1,2.75)
            node[anchor=east,font=\footnotesize,align=right]{\SI{6}{\liter/\minute}\\\SI{0.1}{\kilo\gram/\liter}};
  \draw[-stealth] (6.5,0.75) -- (7.2,0.75)
            node[anchor=west,font=\footnotesize]{\SI{5}{\liter/\minute}};
  \node[anchor=north,font=\footnotesize] at (3,3) {$x(t)$};
  \node[anchor=north,font=\footnotesize] at (3,2) {?\si{\liter}};
  \node[anchor=north,font=\footnotesize] at (3,1) {$x(0) = \SI{0}{\kilo\gram}$};
\end{tikzpicture}%
\end{document}

enter image description here

5
  • 2
    The flowing liquid should form a parabolic trajectory, IMHO. Aug 17, 2014 at 11:25
  • 4
    @cyanide-basedfood Aah! I am poisoned!
    – user11232
    Aug 17, 2014 at 12:25
  • Thank you! on a future occasion I will include my progress as suggested @cfr Aug 17, 2014 at 13:57
  • @CristianRodríguez Welcome to tikz mafia. On your spare time please do read pgfmanual (tikz manual) which has lot of examples easy to understand. When you are struck, people here will always be happy to help.
    – user11232
    Aug 17, 2014 at 14:41
  • This is a great community, I appreciate the helpful attitude. usually I have problems with TikZ, since there are no manuals in Spanish, and I'm a Spanish speaker. I am in the process of learning English, but my level is still very basic. Aug 17, 2014 at 14:44
25

I decided to post this answer for several reasons:

  • This picture gives me the opportunity to show some useful options for users of TikZ.

  • I defined customizable macros for: Dimensions of the tank \tankwidth, \tankheight and \waterheight. This allows to change them without affect the picture (without exaggeration);

  • I defined a color for the water to allow changing in whole picture.
  • I show some features of the last version of PGF/Tikz (v 3.0.0) as: the pic operation, the arrows.meta library.
  • I use operations like parabola simuling a water fall.
  • The code is mostly commented for better understanding.
  • I use mathptmx for emulating the font used in the picture (Times).
  • I use the siunitx package to handle units.

The code

\documentclass{article}
\usepackage{mathptmx} % To emulate your `font`
\usepackage{siunitx} % To write units correctly 
\usepackage{tikz} % Obvious
\usetikzlibrary{decorations.pathmorphing} % To decorate the surface of water
\usetikzlibrary{arrows.meta} % The newer options for arrows (PGF 3.0)
\colorlet{water}{cyan!25} % Define color for the water
%--------------------------
% Dimensions of the tank
\def\tankwidth{6}
\def\tankheight{4}
\def\waterheight{2.2} % Water height 
%--------------------------
\tikzset{
    faucet/.pic={ % Define a 'pic' for the water inlet and outlet (PGF 3.0)
        \fill[water](-0.25,-0.25) rectangle (0.25,0.25);
        \draw[line width=1pt](-0.25,-0.25)--(0.25,-0.25) (-0.25,0.25)--(0.25,0.25);
    },
    myarrow/.tip={Stealth[scale=1.5]}, % Define a style for the tip of arrow
    surface water/.style= % style for border of water surface
    {decoration={random steps,segment length=1mm,amplitude=0.5mm}, decorate}
}
\begin{document}
\begin{tikzpicture}
% Water fill (I filled first so that way it is in the background)
\fill[water] decorate[surface water]{(\tankwidth,\waterheight) -- (0,\waterheight)}--(0,0) -- (\tankwidth,0) -- cycle;

% Tank
\draw[line width=1pt] (0,0) rectangle (\tankwidth,\tankheight);

\coordinate (entrance) at (0,\tankheight-0.7);
\coordinate (exit) at (\tankwidth,0.7);

\pic[xshift=-2.5mm+0.5pt] at (entrance) {faucet}; % water inlet (0.5pt is half of line width) 
\pic[xshift=2.5mm-0.5pt] at (exit) {faucet}; % outlet water

% Entrance label (with `siunitx`)
\node[align=right,left=1cm] (inlet-unit) at (entrance)  {\SI[per-mode=symbol]{6}{\liter\per\minute}\\\SI[per-mode=symbol]{0.1}{\kilogram\per\liter}};
 %[align=...] in the last node is necessary for splitting in two lines with `\\`
\draw[-myarrow](inlet-unit)--([xshift=-5mm]entrance);

% Exit label
\node[align=left,right=1cm] (outlet-unit) at (exit) {\SI[per-mode=symbol]{5}{\liter\per\minute}};
\draw[-myarrow]([xshift=5mm]exit)--(outlet-unit);

\draw[|-|] ([xshift=-2mm]0,0) -- node[fill=white,inner xsep=0]{$V_{0}$}([xshift=-2mm]0,\waterheight); 

% Fall water (i use `parabola` operation, it's more realistic, bacause it's a fall water) 
\fill[water] ([shift={(0.5pt,-2.5mm)}]entrance) parabola (0.3*\tankwidth,1pt) -- 
 (0.5*\tankwidth,1pt) parabola[bend at end] ([shift={(0.5pt,2.5mm)}]entrance);

% Inner labels
\path (0.5*\tankwidth,\tankheight)--(0.5*\tankwidth,0)
    node[pos=0.2] {$x(t)$}
    node[pos=0.5] {?\,L}
    node[pos=0.8] {$x(0)=\SI{0}{\kilogram}$};
\end{tikzpicture}
\end{document}

The result

enter image description here

You can change some parameters (without exaggeration) like \colorlet{water}{...}, \tankwidth, \tankheight, \waterheight ((entrance) and (exit) inclusive, but carefully) and to watch the behavior of the picture.

1
  • Muchas gracias!, tomé un par de cosas que necesitaba de acá, pero no te puedo dar el voto de mejor respuesta, soy alguien que aprecia la simplicidad del código ;) Aug 17, 2014 at 14:00
14

The following is intentionally made simple without labels just for fun with PSTricks.

\documentclass[pstricks,border=12pt,12pt]{standalone}
\usepackage{pst-eucl,pst-plot}
\pstVerb{realtime srand}

\psset
{
    algebraic,
    saveNodeCoors,
    NodeCoorPrefix=N,
    PointName=none,
    PointSymbol=none,
}

\def\parabola#1#2{\psplot{0}{#1}{(#2)*(1-(x/(#1))^2)}}

\begin{document}
\psLoop{10}{
\begin{pspicture}(8,6)
    \pstGeonode
        (0,5){A}
        (1,5){B}
        (1,6){C}
        (7,6){D}
        (7,2){E}
        (8,2){F}
        (8,1.5){G}
        (7,1.5){H}
        (7,0){I}
        (1,0){J}
        (1,3){K}
        (1,4.5){L}
        (0,4.5){M}  
    \pscustom[fillstyle=solid,linewidth=0,linestyle=none,fillcolor=cyan!40]
    {   
        \msave
            \translate(K)
            \parabola{1}{NLy-NKy}
            \reversepath
        \mrestore
        \psline(M)(A)(B)
        \msave
            \translate(K)
            \parabola{2}{NBy-NKy}
        \mrestore
        \closepath
    }
    \curvepnodes[plotpoints=30]{NJx}{NIx}{t|Rand*(1+sin(5*t))/7+NKy}{P}
    \pscustom[fillstyle=solid,linewidth=0,linestyle=none,fillcolor=cyan!35,opacity=.75]
    {   
        \psncurve(0,\Pnodecount){P}
        \psline(E)(F)(G)(H)(I)(J)
        \closepath
    }   
    \psline(A)(B)(C)(D)(E)(F)
    \psline(G)(H)(I)(J)(L)(M)
\end{pspicture}}
\end{document}

enter image description here

Not the answer you're looking for? Browse other questions tagged .