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.

1 Answer 1

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}
5
  • Do you know if this bug will always exists or will it be fixed some time in the future?
    – dustin
    Jul 17, 2013 at 17:51
  • 3
    If someone reports it, it might get fixed =)
    – Jake
    Jul 17, 2013 at 17:56
  • @dustin tex.stackexchange.com/questions/77624/pgf-math-engine-imprecise Atan for angles closer to 90 is not an easy task with TeX precision.
    – percusse
    Jul 17, 2013 at 18:12
  • 1
    With the latest CVS version of TikZ/pgf (since 2013-07-19), this bug (numerical instability in the atan2 implementation) is fixed. Jul 29, 2013 at 14:26
  • @PaulGaborit: Sweet, thanks for the notification!
    – Jake
    Jul 29, 2013 at 14:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.