我在正确弯曲抓斗边缘时遇到了一些问题。
我想绘制一个流网络,到目前为止我已经完成了以下工作:
我希望从源节点 (S) 发出的边尽可能长时间停留在该节点的高度,直到它们弯曲到下层相应的节点。从顶视图看,边应该是一条直线。此外,它们应该垂直进入中间层的节点。
例如,考虑中间层最左边的节点:边缘没有到达北锚点处的节点,而是稍微向左移动。所以我想让边缘连接北锚点处的这些节点,箭头尖端垂直方向,显示在底部。
附件是用于生成该图表的代码。
\documentclass{article}
\usepackage{graphicx}
\usepackage{tikz}
\usetikzlibrary{shapes,fit,calc,positioning} %use shapes library if you need ellipse
\usetikzlibrary{arrows}
\usepackage[english]{babel} % The dictionary for hyphenation
\usepackage[utf8]{inputenc} % input-encoding
\usepackage[T1]{fontenc} % Schriftfamilie T1 ermöglicht Trennung und
% Suche von Wörtern mit Umlauten.
\definecolor{linkNode_color}{RGB}{60,60,60}
\definecolor{detNode_color}{RGB}{60,60,60}
\definecolor{sourceNode_color}{RGB}{60,60,60}
\newcommand{\myGlobalTransformation}[2]
{
\pgftransformcm{1}{0}{0.4}{0.5}{\pgfpoint{#1cm}{#2cm}}
}
% draw a 4x4 helper grid in 3D
% Input: point of origins x and y coordinate and additional drawing-parameters
\newcommand{\gridThreeD}[3]
{
\begin{scope}
\myGlobalTransformation{#1}{#2};
\draw [#3,step=1.5cm] grid (10.5,10.5);
\end{scope}
}
\begin{document}
\newlength{\sizeCircle}
\setlength{\sizeCircle}{0.2cm}
\def \NodeDistance{4}
\tikzstyle{linkNode}=[draw,circle,fill=linkNode_color,inner sep=0pt,minimum size=\sizeCircle]
\tikzstyle{detNode}=[draw,circle,fill=detNode_color,inner sep=0pt,minimum size=\sizeCircle]
\tikzstyle{sourceNode}=[draw,circle,fill=sourceNode_color,inner sep=0pt,minimum size=\sizeCircle]
\tikzstyle{linkEdge}=[->,>=stealth',black,thick]
\tikzstyle{sourceEdge}=[->,>=stealth',black,thick]
\tikzstyle{detEdge}=[->,>=stealth',black,thick]
\begin{tikzpicture}
\begin{scope}[scale=0.2]
\gridThreeD{0}{9}{black!50};
\gridThreeD{0}{-5}{black!50};
\begin{scope}
\myGlobalTransformation{0}{5}
\node[linkNode] (link_1_1) at (0,0) {};
\node[linkNode] (link_1_2) at (0,2) {};
\node[linkNode] (link_2_1) at (2*\NodeDistance,0) {};
\node[linkNode] (link_2_2) at (2*\NodeDistance,2) {};
\node[linkNode] (link_3_1) at (4*\NodeDistance,0) {};
\node[linkNode] (link_3_2) at (4*\NodeDistance,2) {};
\node[detNode] (det_1_1) at (1*\NodeDistance,0) {};
\node[detNode] (det_1_2) at (1*\NodeDistance,2) {};
\node[detNode] (det_2_1) at (3*\NodeDistance,0) {};
\node[detNode] (det_2_2) at (3*\NodeDistance,2) {};
\node[detNode] (det_3_1) at (5*\NodeDistance,0) {};
\node[detNode] (det_3_2) at (5*\NodeDistance,2) {};
\draw[linkEdge] (det_1_1) -- (link_2_1);
\draw[linkEdge] (det_1_1) -- (link_2_2);
\draw[linkEdge] (det_1_2) -- (link_2_1);
\draw[linkEdge] (det_1_2) -- (link_2_2);
\draw[linkEdge] (det_1_1) to[out=300, in=270, looseness=1] (link_3_1);
\draw[linkEdge] (det_1_2) to[out=120, in=120, looseness=1] (link_3_2);
\draw[linkEdge] (det_2_1) -- (link_3_1);
\draw[linkEdge] (det_2_2) -- (link_3_1);
\draw[linkEdge] (det_2_1) -- (link_3_2);
\draw[linkEdge] (det_2_2) -- (link_3_2);
\draw[detEdge] (link_1_1) -- (det_1_1);
\draw[detEdge] (link_1_2) -- (det_1_2);
\draw[detEdge] (link_2_2) -- (det_2_2);
\draw[detEdge] (link_3_1) -- (det_3_1);
\draw[detEdge] (link_3_2) -- (det_3_2);
\draw[detEdge] (link_2_1) -- (det_2_1);
\end{scope}
\begin{scope}
\myGlobalTransformation{0}{9}
\node[sourceNode] (source) at (4,4) {S};
\draw[sourceEdge] (source.west) to[out=180, in=120,looseness=2] (link_1_1);
\draw[sourceEdge] (source.west) to[out=180, in=120,looseness=2] (link_1_2);
\draw[sourceEdge] (source.south) to[out=180, in=120,looseness=1] (link_2_1);
\draw[sourceEdge] (source.south) to[out=180, in=120,looseness=1] (link_2_2);
\draw[sourceEdge] (source.east) to[out=0, in=110,looseness=1] (link_3_1.north);
\draw[sourceEdge] (source.east) to[out=0, in=110,looseness=1] (link_3_2.north);
\pgftransformreset
\end{scope}
\begin{scope}
\myGlobalTransformation{0}{-5}
\node[sourceNode] (sink) at (6,10) {T};
\draw[sourceEdge] (det_1_1.south) to[out=270, in=180,looseness=1] (sink.west);
\draw[sourceEdge] (det_1_2.south) to[out=270, in=180,looseness=1] (sink.west);
\draw[sourceEdge] (det_2_1.south) to[out=270, in=0,looseness=1] (sink.east);
\draw[sourceEdge] (det_2_2.south) to[out=270, in=0,looseness=1] (sink.east);
\draw[sourceEdge] (det_3_1.south) to[out=270, in=0,looseness=1] (sink.east);
\draw[sourceEdge] (det_3_2.south) to[out=270, in=0,looseness=1] (sink.east);
\end{scope}
\begin{scope}
\myGlobalTransformation{0}{5}
\node[linkNode] (link_1_1) at (0,0) {};
\node[linkNode] (link_1_2) at (0,2) {};
\node[linkNode] (link_2_1) at (2*\NodeDistance,0) {};
\node[linkNode] (link_2_2) at (2*\NodeDistance,2) {};
\node[linkNode] (link_3_1) at (4*\NodeDistance,0) {};
\node[linkNode] (link_3_2) at (4*\NodeDistance,2) {};
\node[detNode] (det_1_1) at (1*\NodeDistance,0) {};
\node[detNode] (det_1_2) at (1*\NodeDistance,2) {};
\node[detNode] (det_2_1) at (3*\NodeDistance,0) {};
\node[detNode] (det_2_2) at (3*\NodeDistance,2) {};
\node[detNode] (det_3_1) at (5*\NodeDistance,0) {};
\node[detNode] (det_3_2) at (5*\NodeDistance,2) {};
\end{scope}
\end{scope}
\end{tikzpicture}
\end{document}
答案1
可能是这样的?我基本上从头开始重新实现了大部分代码,主要是为了说明如何更紧凑地完成它:
\documentclass[tikz,border=5]{standalone}
\begin{document}
\begin{tikzpicture}[z=(240:.25cm), >=stealth,
every node/.style={circle, draw, fill=black!50, inner sep=.5ex}]
\foreach \x in {1,...,6}
\foreach \z in {1,2}
\node (node-\x-\z) at (\x,0,\z*2-3) {};
\foreach \i [evaluate={\j=int(\i+1);}] in {1,...,5}
\foreach \z in {1,2}
\draw [->] (node-\i-\z) -- (node-\j-\z);
\foreach \i/\j in {2/3, 4/5}{
\draw [->] (node-\i-1) -- (node-\j-2);
\draw [->] (node-\i-2) -- (node-\j-1);
}
\node at (2, 2,0) (S) {S}; \node at (4,-2,0) (T) {T};
\foreach \i/\out in {1/180,3/270,5/0}
\foreach \z in {1,2}
\draw [->] (S) to [out=\out,in=90] (node-\i-\z);
\foreach \i/\in in {2/180,4/90,6/0}
\foreach \z in {1,2}
\draw [->] (node-\i-\z) to [out=270,in=\in] (T);
\foreach \z in {1,2}
\draw [->] (node-2-\z) to [out=\z*180-135, in=\z*180-135, looseness=.5] (node-5-\z);
\end{tikzpicture}
\end{document}