未找到 TikZ 交叉点

未找到 TikZ 交叉点

我遇到了以下问题:使用“plot”构建路径时,我无法找到完全落在用于构建该路径的坐标上的交点。在下面的示例中,只有当我移动矩形以使其在 x=4 之前或之后与 plot 路径相交时,才会找到第二个交点。

在我看来,这有点像“情节”路径实际上不是单一路径,而是连接在一起的段,并且在线段连接的点处找不到交点。

这是有意为之吗,或者可能是一个错误?

\documentclass{standalone}

\usepackage{tikz}
\usetikzlibrary{shapes,intersections,scopes,calc,positioning}

\begin{document}
\begin{tikzpicture}[scale=1, transform shape]
    \tikzstyle{dot}=[fill=blue,circle,inner sep=.3ex]
    \draw[name path=b,yellow] (2cm,-.5cm) rectangle (4.0cm,2); %3.9cm works 
        \draw [name path=p, blue, thick]
            plot [smooth] coordinates { (0,0) (1,.1) (2,1) (3,1) (4,0.1) (5,0) };
        \path [name intersections={of=b and p}]
            (intersection-1) node[dot] {}
            (intersection-2) node[dot] {};           
\end{tikzpicture} 
\end{document}

答案1

有趣的是!只需省略坐标中的单位,即:而不是(4.0cm,2)使用(4.0,2)或更短的(4,2),您的代码就会按预期工作:

\documentclass[margin=3mm]{standalone}
\usepackage{tikz}
\usetikzlibrary{shapes,intersections,scopes,calc,positioning}

\begin{document}
\begin{tikzpicture}[scale=1, transform shape]
    \tikzstyle{dot}=[fill=blue,circle,inner sep=.3ex]
    \draw[name path=b,yellow] (2cm,-.5cm) rectangle (4,2);
        \draw [name path=p, blue, thick]
            plot [smooth] coordinates { (0,0) (1,.1) (2,1) (3,1) (4,0.1) (5,0) };
        \path [name intersections={of=b and p}]
            (intersection-1) node[dot] {}
            (intersection-2) node[dot] {};
\end{tikzpicture}
\end{document}

在此处输入图片描述

相关内容