[metapost] Labeling an angle

Palle Jørgensen gimmespam at pallej.dk
Thu Dec 28 14:44:23 CET 2006

mailanholgerpeters at web.de writes:

> Hi,
> thanks for your help, but I'd rather have a sector of a circle drawn
> around it, as in:
> http://de.wikipedia.org/wiki/Bild:Vertical_angles.png
> Is there an easier way than to do hard-coded positioning of the
> circle and the label?
> Holger

I have created a solution. It is probably not perfect yet, but feel
free to use, and please report any problems to me. Suggestions for
improvements can be sent to me as well.

When sufficient testing and improvements has been applied I will
upload it to CTAN. Of course some proper documentation is needed as


<solution and example>

%% The definitions
numeric archwidth;

vardef archangle@#(expr _p, _q, _s) text _t =
    save _a,_b,_w, _arch, _halfangle, _label_origin;
    (_a,_b)=_p intersectiontimes _q;
    pair _w;
    _w = whatever[point _a of _p + archwidth * unitvector direction _a of _p,
    point _a of _p +
    archwidth * unitvector direction _a of _p +
    (ypart.direction _a of _p, -xpart.direction _a of _p)];
    _w  = whatever[point _b of _q, point _b of _q + direction _b of _q];
    path _arch;
    _arch = point _a of _p +
    archwidth * unitvector direction _a of _p{(if direction _a of _p dotprod unitvector direction _b of _q > 0: 1 else: -1 fi)*(_w-(point _a of _p +
      archwidth * unitvector direction _a of _p))}..point _b of _q +
    archwidth * unitvector direction _b of _q;
    draw _arch _t;
    path _halfangle;
    _halfangle = point _a of _p-2*archwidth*unitvector(direction _a of _p + direction _b of _q)--point _a of _p+2*archwidth*unitvector(direction _a of _p + direction _b of _q);
    pair _label_origin;
    _label_origin = _halfangle intersectionpoint _arch;
    label@#(_s, _label_origin) _t; 

%% The example

path p, q;

p = (-1cm,1.5cm)--(3cm,1cm);
q = (0,3cm)--(1cm,0);

  archangle.lrt(q, p, btex $\alpha$ etex)
    withpen pencircle scaled 2pt withcolor blue;
  archangle.urt(reverse q, p, btex $\beta$ etex)
    withcolor green;
  archangle.urt(q, reverse p, btex $\delta$ etex)
    withcolor green + red;
  archangle.ulft(reverse q, reverse p, btex $\gamma$ etex)
    withcolor blue + red;
  draw p;
  draw q withcolor red;
  label.rt(btex p etex,point 1 of p);
  label.bot(btex q etex,point 1 of q);

</solution and example>

Palle Jørgensen, Stud.mag., BSc

E-post: hamselv(at)pallej(dot)dk
WWW:    http://pallej.dk/

More information about the metapost mailing list