![绘制类似这样的控制流图的最简单方法是什么?](https://linux22.com/image/388692/%E7%BB%98%E5%88%B6%E7%B1%BB%E4%BC%BC%E8%BF%99%E6%A0%B7%E7%9A%84%E6%8E%A7%E5%88%B6%E6%B5%81%E5%9B%BE%E7%9A%84%E6%9C%80%E7%AE%80%E5%8D%95%E6%96%B9%E6%B3%95%E6%98%AF%E4%BB%80%E4%B9%88%EF%BC%9F.png)
答案1
现在有文本。
\documentclass[tikz,border=3.14mm]{standalone}
\usetikzlibrary{chains,shadows.blur}
\begin{document}
\begin{tikzpicture}[auto,
node distance = 12mm,
start chain = going below,
box/.style = {draw,rounded corners,blur shadow,fill=white,
on chain,align=center}]
\node[box] (b1) {$x_1\leftarrow0$\\ $y_1\leftarrow0$};
\node[box] (b2) {$x_2\leftarrow\phi(x_1,x_3)$\\
$y_2\leftarrow\phi(y_1,y_3)$\\
$(x_2<10)$?};
\node[box] (b3) {$y_3\leftarrow y_2+x_2$\\ $x_3\leftarrow x_2+1$};
\node[box] (b4) {print($y_2$)};
\begin{scope}[rounded corners,-latex]
\path (b2.-40) edge[bend left=50] (b4.40)
(b1) edge (b2) (b2) edge (b3);
\draw (b3.230) -- ++(0,-0.3) -| ([xshift=-5mm]b2.west) |-
([yshift=3mm]b2.130) -- (b2.130);
\end{scope}
\end{tikzpicture}
\end{document}
我认为可以说基础知识并不太难学。每个人都遇到的问题是 pgfmanual 有 1000 多页,所以任何答案都可以以无数种不同的方式重复。在这里,您可以选择另一种方式来弯曲路径,可以使用节点矩阵和许多其他东西。您的问题是关于“绘制类似这样的控制流图的最简单方法?”。我不是声称这是最简单的方法,但它A可能的方式,在我看来,这相当简单。
答案2
一个简单的pstricks
解决方案:
\documentclass[svgnames, border=12pt]{standalone}
\usepackage[utf8]{inputenc}
\usepackage{lmodern}
\usepackage[T1]{fontenc}
\usepackage{amsmath}
\usepackage{pst-node, pst-blur}
\usepackage{auto-pst-pdf}
\newcommand{\shadowframe}[1]{\psframebox[shadow, blur]{\enspace #1\enspace }}
\begin{document}
\psset{framearc=0.2, shadowcolor=DarkGray, shadowangle=-60}
\begin{psmatrix}[colsep =1cm, rowsep=1.2cm]
&[name=A] \shadowframe{$\begin{aligned}
x_1 & \leftarrow 0 \\ y_1 & \leftarrow 0
\end{aligned}$}\\
& [name=B] \shadowframe{$\begin{gathered}
\begin{aligned}
x_2 & \leftarrow \phi(x_1,x_3)\\ y_2 & \leftarrow \phi(y_1,y_3)
\end{aligned}\\
x_2 < 10\,?
\end{gathered}$}\\
\pnode{I} & [name=C] \shadowframe{$\begin{aligned}
y_3 & \leftarrow y_2 + x_2 \\ x_3 & \leftarrow x_2 + 1
\end{aligned}$}\\
& [name=D] \shadowframe{\makebox[5.75em][l]{print($y_2$)}}
%%% Links
\psset{arrows=->, arrowinset=0.12, linejoin=1, linearc=0.25}%, nodesep=4pt
\ncline{A}{B}
\ncline{B}{C}
\ncbar[arrows=-, angleA=-90,armA=1.2em, offsetA = -2em, angleB=90]{C}{I}%
\ncbar[angleA=90, angleB=90 , offsetB = -2em, armB=1.5em]{I}{B}%
\ncarc[arcangleA=50, arcangleB=60]{B}{D}% offsetB=2em,offset=1em,
\end{psmatrix}
\end{document}