When drawing with TikZ, I find sometime convenient to use polar coordinates (angle:distance), as in this MWE

\documentclass{article}
\usepackage{tikz}

\begin{document}
\begin{tikzpicture}
   [pole/.style={circle,draw=gray,fill=gray,thick,text width=2cm, align=center}]
  \node[pole] (eur) at (60:3cm) {Europe};
  \node[pole] (afr) at (300:3cm) {Afrique};
  \node[pole] (amq) at (180:3cm)  {Amérique};
\end{tikzpicture}
\end{document}

How can I get a similar effect using METAPOST ? I could'nt find direct answer in the manual. I am quite sure one can achieve the same with a good knowledge of geometry. It would be good for scripting.

So far, my METAPOST equivalent would be

beginfig(1);
u:=1cm ;
label(btex Amérique etex, (-3u,0) ) ;
label(btex Europe etex, (u,2u) ) ;
label(btex Afrique etex, (u,-2u) ) ;
endfig ;
end

Of course this are not polar coordinates and I am even not sure angles are the same as in TikZ. Since I am not a scientist, I would be glad to have some explanation if some geometry knowledge is required.

  • You can easily convert r and φ to cartesian coordinates using the prescription (x,y) = (r*cos(φ),r*sin(φ)) – Henri Menke Nov 15 at 20:21
up vote 7 down vote accepted

Use the dir operator. From the MetaPost manual:

enter image description here

Here with MetaFun in ConTeXt:

\startMPpage
u:=1cm ;
label(btex Amérique etex, 3u*dir 60) ;
label(btex Europe etex, 3u*dir 300) ;
label(btex Afrique etex, 3u*dir 180) ;
\stopMPpage
  • Thanks. I wouldn't have been able to find this on my own. It's been too long since I learnt what does cos and sin reflect… But now I see the point. – sztruks Nov 15 at 21:24
  • There is also an operator angle that does the opposite, so that angle dir 60 should return 60. A bit like atan2 in other languages. – Thruston Nov 15 at 21:42
  • As a matter of style you could also write 3 dir 60 scaled u. – Thruston Nov 15 at 21:47
  • @Thruston angle does exactly perform atan2 (at least in double and decimal mode) github.com/TeX-Live/texlive-source/blob/… – Henri Menke Nov 15 at 21:50
  • Yes quite right. In my old-fashioned British way, when I say “a bit like” I mean “exactly the same as”… – Thruston Nov 15 at 21:55

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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