框图中的节点和文本(Tikz)

框图中的节点和文本(Tikz)

我有以下框图

在此处输入图片描述 有人能帮我解决我图上红色标记的东西吗?

这是我当前的代码:

\usepackage{tikz}
\usepackage{float}
\usetikzlibrary{shapes,arrows}
\usetikzlibrary{arrows,calc,positioning}
\usetikzlibrary{fit,positioning,arrows}

\tikzset{
    block/.style = {draw, rectangle,
        minimum height=1cm,
        minimum width=2cm},
    input/.style = {coordinate,node distance=1cm},
    output/.style = {coordinate,node distance=6cm},
    arrow/.style={draw, -latex,node distance=2cm},
    pinstyle/.style = {pin edge={latex-, black,node distance=2cm}},
    sum/.style = {draw, circle, node distance=1cm},
}

 \begin{figure}[h]
    \centering
        \begin{center}
            \begin{tikzpicture}[auto, node distance=1cm,>=latex', scale=0.77, transform shape] 
            \node [input, name=input] {};
            \node [sum, right=of input, line width=0.25mm,] (sum) {};
            
            \node [draw=black,
            line width=0.25mm,
                    minimum width=2.5cm,
                    minimum height=1.4cm,
                     right=1.1cm of sum]  (controller){};
                     
            \node [draw=black,line width=0.25mm,
                    minimum width=2.5cm,
                    minimum height=1.4cm,
                    right=1.1cm of controller]  (plant2){};
                    
             \node [draw=black,line width=0.25mm,
                    minimum width=2.5cm,
                    minimum height=1.4cm,
                    right=1.1cm of plant2]  (plant){};
            
            \node [draw=black,line width=0.25mm,
                    minimum width=2.5cm,
                    minimum height=1.4cm,
                    above=1.1cm of plant]  (GP){};
                    

            \node [draw=black,
            line width=0.25mm,
                    minimum width=2.5cm,
                    minimum height=1.4cm,
                    right=1.1cm of plant]  (plant1){};                   
            \node [minimum width=2.5cm,
            line width=0.25mm,
                    minimum height=1.4cm, output, right=of plant] (output) {};
            \node at ($(controller)!0.9!(plant)+(0,-2.7)$) [block, line width=0.25mm] (feedback) {};
           
            \draw [draw,->, line width=0.25mm] (input) -- node {$\boldsymbol{r}$} (sum);
            \draw [->,line width=0.25mm] (sum) -- (controller);
            \draw [->,line width=0.25mm] (GP) -- (plant);
            \draw [->,line width=0.25mm] (controller) -- node {$\boldsymbol{v}$} (plant2);
             \draw [->,line width=0.25mm] (plant2) -- node {$\boldsymbol{v}$} (plant);
             \draw [->,line width=0.25mm] (GP) 
              -| ($ (GP.west)!0.6!(plant2.north) $) 
              -| node[pos=0, swap] {} (plant2);
            %\draw [->] (feedback) -- node {} (plant);
            
            \draw [->,line width=0.25mm] (feedback) 
              |- ($ (feedback.north)!.5!(plant.south) $) 
              -| node[pos=0, swap] {} (plant2);
            %\draw [->] (feedback) -- node {} (plant);
            \draw [->,line width=0.25mm] (plant) -- node {$\boldsymbol{u}$} (plant1);
            \draw [->,line width=0.25mm] (plant1) -- node [name=y] {$\boldsymbol{x}$}(output);
            \draw [->,line width=0.25mm] (y) |- (feedback) ;
            \draw [->,line width=0.25mm] (y) |- (GP) ;
            \draw [->,line width=0.25mm] (feedback) -| node[pos=0.99] {$-$} (sum);
            \end{tikzpicture}    
        \end{center}
    \end{figure}

答案1

\documentclass[border=3.141592]{standalone}
\usepackage{tikz}
\usetikzlibrary{arrows.meta,
                calc, chains,
                positioning,
                quotes}
\usepackage{bm}

\begin{document}
    \begin{tikzpicture}[
node distance = 11mm and 7mm,
  start chain = A going right,
   arr/.style = {-Stealth, semithick},
   box/.style = {draw, text width=22mm, minimum height=11mm, align=center},
   dot/.style = {circle, fill, inner sep=1.2pt, node contents={}},
   sum/.style = {circle, draw, minimum size=6mm, node contents={}},
every edge/.style = {draw, arr}
                        ]
   \begin{scope}[nodes={on chain=A}]
\coordinate (in);       % A-1
\node [sum];            % A-2
\node [box] {A-3};
\node [box] {A-4};
\node [box] {A-5};
\node [box] {A-6};
\node [dot];            % A-7
\coordinate (out);      % A-8
    \end{scope}
\node [box, above=of A-5] (A-9)   {A-9: o};
\node [box, below=of {$(A-4.south east)!0.5!(A-5.south west)$}] (A-10)  {A-10: f};
%
\path   (in)  edge ["$\bm{r}$"] (A-2)
        (A-2) edge                      (A-3)
        (A-3) edge ["$\bm{v}$"] (A-4)
        (A-4) edge ["$\bm{v}$"] (A-5)
        (A-5) edge ["$\bm{u}$"] (A-6)
        (A-6) edge [pos=0.25,"$\bm{x}$"] (out)                              % <--- red x label
       ([xshift=-2mm] A-9.south) edge ["$t$" '] ([xshift=-2mm] A-5.north)   % <--- red lines in your MWE
        (A-9) edge  (A-5)
        ([xshift=+2mm] A-9.south) edge ["$t$"]  ([xshift=+2mm] A-5.north)   % <--- red lines in your MWE
        ;
   \begin{scope}[every path/.style ={arr}]
\draw   (A-7)  |- (A-9);
\draw   (A-9)  -| node[pos=0.25,above] {$t$} (A-4);                         % <--- red lines from observer
\draw   (A-7)  |- (A-10);
\draw   (A-10) -| (A-2.south) node[pos=0.98,left] {$-$};
%
\draw   ([xshift=-2mm] A-10.north) -- ++ (0,5mm)
                                   -| (A-4);                                % <--- red lines from feedback
\draw   ([xshift=+2mm] A-10.north) -- ++ (0,5mm)
                                   -| (A-5);                                % <--- red lines from feedback
    \end{scope}
    \end{tikzpicture}
\end{document}

在此处输入图片描述

编辑: 添加了t红线处的变量和代码注释,用于定义草图中的红线。

在提出的解决方案中,我执行以下编辑步骤(我在您编辑问题之前编写的代码)

  • 在所有节点上使用已定义的样式box,即block在您的代码中,然后删除所有节点样式的本地定义。这样,代码变得更短更清晰。除此之外,图像现在具有统一的节点样式(可能影响此决定的节点的实际内容仍然未知)
  • 由于除观察者外的节点(顶部节点是否存在?)都在链中,因此对于它们的位置,我建议使用chains库,通过这种方式消除重复right=of <node name>,使代码更短
  • 因为链被命名为A,所以其中的节点编号为A-1A-2等等。这样可以删除绘制箭头所需的节点名称,但是,您仍然可以按照原样为它们命名(例如,我保留了第一个和最后一个节点的名称(现在由coordinates 替换)。
  • 在节点之间绘制箭头时,我更喜欢使用边引号。代码稍微短一点,但需要quotes在文档序言中添加库
  • 节点之间箭头的书写方式使用边。它们的样式也在选项中定义tikzpicture。使用它,绘制箭头的代码进一步缩短。

就这些。

从两个 MWE 的比较中应该可以明显看出 MWE 的变化。是的,在编辑代码片段时做了很多更改。如果在阅读这些描述后仍有不清楚的地方,请随时要求解释。

更改,在图片中添加红线,现在用% <--- <description>

还修正了提出的 MWE,现在包含变量,您也可以在红色箭头处写上这些变量。

编辑(2): 添加丢失的带有标签的输出箭头x,标签uv被移动到与草图中相同的位置,以及is replaced with在同名包中定义的 \boldsymbol \bm`。

在方框中添加了它们的名称。这可以帮助您识别箭头的坐标。

可能发生的情况是,MWE 中仍然存在一些错误,例如错误的标签(请注意,您有两个v在我看来是错误的标签),现在应该能够自行纠正 ;-)

相关内容