![TikZ 的结库未找到所有交叉点](https://linux22.com/image/441578/TikZ%20%E7%9A%84%E7%BB%93%E5%BA%93%E6%9C%AA%E6%89%BE%E5%88%B0%E6%89%80%E6%9C%89%E4%BA%A4%E5%8F%89%E7%82%B9.png)
当我试图回答这个问题,我观察到 Ti 的奇怪行为钾Z 的knots
图书馆。或者也许这根本不奇怪,只是我忽略了一些东西……
看看这个代码:
\documentclass[tikz, border=0mm]{standalone}
\usetikzlibrary{knots, decorations.markings}
\begin{document}
\begin{tikzpicture}[
arrowmark/.style={draw=red, only when rendering/.style={postaction=decorate}}
]
\begin{knot}[
clip width=3,
]
%\strand (0,0) ellipse (20pt and 10pt); <-- uncomment for second image
\strand (0:20pt) arc (0:180:20pt and 10pt) arc (180:0:20pt and -10pt) -- cycle; <-- comment out for second image
\strand (0:1cm+20pt) arc (0:180:20pt and 20pt) arc (180:0:20pt and -20pt) -- cycle;
\strand[arrowmark, decoration={markings, mark=at position 0.5 with {\arrow{>}}}] (1,-1.5) .. controls (1.8,0.2) and (0.2,0.2) .. (1,-1.5);
\strand[arrowmark, decoration={markings, mark=at position 0.45 with {\arrow{>}}}] (1,-1.5) to[out=180, in=0] (-.5,0) .. controls (-1.25,0) and (-.75,-1.5) .. (1,-1.5);
%\flipcrossings{1,2,5} <-- uncomment for second image
\flipcrossings{1,4,6} <-- comment out for second image
\end{knot}
\filldraw [red] (1,-1.5) circle (1pt);
\end{tikzpicture}
\end{document}
它呈现的效果很好,如下所示:
现在取消注释两行注释,并注释掉以下两行(如上面的代码所示),那么您(或者至少我)将得到(当然没有黄色突出显示):
可以清楚地看到,最右边的红色卷曲与椭圆的交点不是我所期望的。当我最初使用两个椭圆时,我遇到了同样的问题。我最初认为使用ellipse
可能会导致这种情况。如果我添加选项draft mode=crossings
,则相关交点似乎根本无法识别。我无法在相关文件。
实际上一个很好的答案上述链接问题的答案也使用了相同的方法。它似乎适用于两个椭圆和两条开放路径。这里有什么区别?
答案1
我自己找到了答案。万一有人遇到类似的问题,我仍然会在这里发布它。
库可能会忽略某些交叉点的原因knots
显然是它们太靠近路径的端点。可以使用选项来纠正这个问题end tolerance
。
在这种情况下,这个公差应该非常低,因为相关交点与椭圆的终点和起点(位于路径的最底部)之间的距离恰好几乎位于同一坐标。
\documentclass[tikz, border=0mm]{standalone}
\usetikzlibrary{knots, decorations.markings}
\begin{document}
\begin{tikzpicture}[
arrowmark/.style={draw=red, only when rendering/.style={postaction=decorate}}
]
\begin{knot}[
draft mode=crossings,
end tolerance=1pt,
clip width=3,
]
\strand (0,0) ellipse (20pt and 10pt);
%\strand (0:20pt) arc (0:180:20pt and 10pt) arc (180:0:20pt and -10pt) -- cycle; <
\strand (0:1cm+20pt) arc (0:180:20pt and 20pt) arc (180:0:20pt and -20pt) -- cycle;
\strand[arrowmark, decoration={markings, mark=at position 0.5 with {\arrow{>}}}] (1,-1.5) .. controls (1.8,0.2) and (0.2,0.2) .. (1,-1.5);
\strand[arrowmark, decoration={markings, mark=at position 0.45 with {\arrow{>}}}] (1,-1.5) to[out=180, in=0] (-.5,0) .. controls (-1.25,0) and (-.75,-1.5) .. (1,-1.5);
\flipcrossings{1,4,6}
\end{knot}
\filldraw [red] (1,-1.5) circle (1pt);
\end{tikzpicture}
\end{document}