[Tex/LaTex] Using math in TikZ


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 :

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

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

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

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(!?)

\draw (0,0) arc (0:45:({veclen(2,2)}););

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.

Related Question