[metapost] Arrows in the middle of a path

Hartmut Henkel hartmut_henkel at gmx.de
Mon Jul 28 20:18:10 CEST 2008


On Mon, 28 Jul 2008, Troy Henderson wrote:

> >   def midarrow (expr p, t) =
> >     drawarrow subpath(0,t) of p;
> >     draw subpath(t,1) of p;
> >   enddef;
>
> I might do something like
>
>    def midarrow (expr p, t) =
>      drawarrow subpath(0,t*length(p)) of p;
>      draw subpath(t,length(p)) of p;
>    enddef;
>
> and this works for paths of length greater than 1.  The parameter t is
> now a percentage of the total "path time".

if you like, you can also use the real path length, e. g. like this:


prologues:=3;

beginfig(1);

def midarrow (expr p, t) =
    draw p;
    filldraw arrowhead subpath(0,
        arctime(t*(arclength(p)-ahlength)+ahlength) of p) of p;
enddef;

u := 1cm;
path p; p := halfcircle scaled 20mm;
midarrow (p, 0.5);

endfig;
bye


...but this might get ugly if the curve has sharp bends and you get near
to them with the arrowhead.

Regards, Hartmut



More information about the metapost mailing list