Auteur ou autrice : Vincent Zoonekynd.
Mise en ligne le 12 octobre 2024
Code
u:=1cm;
beginfig(163)
vardef longueur(expr p) =
save l,i;
numeric l;
l:=0;
for i=0 step .01 until length(p):
l:=l+abs( (point i of p) - (point(i+.01) of p) );
endfor;
l % Pas de point-virgule
enddef;
vardef milieu(expr p) =
save l,i,tot,A,B;
numeric l,tot,i;
pair A,B;
tot := longueur(p);
l:=0;
B := point 0 of p;
for i:=0 step .01 until length(p):
A := B;
B := point i of p;
l := l+abs(B-A);
exitif l > 1/2 tot;
endfor;
1/2[A,B]
enddef;
vardef milieu_time(expr p) =
save l,i,tot,A,B,t;
numeric l,tot,i,t;
pair A,B;
tot := longueur(p);
l:=0;
B := point 0 of p;
for i:=0 step .01 until length(p):
t:=i;
A := B;
B := point i of p;
l := l+abs(B-A);
exitif l > 1/2 tot;
endfor;
t
enddef;
save arrowhead;
vardef arrowhead expr p =
save A,u,a,b; pair A,u; path a,b;
A := milieu(p);
u := unitvector(direction milieu_time(p) of p);
a := A{-u} .. (A - ahlength*u rotated 30);
b := A{-u} .. (A - ahlength*u rotated -30);
( a & reverse(a) & b & reverse(b) ) --cycle
enddef;
u:=1cm;
drawarrow (0,0) .. (-u,u) .. (u,u);
endfig;
end.