Tikz 曲线边缘路径

Tikz 曲线边缘路径

我正在使用 beamer 进行演示,并希望使用边连接图形的顶点。我可以使用以下代码来实现这一点。

\documentclass[xcolor=pdftex,dvipsnames,table]{beamer}
\usepackage{array}
\usepackage{amsthm,amsmath,amssymb}
\usepackage{multirow}
\usepackage{multicol}
\usepackage{url}
\usepackage{tikz}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}

\begin{document}

\begin{frame}{Graph Theory}
\begin{tikzpicture}

\node[draw,circle,fill] (1) at (0,3.163) {};
\node[draw,circle,fill] (2) at (1.565,1.918) {};
\node[draw,circle,fill] (3) at (1,0) {};
\node[draw,circle,fill] (4) at (-1,0) {};
\node[draw,circle,fill] (5) at (-1.565,1.918) {};
\node[draw,circle,fill] (6) at (6,2.382) {};
\node[draw,circle,fill] (7) at (7,.65) {};
\node[draw,circle,fill] (8) at (5,.65) {};
\node [above=.25cm] at (1) {1};
\node [right=.25cm] at (2) {2};
\node [below right=.2cm] at (3) {3};
\node [below left=.2cm] at (4) {4};
\node [left=.25cm] at (5) {5};
\node [above=.25cm] at (6) {1};
\node [above right=.2cm] at (7) {2,3};
\node [above left=.2cm] at (8) {4,5};

\begin{pgfonlayer}{background}
\draw[blue, ultra thick] (1) -- (2) -- (3) -- (4) -- (5) -- (1);
\draw[red, ultra thick] (1) -- (3) -- (5) -- (2) -- (4) -- (1);
\draw[blue, ultra thick] (6) -- (7) -- (8) -- (6);
\draw[blue, ultra thick] (8) arc [radius=.4cm, start angle=20, end angle=380];
\draw[blue, ultra thick] (7) arc [radius=.4cm, start angle=160, end angle= 520];
\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6);
\draw[red, ultra thick] (6) to [out=330,in=95,distance=.6cm] (7);
\draw[red, ultra thick] (7) to [out=155,in=25,distance=.55cm] (8);
\draw[red, ultra thick] (8) to [out=335,in=205,distance=.55cm] (7);
\draw[red, ultra thick] (7) to [out=230,in=310,distance=.675cm] (8);
\end{pgfonlayer}

\end{tikzpicture}
\end{frame}

然而,三角形与下面使用的更易于使用的代码有很大不同

\begin{frame}{Graph Theory}
\begin{tikzpicture}

\node[draw,circle,fill] (1) at (0,3.163) {};
\node[draw,circle,fill] (2) at (1.565,1.918) {};
\node[draw,circle,fill] (3) at (1,0) {};
\node[draw,circle,fill] (4) at (-1,0) {};
\node[draw,circle,fill] (5) at (-1.565,1.918) {};
\node[draw,circle,fill] (6) at (6,2.382) {};
\node[draw,circle,fill] (7) at (7,.65) {};
\node[draw,circle,fill] (8) at (5,.65) {};
\node [above=.25cm] at (1) {1};
\node [right=.25cm] at (2) {2};
\node [below right=.2cm] at (3) {3};
\node [below left=.2cm] at (4) {4};
\node [left=.25cm] at (5) {5};
\node [above=.25cm] at (6) {1};
\node [above right=.2cm] at (7) {2,3};
\node [above left=.2cm] at (8) {4,5};

\begin{pgfonlayer}{background}
\draw[blue, ultra thick] (1) -- (2) -- (3) -- (4) -- (5) -- (1);
\draw[red, ultra thick] (1) -- (3) -- (5) -- (2) -- (4) -- (1);
\draw[blue, ultra thick] (6) -- (7) -- (8) -- (6);
\draw[blue, ultra thick] (8) arc [radius=.4cm, start angle=20, end angle=380];
\draw[blue, ultra thick] (7) arc [radius=.4cm, start angle=160, end angle= 520];
\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6) to [out=330,in=95,distance=.6cm] (7) to [out=155,in=25,distance=.55cm] (8) to [out=335,in=205,distance=.55cm] (7) to [out=230,in=310,distance=.675cm] (8);
\end{pgfonlayer}

\end{tikzpicture}
\end{frame}

似乎将命令链接在一起会创建一条从边缘结束位置(而不是从节点)开始的路径。除了像我在上一个代码中那样单独定义每个命令之外,还有其他方法可以解决这个问题吗?

答案1

你的命令是

\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6) 
     to [out=330,in=95,distance=.6cm] (7) 
     to [out=155,in=25,distance=.55cm] (8) 
     to [out=335,in=205,distance=.55cm] (7) 
     to [out=230,in=310,distance=.675cm] (8);

它不使用edge。这是一条常规路径,因此新段从上一个段结束的位置开始。它们在节点的边界处结束,因为您的黑色圆圈是节点。

您仍然可以使用这个较短的解决方案,只需再次修复您希望新段开始的位置:

\draw[red, ultra thick] (8) to [out=85,in=210,distance=.6cm] (6) 
     (6) to [out=330,in=95,distance=.6cm] (7) 
     (7) to [out=155,in=25,distance=.55cm] (8) 
     (8) to [out=335,in=205,distance=.55cm] (7) 
     (7) to [out=230,in=310,distance=.675cm] (8);

或者更短,重新排序并使用edges

\draw[red, ultra thick] 
    (8) edge [out=85,in=210,distance=.6cm] (6) 
        edge [out=335,in=205,distance=.55cm] (7) 
    (6) edge [out=330,in=95,distance=.6cm] (7) 
    (7) edge [out=155,in=25,distance=.55cm] (8) 
        edge [out=230,in=310,distance=.675cm] (8);

相关内容