7

Consider the following TikZ drawing:

enter image description here

Why do the lines not go "all the way"? And why does that line appear below what is supposed to look like a water tank?

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\def\balloonheight{1.5}
\def\ballooonwidth{1}
\def\vwidth{0.3}
\def\vheight{3}
\def\vpos{-3}
\centering
\begin{tikzpicture}
    \tikzstyle{balloon}=[ball color=red];
    \shade[balloon] ellipse (1 and 1.5);

    \coordinate (bottom) at (0,-1.5);

    \coordinate (vtop) at (0,\vpos);
    \coordinate (vbottom) at (0,{\vpos - \vheight} );
    \coordinate (vtopright) at (\vwidth, -3 );
    \coordinate (vtopleft) at (-\vwidth, -3 );

    \draw[rounded corners=8pt, thick,black] (vtopright) |- (vbottom) -| (vtopleft);

    \draw[fill=blue!50!white] decorate [blue,decoration={snake}] {(vtopleft)++(0,-0.5) -- ++(2*\vwidth, 0 )} [rounded corners=8pt] |- (vbottom) -| (vtopleft)++(0,-0.5);

    \draw[orange] (bottom) -- coordinate[midway] (ropemid) (vtop) -- ++(0,-1);

    \coordinate (current) at (4,-1.5);

    \path (current) -- ++(0,0.3) node (current+) {};
    \path (current) -- ++(0,-0.3) node (current-) {};

    \draw[thick] (current+) -- +(-0.5,0) -- ++(0.5,0);
    \draw[thick] (current-) -- +(-0.2,0) -- ++(0.2,0);

    \path (vbottom) -- ++(0,-0.5) node (belowvbottom) {};
    \path (vtopleft) -- ++(0,-1.5) node (+entrance) {};
    \path (vtopright) -- ++(0,-1.5) node (-entrance) {};

    \draw[rounded corners=8pt,thick] (current+) |- ++(1,1) |- (belowvbottom) -- ++(-1,0) |- (+entrance);
    \draw[rounded corners=8pt, thick] (current-) |- (-entrance);

    \draw[thick,rounded corners=8pt] (ropemid) -- ++(2,0) 
    node[fill=white, draw, rectangle,rounded corners,align=center] (pico) {PicoScope} -| (current-);

\end{tikzpicture}
\end{document}
nickpapior
  • 17,275
Gaussler
  • 12,801

1 Answers1

6

For the closing of the lines, note that drawing to a node (node) draws to the edge of that, to draw to the middle use (node.center). Alternatively, as suggested in the comments define a coordinate instead of a node.

For the line at the bottom of the water tank, as mentioned this is an artefact from large values of rounnded corners creating short edges. You can draw each half separately to avoid this and do the filling separately:

Sample output

\documentclass{memoir}
\usepackage{tikz}
\usetikzlibrary{decorations.pathmorphing}

\begin{document}
\def\balloonheight{1.5}
\def\ballooonwidth{1}
\def\vwidth{0.3}
\def\vheight{3}
\def\vpos{-3}
\centering
\begin{tikzpicture}
  \tikzstyle{balloon}=[ball color=red];
  \shade[balloon] ellipse (1 and 1.5);

  \coordinate (bottom) at (0,-1.5);

  \coordinate (vtop) at (0,\vpos);
  \coordinate (vbottom) at (0,{\vpos - \vheight} );
  \coordinate (vtopright) at (\vwidth, -3 );
  \coordinate (vtopleft) at (-\vwidth, -3 );

  \fill[blue!50!white] decorate [decoration={snake}]
  {(vtopleft)++(0,-0.5) -- ++(2*\vwidth, 0 )} [rounded corners=8pt]
  |- (vbottom) -| (vtopleft)++(0.1,-0.5);

  \draw decorate [decoration={snake}] {(vtopleft)++(0,-0.5) --
  ++(2*\vwidth, 0 )}; 
  \draw[rounded corners=8pt,thick,black] (vtopright) |- (vbottom);
  \draw[rounded corners=8pt,thick,black] (vbottom) -| (vtopleft); 

  \draw[orange] (bottom) -- coordinate[midway] (ropemid) (vtop) -- ++(0,-1);

  \coordinate (current) at (4,-1.5);

  \path (current) -- ++(0,0.3) node (current+) {};
  \path (current) -- ++(0,-0.3) node (current-) {};

  \draw[thick] (current+) -- +(-0.5,0) -- ++(0.5,0);
  \draw[thick] (current-) -- +(-0.2,0) -- ++(0.2,0);

  \path (vbottom) -- ++(0,-0.5) node (belowvbottom) {};
  \path (vtopleft) -- ++(0,-1.5) node (+entrance) {};
  \path (vtopright) -- ++(0,-1.5) node (-entrance) {};

  \draw[rounded corners=8pt,thick] (current+.center) |- ++(1,1) |-
  (belowvbottom.center) -- ++(-1,0) |- (+entrance); 
  \draw[rounded corners=8pt, thick] (current-.center) |- (-entrance);

  \draw[thick,rounded corners=8pt] (ropemid) -- ++(2,0) 
  node[fill=white, draw, rectangle,rounded corners,align=center]
  (pico) {PicoScope} -| (current-); 
\end{tikzpicture}

\end{document}
Andrew Swann
  • 95,762