TikZ:放置一条与连接节点的边缘平行的线(转换成正弦形状)

TikZ:放置一条与连接节点的边缘平行的线(转换成正弦形状)

我正在画一个小草图,其中一条线进入一个圆圈,然后出现另外三条线。每条线上方都有一条小正弦曲线(几乎就像我使用了一种构造,\node (a) edge node[auto] {Some caption} (b);您可以在 PGF 手册 2.10 第 48 页找到它);这说明了我目前所拥有的(下面的代码):

在此处输入图片描述

我的问题是:我怎样才能将一条波浪线(例如左侧的线)放置在右侧其他 3 条线的上方?尤其是向北和向东南的线让我很困扰。此外:我怎样才能让锚点围绕中间节点(潜在节点)放置在一个圆圈上,以便我的所有边都具有相同的长度?

迄今为止:我通过在左边缘上方放置两个空节点,并将一个节点在 x 轴上向左移动,一个节点向右移动,并命名它们,从而将线放置在左边缘上方:

\node[shape=coordinate] (arrow start) [left=of potential,xshift=-1cm] {}
    edge [post] node[auto,above,name=wavestart,yshift=0.3cm,xshift=-0.7cm] {}
                node[auto,above,name=waveend,yshift=0.3cm,xshift=0.7cm] {} (potential);

之后,我可以通过仅在它们之间创建另一条边并对其进行路径变形来轻松连接这些新节点:

\path (wavestart) edge[decorate,decoration={snake,amplitude=1.4mm, segment length=15pt}] (waveend);

全部代码:

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{patterns,positioning,decorations.pathmorphing,arrows}

\begin{document}

\begin{tikzpicture}%
    [post/.style={->,shorten >=1pt,>=stealth',semithick}]

    \node[circle, draw=black, pattern color=gray,%
     pattern=north east lines,label=below:$V(x)$,%
     minimum size=1cm] (potential) {};
    \node[shape=coordinate] [above right=of potential] (outgoing up) {};
    \node[shape=coordinate] [right=of potential] (outgoing mid) {};
    \node[shape=coordinate] [below right=of potential] (outgoing down) {};

    \path (potential)
        edge[post] (outgoing up)
        edge[post] (outgoing mid)
        edge[post] (outgoing down);

    \node[shape=coordinate] (arrow start) [left=of potential,xshift=-1cm] {}
        edge [post] node[auto,above,name=wavestart,yshift=0.3cm,xshift=-0.7cm] {}
                                node[auto,above,name=waveend,yshift=0.3cm,xshift=0.7cm] {} (potential);

    \path (wavestart) edge[decorate,decoration={snake,amplitude=1.4mm, segment length=15pt}] (waveend);



\end{tikzpicture}

\end{document}

答案1

您可以将波浪线放在节点中,然后像平常一样定位它。示例代码:

\documentclass{standalone}
\usepackage{tikz}
\usetikzlibrary{patterns,positioning,decorations.pathmorphing,arrows}
\begin{document}
\def\sinline{\tikz\draw[decorate,decoration={snake,amplitude=1.4mm, segment length=15pt}] (0,0) -- (.8,0);}
\begin{tikzpicture}%
    [post/.style={->,shorten >=1pt,>=stealth',semithick}]

    \node[circle, draw=black, pattern color=gray,%
     pattern=north east lines,label=below:$V(x)$,%
     minimum size=1cm] (potential) {};
    \node[shape=coordinate] [above right=of potential] (outgoing up) {};
    \node[shape=coordinate] [right=of potential] (outgoing mid) {};
    \node[shape=coordinate] [below right=of potential] (outgoing down) {};

    \path (potential) ++(-2,0) edge[post] node[above,sloped]{\sinline} (potential);

    \path (potential)
        edge[post] node[above,sloped]{\sinline} (outgoing up)
        edge[post] node[above,sloped]{\sinline} (outgoing mid)
        edge[post] node[above,sloped]{\sinline} (outgoing down);

\end{tikzpicture}
\end{document}

结果:

波浪线

答案2

对于这种路径的注释是专门pic为 s 而做的。

图片被调用sine并被绘制成这样,给出的选项pic[<options>]可以通过pic actions键在图片代码中使用。

我已将其pic直接添加到post样式中,并为正弦曲线添加了一个可选颜色参数。

代码

\documentclass[tikz]{standalone}
\usetikzlibrary{patterns,arrows.meta}
\begin{document}
\begin{tikzpicture}[
  reset/.style={color=black,thin,solid,opaque,line cap=butt,line join=miter,arrows=-},
  post/.style={
    -{Stealth[round]}, shorten >=1pt, semithick,
    edge node={pic[reset,sloped,draw=#1]{sine}}},
  post/.default=black,
  sine/.pic={
    \path[yscale=.1,xscale=.08,pic actions] (-2*pi,2)
      foreach \i in {1,-1,1,-1} {
        sin ++(pi/2,+\i) cos ++(pi/2,+-\i) };
  }]

\node[circle, draw=black, pattern color=gray, pattern=north east lines,
      label=below:$V(x)$, minimum size=1cm] (potential) {};

\path (potential) ++ (left:2) edge[post] (potential)
      (potential)             edge[post=red]   ++ ( 45:2)
                              edge[post=green] ++ (  0:2)
                              edge[post=blue]  ++ (-45:2);
\end{tikzpicture}
\end{document}

输出

在此处输入图片描述

相关内容