Is there any option(s) in METAPOST (and/or METAFUN) to label things like TikZ allows it for nodes?
Of course I know about label.{top|bot|lft|rt|...} but is there something more precise?
Is there any option(s) in METAPOST (and/or METAFUN) to label things like TikZ allows it for nodes?
Of course I know about label.{top|bot|lft|rt|...} but is there something more precise?
There is the freelabel(label, point, point_origin) macro of Metafun. Not the same kind of labels as in tikz, but it can help.
It sets the label upon the straight line point_origin--point, near point but on the opposite side of point_origin.
A very quick example:
\documentclass{standalone}
\usepackage{luamplib}
\mplibsetformat{metafun}
\mplibtextextlabel{enable}
\begin{document}
\begin{mplibcode}
beginfig(1);
u := 3cm;
draw fullcircle scaled (2u);
for i = 0 upto 14:
draw origin -- u*dir 24i;
freelabel("$" & decimal 24i & "$", u*dir 24i, origin);
endfor;
endfig;
\end{mplibcode}
\end{document}
See the Metafun documentation (p. 453 and following) for more details.
One could extend the thefreelabel from metafun to put the labels in the direction one wants. It is the freelabeloffset that determines how far from the point the label is set.
\startMPpage[offset=1dk]
vardef dirlabel(expr s, l, d) =
thefreelabel(s,l, unitvector dir(d+180) shifted l)
enddef ;
path p ; p = (origin -- (1,0) .. (2,2) .. (0,1) .. cycle) scaled 100 ;
numeric N ; N := 20 ;
draw p ;
for i = 0 upto (N - 1) :
draw point i/N along p withpen pencircle scaled 2 withcolor darkred ;
draw dirlabel(decimal i, point i/N along p, angle(direction (arctime ((i/N)*arclength p) of p) of p) - 90) ;
endfor ;
\stopMPpage