Tikz:带有交叉线的求和块的框图

Tikz:带有交叉线的求和块的框图

我想要绘制如下图所示的框图。 在此处输入图片描述

我已经制作了以下代码

\documentclass{article}

   \usepackage{tikz}
   \usetikzlibrary{shapes,arrows}
\begin{document}

\tikzstyle{block} = [draw, fill=white, rectangle, 
minimum height=3em, minimum width=6em]
 \tikzstyle{sum} = [draw, fill=white, circle, node distance=1cm]
 \tikzstyle{input} = [coordinate]
 \tikzstyle{output} = [coordinate]
  \tikzstyle{pinstyle} = [pin edge={to-,thin,black}]

\tikzset{
charge node/.style={inner sep=0pt},
pics/sum block/.style n args={4}{
    code={
        \path node (n) [draw, circle, inner sep=0pt, minimum size=9mm] {}
        (n.north) +(0,-1.5mm) node [charge node] {$#1$}
        (n.south) +(0,1.5mm) node [charge node] {$#2$}
        (n.west) +(1.5mm,0) node [charge node] {$#3$}
        (n.east) +(-1.5mm,0) node [charge node] {$#4$}
        ;
        \draw
        (n.north west) -- (n.south east)
        (n.south west) -- (n.north east)
        ;
    }
      }
    }
 \begin{tikzpicture}
\path pic at (20mm,0) {sum block={}{-}{+}{}};
 \end{tikzpicture}

 \begin{tikzpicture}[auto, node distance=3cm,>=latex']

\node [input, name=input] {};
\node [sum, right of=input] (sum) {};
\node [block, right of=sum] (controller) {$K_p + \frac{K_i}{s} + K_ds$};
\node [block, right of=controller,
        node distance=4cm] (system) {$G_p(s)$};

\draw [->] (controller) -- node[name=u] {$u(s)$} (system);
\node [output, right of=system] (output) {};
%\node [block, below of=u] (measurements) {Measurements};
\coordinate [below of=u] (measurements) {};
  \draw [draw,->] (input) -- node[pos=0.3] {Set point} (sum);
 \draw [->] (sum) -- node {$E(s)$} (controller);
  \draw [->] (system) -- node [name=y] {Output}(output);
    %\draw [->] (y) |- (measurements);
  \draw [-] (y) |- (measurements);
     %\draw [->] (measurements) -| node[pos=0.99] {$-$} 
    \draw [->] (measurements) -| %node[pos=1.00] {$-$}  
  node [near end] {} (sum);

  %\draw [->] 
 \end{tikzpicture}

上面的代码绘制了两个图形:求和块和框图。我想在第二个图形制作的框图中使用第一个图形中绘制的求和块。换句话说,我想要一个由上面的代码制作的第二个图形绘制的交叉线求和块。请告诉我怎么做

答案1

这是对 Zarko 的回答的扩展评论,我之所以写这个评论是因为我们讨论过这个问题好几次。我将其设为社区 Wiki,以明确表示我对“窃取声誉点数”不感兴趣。但是,我感兴趣的是为 OP 提供一些符合 pgfmanual 规则的内容。pgfmanual 在第 166 页上说。

在此处输入图片描述

我还没有见过真正需要使用它\pgfextra来绘制路径的情况。特别是,在这种情况下,你可以这样做

\documentclass{article}
\usepackage{nccmath}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,    % changed
                calc, chains,   % new
                positioning,    % new
                quotes          % new
                }

\begin{document}
    \begin{tikzpicture}[auto, 
  node distance = 6mm and 14mm,
    start chain = A going right,
block/.style = {draw,
                minimum height=11mm, minimum width=12mm,
                on chain=A},
  sum/.style = {circle, draw, minimum size=9mm,
                append after command={\pgfextra{\let\LN\tikzlastnode}
                       (\LN.north west) edge (\LN.south east)
                            (\LN.south west) edge (\LN.north east)
                    node[left]     at (\LN.center) {$+$}
                    node[below]    at (\LN.center) {$-$}
                                    },
                node contents={},
                on chain=A},
  arr/.style = {-{Triangle[angle=60:2pt 3]}, semithick},
every edge quotes/.style = {font=\footnotesize, inner sep=2pt}
                        ]
\coordinate[on chain=A] (in);                       % A-1
\node [sum];                                        % A-2
\node [block]   {$K_p + \mfrac{K_i}{s} + K_ds$};
\node [block]   {$G_p(s)$};                         
\coordinate[on chain=A] (out);                      % A-5
%
\draw[arr]  (in)    edge ["Set point"]  (A-2)
            (A-2)   edge ["$E(s)$"]     (A-3)
            (A-3)   edge ["$u(s)$"]     (A-4)
            (A-4)   edge ["Output"]     (out)
            ($(A-4.east)!0.5!(out)$) -- ++ (0,-11mm)
                    -| (A-2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

请注意,使用它\pgfextra来计算某些内容或为宏分配值(如这里所做的那样)是可以的。但使用它来构造路径甚至节点则不行。

答案2

path picture=可以向圆形节点添加所需的线条和符号:

\documentclass{article}
\usepackage{nccmath}

\usepackage{tikz}
\usetikzlibrary{arrows.meta,    % changed
                calc, chains,   % new
                positioning,    % new
                quotes          % new
                }
 \newcommand\ppbb{path picture bounding box} % new
\begin{document}
    \begin{tikzpicture}[auto,
  node distance = 6mm and 14mm,
    start chain = A going right,
block/.style = {draw,
                minimum height=11mm, minimum width=12mm,
                on chain=A},
  sgn/.style = {circle, minimum size=3mm, inner sep=0pt, #1},
  sum/.style = {circle, draw, minimum size=9mm, inner sep=0pt,
                path picture={    
                    \draw   (\ppbb.north west) -- (\ppbb.south east)
                            (\ppbb.south west) -- (\ppbb.north east);
                    \node[sgn=right] at (\ppbb.west)  {$+$};
                    \node[sgn=above] at (\ppbb.south) {$-$};
                             },
                node contents={},
                on chain=A},
  arr/.style = {-{Triangle[angle=60:2pt 3]}, semithick},
every edge quotes/.style = {font=\footnotesize, inner sep=2pt}
                        ]
\coordinate[on chain=A] (in);                       % A-1
\node [sum];                                        % A-2
\node [block]   {$K_p + \mfrac{K_i}{s} + K_ds$};
\node [block]   {$G_p(s)$};
\coordinate[on chain=A] (out);                      % A-5
%
\draw[arr]  (in)    edge ["Set point"]  (A-2)
            (A-2)   edge ["$E(s)$"]     (A-3)
            (A-3)   edge ["$u(s)$"]     (A-4)
            (A-4)   edge ["Output"]     (out)
            ($(A-4.east)!0.5!(out)$) -- ++ (0,-11mm)
                    -| (A-2);
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容