[Tex/LaTex] Using math in TikZ

tikz-pgf

I know it has been asked and answered before, and I need to put { and } around it, but for some reason this doesn't work:

\draw (0,0) -- ({atan(1)}:{sqrt(2)});

Any idea why?

Best Answer

This issue has been fixed in the official version of TikZ ( v.3.0.0 and later).

The answer continues after these messages.... Community Promotion Ads - 2015



It needs more cowbell!!

The reason is quite mystical for me and probably our wizards will explain it. You need an extra space in the end :

\begin{tikzpicture}
\draw (0,0) -- ({atan(1)}:{sqrt(2)} );
\end{tikzpicture}

or, remarkably, you don't put any braces in the last computation and skip the closing parenthesis:

\begin{tikzpicture}
\draw (0,0) -- ({atan(1)}:sqrt(2);
\end{tikzpicture}

This is simply black magic (or an extra parenthesis is carried from the math computation). So I welcome anyone to edit this answer and enlighten us.

I don't know if it is related or not but here is another one with more hilarity(!?)

\usetikzlibrary{calc}
\begin{tikzpicture}
\draw (0,0) arc (0:45:({veclen(2,2)}););
\end{tikzpicture}

In this example you can't get away with an extra space. You need to omit the last paranthesis. Also one can remove the last two characters ); since they play no role after the semicolon.

\begin{tikzpicture}
);
\end{tikzpicture}
Related Question