为什么我的 TikZ 交叉点不精确?

为什么我的 TikZ 交叉点不精确?

在 TikZ 图片中,我尝试将圆弧与三次贝塞尔线相交。但是,计算出的交点似乎不对 — 你知道这是为什么吗?这是一种舍入误差吗?

放大交叉口

\documentclass{article}
\usepackage{tikz}
\usepackage[graphics, active, tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[
    detector/.style={line width=0.5pt, color=gray, line cap=round},
    track/.style={line width=0.9pt, color=black, -{Latex[length=2mm]}},
    seed track/.style={track, color=blue},
    red dot/.style={red, opacity=0.3}
]

\draw[detector, name path=L1] (0,20mm) arc[start angle=90, end angle=0, radius=20mm];
\draw[detector, name path=L2] (0,30mm) arc[start angle=90, end angle=0, radius=30mm];
\draw[detector, name path=L3] (0,50mm) arc[start angle=90, end angle=0, radius=50mm];

\draw[seed track, name path=curler track, opacity=0.6] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);

\fill[red dot, name intersections={of=L3 and curler track}](intersection-1) circle (1pt);
\fill[red dot, name intersections={of=L2 and curler track}](intersection-1) circle (1pt);
\fill[red dot, name intersections={of=L1 and curler track}](intersection-1) circle (1pt);

\end{tikzpicture}

\end{document}

答案1

这是因为添加“快捷”箭头会扭曲路径。修复此问题就像加载库一样简单bending,请参阅 pgfmanual 版本 3.1.8b 的第 204 页:

在此处输入图片描述

\documentclass{article}
\usepackage{tikz}
\usepackage[graphics, active, tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[
    detector/.style={line width=0.5pt, color=gray, line cap=round},
    track/.style={line width=0.9pt, color=black, -{Latex[length=2mm]}},
    seed track/.style={track, color=blue},
    red dot/.style={red, opacity=0.3}
]

\draw[detector, name path=L1] (0,20mm) arc[start angle=90, end angle=0, radius=20mm];
\draw[detector, name path=L2] (0,30mm) arc[start angle=90, end angle=0, radius=30mm];
\draw[detector, name path=L3] (0,50mm) arc[start angle=90, end angle=0, radius=50mm];

\draw[seed track, name path=curler track, opacity=0.6] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);

\fill[red dot, name intersections={of=L3 and curler track}](intersection-1) circle (1pt);
\fill[red dot, name intersections={of=L2 and curler track}](intersection-1) circle (1pt);
\fill[red dot, name intersections={of=L1 and curler track}](intersection-1) circle (1pt);

\end{tikzpicture}

\end{document}

在此处输入图片描述

为了进行明确的比较,让我们快速添加一个quick箭头。

\documentclass{article}
\usepackage{tikz}
\usepackage[graphics, active, tightpage]{preview}
\PreviewEnvironment{tikzpicture}

\usetikzlibrary{arrows.meta}
\usetikzlibrary{bending}
\usetikzlibrary{intersections}

\begin{document}

\begin{tikzpicture}[
    detector/.style={line width=0.5pt, color=gray, line cap=round},
    track/.style={line width=0.9pt, color=black, -{Latex[length=2mm]}},
    seed track/.style={track, color=blue},
    red dot/.style={red, opacity=0.3}
]

\draw[detector, name path=L1] (0,20mm) arc[start angle=90, end angle=0, radius=20mm];
\draw[detector, name path=L2] (0,30mm) arc[start angle=90, end angle=0, radius=30mm];
\draw[detector, name path=L3] (0,50mm) arc[start angle=90, end angle=0, radius=50mm];

\draw[seed track, name path=curler track, opacity=0.6] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);
\draw[dashed,red,-{Latex[length=2mm,quick]}] (0,0) .. controls (0,0) and (52mm, 8mm) .. (21mm, 62mm);
\fill[red dot, name intersections={of=L3 and curler track}](intersection-1) circle (1pt);
\fill[red dot, name intersections={of=L2 and curler track}](intersection-1) circle (1pt);
\fill[red dot, name intersections={of=L1 and curler track}](intersection-1) circle (1pt);

\end{tikzpicture}

\end{document}

在此处输入图片描述

正如您所见,“快速”曲线已关闭,并且与您在示例中的曲线相匹配。

不用说,如果你加载,你也可以弯曲箭头bending,但这不是当前问题的核心。

相关内容