TikZ 线路没有“全程”

TikZ 线路没有“全程”

考虑以下 TikZ 绘图:

在此处输入图片描述

为什么这些线条没有“完全”延伸?为什么那条线出现在看起来像水箱的东西下面?

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

答案1

对于线条的闭合,请注意,绘制到节点(node)会绘制到该节点的边缘,绘制到中间使用(node.center)。或者,如注释中所建议的那样,定义一个坐标而不是节点。

对于水箱底部的线,如上所述,这是由于rounnded corners创建短边的较大值而产生的伪影。您可以分别绘制每一半以避免这种情况并分别进行填充:

示例输出

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

相关内容