如何绘制连接图像上点的 tikz 平滑路径?

如何绘制连接图像上点的 tikz 平滑路径?

我想绘制一条连接下图中点的“特定”平滑路径数字

要得到这

我所能做的就是把要点放在正确的地方。这是我的 MWE

\documentclass[tikz]{standalone} 
\begin{document} 
\begin{tikzpicture} 
\node[anchor=south west,inner sep=0] 
at (-3,-2) {\includegraphics[width=\textwidth]{euler.png}};  
\draw [fill=blue] (1.2,1.2) circle (3pt);%A
\draw [fill=blue] (1,-1.9) circle (3pt);%B
\draw [fill=blue] (1.5,4) circle (3pt);%C
\draw [fill=blue] (6.2,.9) circle (3pt); 
\end{tikzpicture}
\end{document} 

答案1

我建议给桥梁起坐标名。然后你可以使用命令

\draw (x) to[out=<angle>,in=<angle>] (y);

这样小路就可以越过桥梁。

在此处输入图片描述

我画了红色圆圈来表示桥梁坐标,但你当然可以通过删除\fill[red]...命令来移除它们。我还为你的蓝色圆圈赋予了坐标名称,以便于调整。

以下是代码:

\documentclass[tikz]{standalone} 
\begin{document} 
\begin{tikzpicture} 
\node[anchor=south west,inner sep=0] 
at (-3,-2) {\includegraphics[width=\textwidth]{mOizq.png}};  
\coordinate (a) at (-.25,-.35);
\coordinate (b) at (2.6,-.92);
\coordinate (c) at (.32,2.82);
\coordinate (d) at (3.05,2.75);
\coordinate (e) at (4.3,.88);
\coordinate (f) at (5.3,-.27);
\coordinate (g) at (5.7,2.1);
\coordinate (A) at (1.2,1.2);
\coordinate (B) at (1,-1.9);
\coordinate (C) at (1.5,4);
\coordinate (D) at (6.2,.9);
\fill[red] (a) circle(2pt);
\fill[red] (b) circle(2pt);
\fill[red] (c) circle(2pt);
\fill[red] (d) circle(2pt);
\fill[red] (e) circle(2pt);
\fill[red] (f) circle(2pt);
\fill[red] (g) circle(2pt);
\draw [fill=blue] (A) circle (3pt);
\draw [fill=blue] (B) circle (3pt);
\draw [fill=blue] (C) circle (3pt);
\draw [fill=blue] (D) circle (3pt);
\begin{scope}[line width=1, blue];
\draw (A) to[out=-135,in=60] (a) to[out=-120,in=180] (B) to[out=0,in=-90] (b) to[out=90,in=180] (e) to[out=0,in=180] (D) to[out=-135,in=75] (f) to[out=-115,in=0] (B);
\draw (A) to[out=135,in=-115] (c) to[out=75,in=180] (C) to[out=0,in=60] (d) to[out=-120,in=180] (e) to[out=180,in=0] (A);
\draw (C) to[out=0,in=115] (g) to[out=-75,in=135] (D);
\end{scope}
\end{tikzpicture}
\end{document} 

答案2

下面是使用该hobby包的一个例子,该包可以通过某些给定点绘制平滑曲线。

在此处输入图片描述

我定义了一些中间点(A')(A'')(D')(D'')它们有助于在通过直线连接的两个点附近形成形状。您可以调整这些点以获得所需的形状。

代码:

\documentclass[border=2pt]{standalone}

\usepackage{tikz}
\usetikzlibrary{hobby}
 
\begin{document} 
\begin{tikzpicture} 
%\node[anchor=south west,inner sep=0] 
%at (-3,-2) {\includegraphics[width=\textwidth]{euler.png}};  

\coordinate (A) at (1.2,1.2);
\coordinate (A')  at ([shift={(-0.5,  0.5)}]A);
\coordinate (A'') at ([shift={(-0.5, -0.5)}]A);

\coordinate (B) at (1,-1.9);
\coordinate (C) at (1.5,4);

\coordinate (D) at (6.2,.9);
\coordinate (D')  at ([shift={(-0.5,  1.0)}]D);
\coordinate (D'') at ([shift={(-0.5, -1.0)}]D);

\draw [fill=blue] (A) circle (3pt) node [above right] {A};
\draw [fill=blue] (B) circle (3pt) node [below left]  {B};
\draw [fill=blue] (C) circle (3pt) node [above left]  {C};
\draw [fill=blue] (D) circle (3pt) node [right]       {D}; 

\draw [red, thick] (D) -- (A)
    to [curve through={(A') (C) (D')}]
    (D);
    
\draw [red, thick] (D) -- (A)
    to [curve through={(A'') (B) (D'')}]
    (D);
\end{tikzpicture}
\end{document} 

答案3

在...的帮助下Peter Grill 的回答,我得出以下结论。 在此处输入图片描述

\documentclass[tikz]{standalone}
\usetikzlibrary{hobby}
\begin{document} 
\begin{tikzpicture}
\node[anchor=south west,inner sep=0] at (-3,-2) {\includegraphics[width=\textwidth]{euler.png}};

\coordinate (A) at (1.5,1.3);
\coordinate (A')  at (.2,3);
\coordinate (A'') at (-.2,-0.5);
\coordinate (B) at (1,-1.9);
\coordinate (C) at (1.8,4);
\coordinate (D) at (6.2,.9);
\coordinate (D')  at ([shift={(-0.5,  1.0)}]D);
\coordinate (D'') at ([shift={(-0.5, -1.0)}]D);  
\coordinate (c'') at (3.1,3);
\coordinate (b'') at (2.5,-0.9); 
\draw [fill=blue] (A) circle (3pt) node [above right] {};%{A}; 
\draw [fill=blue] (B) circle (3pt) node [below left]  {};% {B};
\draw [fill=blue] (C) circle (3pt) node [above left]  {};% {C};
\draw [fill=blue] (D) circle (3pt) node [right]       {};% {D};
\draw [blue, thick] (D) -- (A) to [curve through={(A') (C) (D')}] (D);
\draw [blue, thick] (D) -- (A) to [curve through={(A'') (B) (D'')}] (D);
\draw [blue, thick] (A) to [curve through={(b'')}] (B);
\draw [blue, thick] (A) to [curve through={(c'')}] (C);
\end{tikzpicture}
\end{document} 

我不知道这是否可以得到改善。

相关内容