将圆圈放在交叉线上

将圆圈放在交叉线上

我有下图。我想在交叉线上添加半圆(就像在电子电路中一样)。 在此处输入图片描述 这是我的代码:

\documentclass{article}
\usepackage{fixltx2e}
\usepackage{ntheorem}
\usepackage{float}
\usepackage{xr}
\usepackage{geometry}
\usepackage{algpseudocode}
\usepackage{algorithmicx}
\usepackage{algorithm}
\usepackage{chngcntr}
\usepackage{array}
\usepackage[justification=centering]{caption}
\usepackage{pifont}
\usepackage{verbatim}
\usepackage[english]{babel}
\usepackage{wrapfig}
\usepackage{capt-of}
\usepackage{color}
\usepackage{pdftricks}
\usepackage{etex}
\usepackage[version=0.96]{pgf}
\usepackage{tikz}
\usetikzlibrary{plotmarks,calc,arrows,shapes,snakes,automata,backgrounds,petri,positioning,fit}
\usepackage{proof}
\usepackage{latexsym}
\usepackage{amsfonts}
\usepackage{stackrel}
\usepackage{amsmath}
\usepackage{amssymb}
\usepackage{cases}
\usepackage{subcaption}
\usepackage{changepage}
\usepackage{makecell}
\usepackage{siunitx}
\begin{document}

\begin{figure}[H]
  \centering
\begin{tikzpicture}[->,node distance=1.3cm,>=stealth',bend angle=20,auto,
  place/.style={circle,thick,draw=blue!75,fill=blue!20,minimum size=10mm},
  red place/.style={place,draw=red!75,fill=red!20}
  every label/.style={red},
  every node/.style={scale=.6},
  dots/.style={fill=black,circle,inner sep=2pt},
  initial text={}]

  \node [accepting, place] (l0)  {$idle$};
  \node [place,below=1.5cm of l0,label={[shift={(-2.3,-1.9)}]$C$}] (l1) {$run$};

  \path (l0) edge [in=100, out=160,loop,looseness=4] node[left]{end} (l0)
         edge [bend left] node[right]{init} (l1)
    (l1) edge [in=-10, out=-70,loop,looseness=4] node[right]{end} (l1)
         edge [bend left] node[left]{run} (l0);

  \node [accepting, place] (p1-0) [right=2cm of l0,xshift=2cm] {$idle_1$};
  \node [place] (p1-1) [right=1.5cm of p1-0]{$wait_1$};
  \node [place] (p1-2) [below=1.5cm of p1-1,label={[shift={(2,-1.8)}]$T_1$}]            {$start_1$};
  \node [place] (p1-3) [left=1.5cm of p1-2,label=below:\textcolor{red}{$x\le k$}] {$exec_1$};

  \path (p1-0) edge node[align=center, pos=0.5]{$init_1$} (p1-1)
    (p1-1) edge node[align=center, pos=0.5]{$start_1$\\$x:=0$ } (p1-2)
    (p1-2) edge node[align=center, pos=0.5]{$process_1$,\\ $x\ge t_1$ } (p1-3)
    (p1-3) edge node[align=center, pos=0.5]{$end_1$} (p1-0);


  \node [place] (p2-1) [left=2cm of l0,xshift=-2cm]{$init_2$};
  \node [accepting, place] (p2-0) [left=1.5cm of p2-1]{$wait_2$};
  \node [place] (p2-2) [below=1.5cm of p2-1,label={[shift={(-5.5,-1.8)}]$T_2$}]            {$start_2$};
  \node [place] (p2-3) [left=1.5cm of p2-2,label=below:\textcolor{red}{$y\le p$}] {$exec_2$};

  \path (p2-0) edge node[align=center, pos=0.5]{$init_2$} (p2-1)
    (p2-1) edge node[align=center, pos=0.5]{$start_2$\\ $x:=0$ } (p2-2)
    (p2-2) edge node[align=center, pos=0.5]{$process_2$, $x\ge t_2$ } (p2-3)
    (p2-3) edge node[align=center, pos=0.5]{$end_2$} (p2-0);

  \node [accepting, place] (r0) [above=2.5cm of l0,xshift=-2.25cm,label={[shift={(-1.5,-1.8)}]$R$}] {$free$};
  \node [place,right=2cm of r0,label=right:\textcolor{red}{$z\le m$}] (r1) {$busy$};

  \path (r0) edge [bend left] node[above]{enter} (r1)
    (r1) edge [bend left] node[below]{exit} (r0);

  \node [inner xsep=3cm,inner ysep=2cm,draw, yshift=-1mm, fit=(l0)(l1)] (rec1) {};
  \node [inner xsep=3cm,inner ysep=1.5cm,draw, fit=(r0)(r1)] (rec2) {};
  \node [inner xsep=3cm,inner ysep=2cm,draw, fit=(p1-0)(p1-1)(p1-2)(p1-3)] (rec3) {};
  \node [inner xsep=3cm,inner ysep=2cm,draw, fit=(p2-0)(p2-1)(p2-2)(p2-3)] (rec4) {};
%  \node [inner xsep=4cm,inner ysep=2.5cm,draw, fit=(rec1)(rec2)(rec3)(rec4)] (rec5) {};
 % \node [inner xsep=1.5cm,inner ysep=5mm,draw,above=5mm of rec1] (rec5) {

  %  $\begin{aligned}
  %    \gamma &=\{
  %  init_1=\{init,init_1\}, start_1=\{start,start_1\}, process_1=\{enter,proces_1\}, 
  %  end_1=\{end,exit,end_1\}, \\
   %  & init_2=\{init, init_2\}, start_2=\{start,start_2\}, 
   % process_2=\{enter,process_2\},end_2=\{end,exit,end_2\}\} 
  %  \end{aligned}$
 % };

  \node [dots,label=90:$init_2$] (i2) at ($(rec4.south west)!0.6!(rec4.south east)$) {};
  \node [dots,label=90:$start_2$] (s2) at ($(rec4.south west)!0.8!(rec4.south east)$) {};
  \node [dots,label=-90:$end_2$] (e2) at ($(rec4.north east)!0.2!(rec4.north west)$) {};
  \node [dots,label=-90:$process_2$] (p2) at ($(rec4.north east)!0.5!(rec4.north west)$) {};

  \node [dots,swap,label=90:$init_1$] (i1) at ($(rec3.south east)!0.6!(rec3.south west)$) {};
  \node [dots,swap,label=90:$start_1$] (s1) at ($(rec3.south east)!0.8!(rec3.south west)$) {};
  \node [dots,swap,label=-90:$end_1$] (e1) at ($(rec3.north west)!0.2!(rec3.north east)$) {};
  \node [dots,swap,label=-90:$process_1$] (p1) at ($(rec3.north west)!0.5!(rec3.north east)$) {};

  \node [dots,label=-90:take] (tr) at ($(rec2.north west)!0.5!(rec2.north east)$) {};
  \node [dots,label=90:free] (fr) at ($(rec2.south west)!0.5!(rec2.south east)$) {};

  \node [dots,label=90:init] (ic) at ($(rec1.south west)!0.4!(rec1.south east)$) {};
  \node [dots,label=90:run] (rc) at ($(rec1.south west)!0.6!(rec1.south east)$) {};
  \node [dots,label=-90:end] (ec) at ($(rec1.north west)!0.5!(rec1.north east)$) {};

  \path (tr) ++(0,0.5cm) +(-1cm,0) coordinate(xp2) +(1cm,0) coordinate(xp1);
  \draw  [-] (p1) |-node[above,xshift=-2.5cm]{$process_1$} (xp1) -- (tr) -- (xp2)node[above,xshift=-2.5cm]{$process_2$} -| (p2);

  \path (ic) ++(0,-0.5cm) +(1cm,0) coordinate(xi1) +(-1cm,0) coordinate(xi2);
  \draw  [-] (i1) |-node[above,xshift=-2.5cm]{$init_1$} (xi1) -- (ic) -- (xi2)node[above,xshift=-2.5cm]{$init_2$} -| (i2);
  \path (rc) ++(0,-1cm) +(1cm,0) coordinate(sx1) +(-1cm,0) coordinate(sx2);
  \draw  [-] (s1) |-node[above,xshift=-2cm]{$start_1$} (sx1) -- (rc) -- (sx2)node[above,xshift=-2cm]{$start_2$} -| (s2);

  \path (fr) ++(0,-0.5cm) +(-1cm,0) coordinate(xe2) +(1cm,0) coordinate(xe1);
  \draw [-] (e1) |- node[above,xshift=-2cm]{$end_1$}(xe1) -- (ec);
  \draw [-] (xe1) -- (fr);
  \draw [-] (e2) |- node[above,xshift=2cm]{$end_2$}(xe2) -- (ec);
  \draw [-] (xe2) -- (fr);
 % \path (i1) ++(-0.5cm,0) coordinate(xi1);
 % \path (i2) ++(0.2cm,0) coordinate(xi2);
 % \path (s1) ++(-0.2cm,0) coordinate(xs1);
 % \path (s2) ++(0.2cm,0) coordinate(xs2);
 % \path (e1) ++(-0.3cm,0) coordinate(xe1);
 % \path (e2) ++(0.3cm,0) coordinate(xe2);
 % \path (p1) ++(-0.2cm,0) coordinate(xp1);
 % \path (p2) ++(0.2cm,0) coordinate(xp2);
 % \draw  [-] (i1) -- (xi1) -- (ic);
 % \draw  [-] (i2) -- (xi2) -- (ic);
 % \draw  [-] (s1) -- (xs1) -- (rc);
 % \draw  [-] (s2) -- (xs2) -- (rc);
 % \draw  [-] (e2) -- (xe2) -- (ec);
 % %\draw  [-] (xe2) -- (fr);
 % \draw  [-] (e1) -- (xe1) -- (ec);
%  \draw  [-] (xe1) -- (fr);


\end{tikzpicture}
\caption{A Timed system}\label{fig:run}
\end{figure}
\end{document}

我想将圆圈放在相交线上,如下图所示(仅考虑图 1a 和 1b): 在此处输入图片描述

答案1

使用该intersections库,您可以命名路径,然后使用交点放置半圆(我在代码中标记了添加的部分):

\documentclass{article}
\usepackage{tikz}
\usetikzlibrary{intersections,plotmarks,calc,arrows,shapes,snakes,automata,backgrounds,petri,positioning,fit}
\usepackage{siunitx}

\tikzset{
  connect/.style args={(#1) to (#2) over (#3) by #4}{
    insert path={
    let 
      \p1=($(#1)-(#3)$), 
      \n1={veclen(\x1,\y1)}, 
      \n2={atan2(\y1,\x1)}, 
      \n3={abs(#4)}, 
      \n4={#4>0 ?180:-180}  
      in 
      (#1) -- ($(#1)!\n1-\n3!(#3)$) 
      arc (\n2:\n2+\n4:\n3) -- (#2)
    }
  }
}

\begin{document}

\begin{figure}
  \centering
\begin{tikzpicture}[->,node distance=1.3cm,>=stealth',bend angle=20,auto,
  place/.style={circle,thick,draw=blue!75,fill=blue!20,minimum size=10mm},
  red place/.style={place,draw=red!75,fill=red!20}
  every label/.style={red},
  every node/.style={scale=.6},
  dots/.style={fill=black,circle,inner sep=2pt},
  initial text={}]

  \node [accepting, place] (l0)  {$idle$};
  \node [place,below=1.5cm of l0,label={[shift={(-2.3,-1.9)}]$C$}] (l1) {$run$};

  \path (l0) edge [in=100, out=160,loop,looseness=4] node[left]{end} (l0)
         edge [bend left] node[right]{init} (l1)
    (l1) edge [in=-10, out=-70,loop,looseness=4] node[right]{end} (l1)
         edge [bend left] node[left]{run} (l0);

  \node [accepting, place] (p1-0) [right=2cm of l0,xshift=2cm] {$idle_1$};
  \node [place] (p1-1) [right=1.5cm of p1-0]{$wait_1$};
  \node [place] (p1-2) [below=1.5cm of p1-1,label={[shift={(2,-1.8)}]$T_1$}]            {$start_1$};
  \node [place] (p1-3) [left=1.5cm of p1-2,label=below:\textcolor{red}{$x\le k$}] {$exec_1$};

  \path (p1-0) edge node[align=center, pos=0.5]{$init_1$} (p1-1)
    (p1-1) edge node[align=center, pos=0.5]{$start_1$\\$x:=0$ } (p1-2)
    (p1-2) edge node[align=center, pos=0.5]{$process_1$,\\ $x\ge t_1$ } (p1-3)
    (p1-3) edge node[align=center, pos=0.5]{$end_1$} (p1-0);


  \node [place] (p2-1) [left=2cm of l0,xshift=-2cm]{$init_2$};
  \node [accepting, place] (p2-0) [left=1.5cm of p2-1]{$wait_2$};
  \node [place] (p2-2) [below=1.5cm of p2-1,label={[shift={(-5.5,-1.8)}]$T_2$}]            {$start_2$};
  \node [place] (p2-3) [left=1.5cm of p2-2,label=below:\textcolor{red}{$y\le p$}] {$exec_2$};

  \path (p2-0) edge node[align=center, pos=0.5]{$init_2$} (p2-1)
    (p2-1) edge node[align=center, pos=0.5]{$start_2$\\ $x:=0$ } (p2-2)
    (p2-2) edge node[align=center, pos=0.5]{$process_2$, $x\ge t_2$ } (p2-3)
    (p2-3) edge node[align=center, pos=0.5]{$end_2$} (p2-0);

  \node [accepting, place] (r0) [above=2.5cm of l0,xshift=-2.25cm,label={[shift={(-1.5,-1.8)}]$R$}] {$free$};
  \node [place,right=2cm of r0,label=right:\textcolor{red}{$z\le m$}] (r1) {$busy$};

  \path (r0) edge [bend left] node[above]{enter} (r1)
    (r1) edge [bend left] node[below]{exit} (r0);

  \node [inner xsep=3cm,inner ysep=2cm,draw, yshift=-1mm, fit=(l0)(l1)] (rec1) {};
  \node [inner xsep=3cm,inner ysep=1.5cm,draw, fit=(r0)(r1)] (rec2) {};
  \node [inner xsep=3cm,inner ysep=2cm,draw, fit=(p1-0)(p1-1)(p1-2)(p1-3)] (rec3) {};
  \node [inner xsep=3cm,inner ysep=2cm,draw, fit=(p2-0)(p2-1)(p2-2)(p2-3)] (rec4) {};
%  \node [inner xsep=4cm,inner ysep=2.5cm,draw, fit=(rec1)(rec2)(rec3)(rec4)] (rec5) {};
 % \node [inner xsep=1.5cm,inner ysep=5mm,draw,above=5mm of rec1] (rec5) {

  %  $\begin{aligned}
  %    \gamma &=\{
  %  init_1=\{init,init_1\}, start_1=\{start,start_1\}, process_1=\{enter,proces_1\}, 
  %  end_1=\{end,exit,end_1\}, \\
   %  & init_2=\{init, init_2\}, start_2=\{start,start_2\}, 
   % process_2=\{enter,process_2\},end_2=\{end,exit,end_2\}\} 
  %  \end{aligned}$
 % };

  \node [dots,label=90:$init_2$] (i2) at ($(rec4.south west)!0.6!(rec4.south east)$) {};
  \node [dots,label=90:$start_2$] (s2) at ($(rec4.south west)!0.8!(rec4.south east)$) {};
  \node [dots,label=-90:$end_2$] (e2) at ($(rec4.north east)!0.2!(rec4.north west)$) {};
  \node [dots,label=-90:$process_2$] (p2) at ($(rec4.north east)!0.5!(rec4.north west)$) {};

  \node [dots,swap,label=90:$init_1$] (i1) at ($(rec3.south east)!0.6!(rec3.south west)$) {};
  \node [dots,swap,label=90:$start_1$] (s1) at ($(rec3.south east)!0.8!(rec3.south west)$) {};
  \node [dots,swap,label=-90:$end_1$] (e1) at ($(rec3.north west)!0.2!(rec3.north east)$) {};
  \node [dots,swap,label=-90:$process_1$] (p1) at ($(rec3.north west)!0.5!(rec3.north east)$) {};

  \node [dots,label=-90:take] (tr) at ($(rec2.north west)!0.5!(rec2.north east)$) {};
  \node [dots,label=90:free] (fr) at ($(rec2.south west)!0.5!(rec2.south east)$) {};

  \node [dots,label=90:init] (ic) at ($(rec1.south west)!0.4!(rec1.south east)$) {};
  \node [dots,label=90:run] (rc) at ($(rec1.south west)!0.6!(rec1.south east)$) {};
  \node [dots,label=-90:end] (ec) at ($(rec1.north west)!0.5!(rec1.north east)$) {};

  \path (tr) ++(0,0.5cm) +(-1cm,0) coordinate(xp2) +(1cm,0) coordinate(xp1);
  \draw  [-] (p1) |-node[above,xshift=-2.5cm]{$process_1$} (xp1) -- (tr) -- (xp2)node[above,xshift=-2.5cm]{$process_2$} -| (p2);

  \path (ic) ++(0,-0.5cm) +(1cm,0) coordinate(xi1) +(-1cm,0) coordinate(xi2);
  \draw[-,name path=line1] (i1) |-node[above,xshift=-2.5cm]{$init_1$} (xi1) -- (ic) -- (xi2)node[above,xshift=-2.5cm]{$init_2$} -| (i2); %here


  \path (rc) ++(0,-1cm) +(1cm,0) coordinate(sx1) +(-1cm,0) coordinate(sx2);
  
  \path[-,name path=line2] (s1) |-node[above,xshift=-2cm]{$start_1$} (sx1) -- (rc) -- (sx2)node[above,xshift=-2cm]{$start_2$} -| (s2); %here

 \path[name intersections={of=line1 and line2, by={a,b,c,d}}];% here

% draw semicircles at crossing points on the path
\coordinate (aux1) at (s2|-sx2);
\coordinate (aux2) at (s1|-sx1);
\draw[-,connect=(s2) to (aux1) over (d) by 3pt];
\draw[-] (aux1) -- (sx2);
\draw[-,connect=(sx2) to (rc) over (c) by 3pt];
\draw[-,connect=(rc) to (sx1) over (b) by 3pt];
\draw[-] (sx1) -- (aux2);
\draw[-,connect=(aux2) to (s1) over (a) by 3pt];

  \path (fr) ++(0,-0.5cm) +(-1cm,0) coordinate(xe2) +(1cm,0) coordinate(xe1);
  \draw [-] (e1) |- node[above,xshift=-2cm]{$end_1$}(xe1) -- (ec);
  \draw [-] (xe1) -- (fr);
  \draw [-] (e2) |- node[above,xshift=2cm]{$end_2$}(xe2) -- (ec);
  \draw [-] (xe2) -- (fr);
 % \path (i1) ++(-0.5cm,0) coordinate(xi1);
 % \path (i2) ++(0.2cm,0) coordinate(xi2);
 % \path (s1) ++(-0.2cm,0) coordinate(xs1);
 % \path (s2) ++(0.2cm,0) coordinate(xs2);
 % \path (e1) ++(-0.3cm,0) coordinate(xe1);
 % \path (e2) ++(0.3cm,0) coordinate(xe2);
 % \path (p1) ++(-0.2cm,0) coordinate(xp1);
 % \path (p2) ++(0.2cm,0) coordinate(xp2);
 % \draw  [-] (i1) -- (xi1) -- (ic);
 % \draw  [-] (i2) -- (xi2) -- (ic);
 % \draw  [-] (s1) -- (xs1) -- (rc);
 % \draw  [-] (s2) -- (xs2) -- (rc);
 % \draw  [-] (e2) -- (xe2) -- (ec);
 % %\draw  [-] (xe2) -- (fr);
 % \draw  [-] (e1) -- (xe1) -- (ec);
%  \draw  [-] (xe1) -- (fr);


\end{tikzpicture}
\caption{A Timed system}\label{fig:run}
\end{figure}
\end{document}

图像的一部分显示了交叉点处的半圆:

在此处输入图片描述

我使用了 Mark Wibrow 的连接风格的变体his answerTikZ 中两条线的交点实际上并未连接

附注:$init_1$您不应该使用标签,而应该使用类似的$\text{init}_1$(以及与其它标签类似的)。

相关内容