3

I want to draw this picture:

enter image description here

I tried to to it using:

\documentclass[11pt,a4paper]{article} 

\usepackage{xcolor}
\definecolor{lightgray}{gray}{0.9}
\usepackage{tikz}
\usetikzlibrary{calc,patterns,decorations.pathmorphing,arrows.meta,decorations.markings}
\tikzset{place/.style={  circle,
        fill=gray!20,
        thick,
        inner sep=0pt,
        minimum size=6mm},
        spring/.style={ decorate,
                        decoration={zigzag,
                                    pre length=0.3cm,
                                    post length=0.3cm,
                                    segment length=6,
                                    amplitude=6
                                    }
                      },
        damper/.style={ thick,
                        decoration={markings,
                                    mark connection node=dmp,
                                    mark=at position 0.5 with {\node (dmp) [thick,
                                                                            inner sep=0pt,
                                                                            transform shape,
                                                                            rotate=-90,
                                                                            minimum width=15pt,
                                                                            minimum height=3pt,
                                                                            draw=none] {};
                                                                \draw [thick] ($(dmp.north east)+(2.5pt,0)$) -- (dmp.south east) -- (dmp.south west) -- ($(dmp.north west)+(2pt,0)$);
                                                                \draw [thick] ($(dmp.north)+(0,-5pt)$) -- ($(dmp.north)+(0,5pt)$);
                                                                }
                                    },
                        decorate
                      },
        ground/.style={ fill,
                        pattern=north east lines,
                        draw=black,
                        minimum width=0.3cm,
                        minimum height=0.3cm
                      },
        bar/.style={fill=lightgray,
                    draw=black,
                    minimum width=6cm,
                    minimum height=0.2cm,
                    inner sep=0pt,
                    anchor=west
                   }
    }


\begin{document}


\begin{tikzpicture}[>=latex,
                    every node/.style={outer sep = 0pt,
                                       thick
                                      }
                   ]
%% Begining


\draw[thick] (0,0) -+ (6,0) node(l1){};;
\draw[thick] (0,0.5) -- (0.5,0.5) node(l2){};
\draw[thick] (l2.east) -+ ($(l2.east)+(0,2)$) node(l3){};
\draw[thick] (6,0.5) -+ (5.5,0.5) node(l4){};
\draw[thick] (l4.west) -+ ($(l4.west)+(0,2)$) node(l5){};

\node (seperation) [ground,anchor=south,minimum width=0.5cm,minimum height=2cm] at (3,0.5) {};

\draw[thick] (l1.east) -+ ($(l1.east)+(0,-2)$) node(l6){};
\draw[thick] (l6.south) -+ ($(l6.south)+(2.75,0)$) node(l7){};
\draw[thick] ($(l7.east)+(0,0.5)$) -+ ($(l7.east)+(-0.5,0.5)$) node(l8){};
\draw[thick] (l8.west) -+ ($(l8.west)+(0,2)$) node(l9){};

\draw[thick] (0,0) -+ ($(0,0)+(0,-2)$) node(l10){};
\draw[thick] (l10.south) -+ ($(l10.south)+(-2.75,0)$) node(l11){};
\draw[thick] ($(l11.west)+(0,0.5)$) -+ ($(l11.west)+(0.5,0.5)$) node(l12){};
\draw[thick] (l12.east) -+ ($(l12.east)+(0,2)$) node(l13){};

\draw[thick] (l5.north) -+ ($(l5.north)+(2.75,0)$) node(l14){};
\draw[thick] ($(l5.north)+(0,0.5)$) -+ ($(l5.north)+(0.5,0.5)$) node(l15){};
\draw[thick] (l15.east) -+ ($(l15.east)+(0,2)$) node(l16){};
\draw[thick] (l14.east) -+ ($(l14.east)+(0,2)$) node(l17){};

\end{tikzpicture}

\end{document}

enter image description here

But I have a problem in:

1.Connecting lines

2.Creating details like Q, x,R ticks and other labels and water stream like this one:

enter image description here

3
  • You can draw two perpendicular lines using -|. Example: \draw[thick] (0,0)-|+(1,6);. By details you mean the labels?
    – Roald
    Oct 8, 2016 at 13:42
  • Also instead of hardwiring in all those points it might help to define the as named coordinates. Then it will also be easier to make the colored triangles, by defining them from other coordinates. I tend to make most of my tikz drawings like that. It is an interesting image, but I'm not at a pc, so cannot help more at the moment. Btw probably not a good idea to use nodes as a naming device, that is why you get the holes, nodes has an inner size and lines between them go to the edge. Use coordinate instead
    – daleif
    Oct 8, 2016 at 17:51
  • You can also write: \draw[thick] (l2.center) -+ ($(l2.center)+(0,2)$), then the gap is all gone. Although my earlier suggestion is better, in my opinion.
    – Roald
    Oct 8, 2016 at 18:43

1 Answer 1

4

I think this is a good practice of pic-syntax

\documentclass[border=9,tikz]{standalone}
\begin{document}

\tikzset{
    pics/.cd,
    reservoir/.style={
        code={
            \fill[rounded corners,blue!50]  (-1,#1-1)--(-1,-1)--(1,-1)--(1,#1-1);
            \draw[rounded corners](-1.1,1)--(-1,.9)--(-1,-1)--(1,-1)--(1,.9)--(1.1,1);
        }
    },
    right valve/.style={
        code={
            \fill[blue!50](-.1, .1)--(.2, .1)arc(90:0:.2)        --(-.1,-.1);
            \draw         (-.1, .1)--(.2, .1)arc(90:0:.2)(.2,-.1)--(-.1,-.1);
            \fill(.1, .1)+(-.05,0)--+(.05,0)--+(0,-.07)
                 (.1,-.1)+(-.05,0)--+(.05,0)--+(0, .07);
            \draw[blue!50,line width=.2cm,domain=0:#1,samples=#1*10,shift={(.3,-.3)}]
                 (0,.2)--(0,.1)--plot({rand/30},-\x);
        }
    },
    left valve/.style={
        /tikz/xscale=-1,right valve=#1
    },
    pipe/.style={
        code={
            \fill[blue!50](-#1-.1,.1)rectangle(#1+.1,-.1);
            \draw         (-#1-.1,.1)--(#1+.1,.1)(-#1-.1,-.1)--(#1+.1,-.1);
            \fill(0, .1)+(-.05,0)--+(.05,0)--+(0,-.07)
                 (0,-.1)+(-.05,0)--+(.05,0)--+(0, .07);
        }
    }
}

\tikz{
    \path                                               (4,6  )pic{reservoir=1.5}
         (-3,6.5)pic{right valve=2}                     (3,5.5)pic{left valve=2.2}
         (-2,3  )pic{reservoir=1.8}                     (2,3  )pic{reservoir=.7}
                                    (0,2.5)pic{pipe={1}}
         (-3,2.5)pic{left valve=2.7}                    (3,2.5)pic{right valve=1.6}
         (-4,0  )pic{reservoir=.2}                      (4,0  )pic{reservoir=1.1}
    ;
}

\end{document}

For labels, you can add the corresponding code to the definition of pic as follows

\tikzset{
    pics/labeled reservoir/.style 2 args={
        code={
            \fill[rounded corners,blue!50]  (-1,#1-1)--(-1,-1)--(1,-1)--(1,#1-1);
            \draw[rounded corners](-1.1,1)--(-1,.9)--(-1,-1)--(1,-1)--(1,.9)--(1.1,1);
            \draw[->](0,-.9)--(0,#1-1)node[below right]{$#2$};
        }
    },
}
\tikz{
    \path pic{labeled reservoir={1.3}{h_3}};
}

\tikzset{
    pics/labeled right valve/.style n args={3}{
        code={
            \fill[blue!50](-.1, .1)--(.2, .1)arc(90:0:.2)        --(-.1,-.1);
            \draw         (-.1, .1)--(.2, .1)arc(90:0:.2)(.2,-.1)--(-.1,-.1);
            \fill(.1, .1)+(-.05,0)--+(.05,0)--+(0,-.07)
                 (.1,-.1)+(-.05,0)--+(.05,0)--+(0, .07)
                 (.2, .1)node[above]{$#2$};
            \draw[blue!50,line width=.2cm,domain=0:#1,samples=#1*10,shift={(.3,-.3)}]
                 (0,.2)--(0,.1)--plot({rand/30},-\x)node[above right,black]{$#3$};
        }
    },
}
\tikz{
    \path pic{labeled right valve={1.3}{R_4}{Q_4}};
}
0

You must log in to answer this question.

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