9
\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}

The code above produces the following error:

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

There is nothing out of the ordinary with the code, and I am unable to figure out what is causing this issue. I drew the bounding box around the figure it is well within the page.

Furthermore, the line it is pointing to is an arc of a circle with a radius of .75cm so that can be greater than 19 feet either.

jub0bs
  • 58,916
dustin
  • 18,617
  • 23
  • 99
  • 204

1 Answers1

9

This is due to a numerical instability in the atan2 implementation that has been fixed in the CVS version of TikZ since 2013-07-19.

If the y component is too large, the function crashes for large differences between the y and x components. The following example demonstrates this:

\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}

What you can do to circumvent this is to make the y component equal to 1 by dividing both components by the y component. This is not necessary if you use the CVS version of TikZ more recent than 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}
Jake
  • 232,450