如何在 TikZ 中通过给定点绘制平滑的螺旋曲线?

如何在 TikZ 中通过给定点绘制平滑的螺旋曲线?

我正在尝试在 TikZ 中重现下图(这是 8 字结的结图,但这并不重要):

一对嵌套的螺旋曲线。

它由两个嵌套的螺旋线和两个水平段组成。螺旋线最好是平滑的,但如果它们在与水平段的交点处“扭曲”也是可以的,唯一的限制是两个螺旋线不相交。

我曾尝试使用\draw plot [smooth] ...前面的问题中描述的方法TikZ 中的简单曲线

  \begin{tikzpicture}
    \node(L0) at (-1.5,0) {};
    \node(L1) at (-2.5,0) {};
    \node(L2) at (-3.5,0) {};
    \node(L3) at (-4.5,0) {};
    \node(L4) at (-5.5,0) {};
    \node(L5) at (-6.5,0) {};
    \node(L6) at (-7.5,0) {};
    \node(R0) at (1.5,0)  {};
    \node(R1) at (2.5,0)  {};
    \node(R2) at (3.5,0)  {};
    \node(R3) at (4.5,0)  {};
    \node(R4) at (5.5,0)  {};
    \node(R5) at (6.5,0)  {};
    \node(R6) at (7.5,0)  {};
    \node(ML) at (-0.5,0) {};
    \node(MR) at (0.5,0) {};

    \draw plot [smooth, tension=2] coordinates {(L0) (R3) (L6) (L4) (R1) (MR) (L2) (R5)};
    \draw plot [smooth, tension=2] coordinates {(L5) (R2) (L1) (ML) (R4) (R6) (L3) (R0)};
    \draw (L0)--(L5);
    \draw (R0)--(R5);
  \end{tikzpicture}

但这只会产生一条直线(从我对 TikZ 使用的算法的有限理解来看,这是因为任何点的曲线切线都是连接前一个点和后一个点的线,并且我的图中的所有点都是共线的)。

我也尝试过使用兴趣爱好图书馆,但没有成功,结果非常混乱:

兴趣图书馆的成果

(这是通过将\draw上面的两行替换为

    \draw (L0) to[quick curve through={(R3) (L6) (L4) (R1) (MR) (L2)}] (R5);
    \draw (L5) to[quick curve through={(R2) (L1) (ML) (R4) (R6) (L3)}] (R0);

也许可以通过在爱好包中选择正确的选项来解决这个问题。)

问题。有没有办法通过仅指定曲线按顺序经过的点来重现上图所示的“嵌套螺旋”图?如果没有,在 TikZ 中重现该图的最简单方法是什么?

答案1

感谢 Crazymoomin 在评论中的建议,我尝试了库并给出更好的结果:

  \begin{tikzpicture}
  \node[draw=none](L0) at (-1.5,0) {};
  \node[draw=none](L1) at (-2.5,0) {};
  \node[draw=none](L2) at (-3.5,0) {};
  \node[draw=none](L3) at (-4.5,0) {};
  \node[draw=none](L4) at (-5.5,0) {};
  \node[draw=none](L5) at (-6.5,0) {};
  \node[draw=none](L6) at (-7.5,0) {};
  \node[draw=none](R0) at (1.5,0)  {};
  \node[draw=none](R1) at (2.5,0)  {};
  \node[draw=none](R2) at (3.5,0)  {};
  \node[draw=none](R3) at (4.5,0)  {};
  \node[draw=none](R4) at (5.5,0)  {};
  \node[draw=none](R5) at (6.5,0)  {};
  \node[draw=none](R6) at (7.5,0)  {};
  \node[draw=none](ML) at (-0.5,0) {};
  \node[draw=none](MR) at (0.5,0) {};
  \begin{knot}
    \strand [thick] (L0)
      to[out=north,in=north] (R3)
      to[out=south,in=south] (L6)
      to[out=north,in=north] (L4)
      to[out=south,in=south] (R1)
      to[out=north, in=north] (MR)
      to[out=south,in=south] (L2)
      to[out=north, in=north] (R5);

    \strand [thick] (L5)
      to[out=south,in=south] (R2)
      to[out=north,in=north] (ML)
      to[out=south,in=south] (L1)
      to[out=north,in=north] (R4)
      to[out=south, in=south] (R6)
      to[out=north,in=north] (L3)
      to[out=south, in=south] (R0);

    \strand[thick] (L0) to (L5);
    \strand[thick] (R0) to (R5);
  \end{knot}
  \end{tikzpicture}

在此处输入图片描述

当然,我需要移除下跨/上跨,但这不是问题。

相关内容