\documentclass[convert = false, border = 2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\begin{pgfinterruptboundingbox}
\path[name path = line1] (O) -- (15:5cm);
\draw (O) -- (-45:4.5cm) coordinate (P1);
\path[name path = line2] (P1) -- +(0, 5cm);
\path[name intersections = {of = line1 and line2, by = P2}];
\end{pgfinterruptboundingbox}
\draw let
\p0 = (P1),
\p1 = (P2),
\p2 = (O),
\n1 = {atan2(\x1 - \x0, \y1 - \y0)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {.75cm}
in (P1) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2];
\end{tikzpicture}
\end{document}
上述代码产生以下错误:
ERROR: Dimension too large.
--- TeX said ---
<recently read> \pgfmath@x
l.22 \n1 = {atan2(\x1 - \x0, \y1 - \y0)}
,
--- HELP ---
From the .log file...
I can't work with sizes bigger than about 19 feet.
Continue and I'll use the largest value I can
代码没有任何异常,我无法找出导致此问题的原因。我在图形周围画了一个边界框,它完全在页面内。
此外,它指向的线是一个圆弧,半径为,.75cm
因此也可以大于19英尺。
答案1
这是由于atan2
实现中的数值不稳定性造成的,自 2013-07-19 起,该问题已在 TikZ 的 CVS 版本中得到修复。
如果 y 分量太大,函数会因 y 和 x 分量之间的差异过大而崩溃。以下示例说明了这一点:
\documentclass{article}
\usepackage{tikz}
\begin{document}
\pgfmathparse{atan2(0.01,1000)} % Crashes
\pgfmathparse{atan2(0.001,100)} % Crashes
\pgfmathparse{atan2(0.01,100)} % Is fine
\pgfmathparse{atan2(0.0001,10)} % Is fine
\pgfmathparse{atan2(0.0000001,10)} % Is fine
\end{document}
为避免这种情况,您可以通过将两个分量除以 y 分量来使 y 分量等于 1。如果您使用的 TikZ 的 CVS 版本比 2013-07-19 更新,则无需执行此操作。
\documentclass[convert = false, border = 2cm]{standalone}
\usepackage{tikz}
\usetikzlibrary{calc, intersections}
\begin{document}
\begin{tikzpicture}
\coordinate (O) at (0, 0);
\begin{pgfinterruptboundingbox}
\path[name path = line1] (O) -- (15:5cm);
\draw (O) -- (-45:4.5cm) coordinate (P1);
\path[name path = line2] (P1) -- +(0, 5cm);
\path[name intersections = {of = line1 and line2, by = P2}];
\end{pgfinterruptboundingbox}
\draw let
\p0 = (P1),
\p1 = (P2),
\p2 = (O),
\n1 = {atan2((\x1 - \x0)/(\y1 - \y0), 1)},
\n2 = {atan2(\x2 - \x0, \y2 - \y0)},
\n3 = {.75cm}
in (P1) +(\n1:\n3) arc[radius = \n3, start angle = \n1, end angle = \n2];
\end{tikzpicture}
\end{document}