是否可以向贝塞尔曲线的控制点添加偏移量,以使我的红线穿过点云的中心?这是我的 mwe:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\usetikzlibrary{trees}
\usetikzlibrary{arrows,automata}
\usepackage{epstopdf}
\definecolor{mycolor}{RGB}{8,108,131}
\usepackage{array}
\usepackage{adjustbox}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[
scale=0.8,
transform shape,
show background rectangle,
background rectangle/.style={fill=gray!10},
box/.style={draw, font=\itshape}
]
\coordinate (b) at (current page.center);
\node [
label=right:XXX,
] (firewall)at(b) {\includegraphics[width=9mm]{example-image-a}};
\node [
label=above:XXX
] (client) at ([yshift=2cm]firewall){\includegraphics[width=9mm]{example-image-a}};
\node [
label=XXX
] (dnsServer) at([xshift=-5cm]firewall){\includegraphics[width=9mm]{example-image-a}};
\node [
label=center:XXX,
] (cloud) at ([yshift=-2cm]firewall){\includegraphics[width=9mm]{example-image-b}};
\node [
label=below:XXX
] (server1) at([xshift=5cm]cloud){\includegraphics[width=9mm]{example-image-a}};
\node [
label=right:XXX
] (server2) at([xshift=5cm]server1){\includegraphics[width=9mm]{example-image-a}};
\draw [thick,mycolor,->](client) .. controls (firewall) .. (dnsServer)node[very near start, left]{1};
\draw [thick,mycolor,->](dnsServer) .. controls (firewall)and (cloud) .. (server1)node[very near end, left]{2};
\draw [thick,mycolor,<->](server1)--(server2)node[midway,above]{3 et 4};
\draw [thick,mycolor,->](server1) .. controls (cloud) and (firewall).. (client)node[very near start, right]{5};
\draw [thick,red,->](client) .. controls (firewall) and (cloud).. (server1)node[]{};
\path[mycolor,->] (client) edge [loop right] node {6} ();
\end{tikzpicture}
\end{document}
答案1
这是否接近您的要求:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\usetikzlibrary{trees}
\usetikzlibrary{arrows,automata}
\usepackage{epstopdf}
\definecolor{mycolor}{RGB}{8,108,131}
\usepackage{array}
\usepackage{adjustbox}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[
scale=0.8,
transform shape,
show background rectangle,
background rectangle/.style={fill=gray!10},
box/.style={draw, font=\itshape}
]
\coordinate (b) at (current page.center);
\node [
label=right:XXX,
] (firewall)at(b) {\includegraphics[width=9mm]{example-image-a}};
\node [
label=above:XXX
] (client) at ([yshift=2cm]firewall){\includegraphics[width=9mm]{example-image-a}};
\node [
label=XXX
] (dnsServer) at([xshift=-5cm]firewall){\includegraphics[width=9mm]{example-image-a}};
\node [
%label=center:XXX,
] (cloud) at ([yshift=-2cm]firewall){\includegraphics[width=9mm]{example-image-b}};
\node [
label=below:XXX
] (server1) at([xshift=5cm]cloud){\includegraphics[width=9mm]{example-image-a}};
\node [
label=right:XXX
] (server2) at([xshift=5cm]server1){\includegraphics[width=9mm]{example-image-a}};
\draw [thick,mycolor,->](client) .. controls (firewall) .. (dnsServer)node[very near start, left]{1};
\draw [thick,mycolor,->](dnsServer) .. controls (firewall)and (cloud) .. (server1)node[very near end, left]{2};
\draw [thick,mycolor,<->](server1)--(server2)node[midway,above]{3 et 4};
\draw [thick,mycolor,->](server1) .. controls (cloud) and (firewall).. (client)node[very near start, right]{5};
\draw [thick,red,->](client) .. controls ([yshift=-2.5cm]firewall) and ([xshift=-1cm]cloud).. (server1)node[]{};
\path[mycolor,->] (client) edge [loop right] node {6} ();
\end{tikzpicture}
\end{document}
答案2
而@Hafid Boukhoulda 给出了灵活,通用方法进行偏移,将两个控制点设置为同一点(cloud)
使得 Beizer 曲线看起来流畅、简洁、美观——因此如果它满足您的要求,那么可能是另一个值得考虑的选择。
...我使用的代码是:
\documentclass{article}
\usepackage{xcolor}
\usepackage{tikz}
\usetikzlibrary{chains}
\usetikzlibrary{positioning}
\usetikzlibrary{backgrounds}
\usetikzlibrary{trees}
\usetikzlibrary{arrows,automata}
\usepackage{epstopdf}
\definecolor{mycolor}{RGB}{8,108,131}
\usepackage{array}
\usepackage{adjustbox}
\usetikzlibrary{shapes}
\begin{document}
\begin{tikzpicture}[
scale=0.8,
transform shape,
show background rectangle,
background rectangle/.style={fill=gray!10},
box/.style={draw, font=\itshape}
]
\coordinate (b) at (current page.center);
\node [label=right:XXX]
(firewall)at(b) {\includegraphics[width=9mm]{example-image-a}};
\node [label=above:XXX]
(client) at ([yshift=2cm]firewall){\includegraphics[width=9mm]{example-image-a}};
\node [label=XXX]
(dnsServer) at([xshift=-5cm]firewall){\includegraphics[width=9mm]{example-image-a}};
\node [label=center:{}]
(cloud) at ([yshift=-2cm]firewall){\includegraphics[width=9mm]{example-image-b}};
\node [label=below:XXX]
(server1) at([xshift=5cm]cloud){\includegraphics[width=9mm]{example-image-a}};
\node [label=right:XXX]
(server2) at([xshift=5cm]server1){\includegraphics[width=9mm]{example-image-a}};
\draw [thick,mycolor,->](client) .. controls (firewall) .. (dnsServer)node[very near start, left]{1};
\draw [thick,mycolor,->](dnsServer) .. controls (firewall)and (cloud) .. (server1)node[very near end, left]{2};
\draw [thick,mycolor,<->](server1)--(server2)node[midway,above]{3 et 4};
\draw [thick,mycolor,->](server1) .. controls (cloud) and (firewall).. (client)node[very near start, right]{5};
\draw [thick,red,->](client) .. controls (cloud) .. (server1)node[]{};
% only one control (cloud) instead of two
\path[mycolor,->] (client) edge [loop right] node {6} ();
\end{tikzpicture}
\end{document}