Figure 47 de la documentation MetaPost (mpman)

Auteurs ou autrices : John D. Hobby, MetaPost development team.

Mise en ligne le 13 janvier 2023

Image du résultat de l’exemple

Cet exemple est extrait de la documentation de MetaPost.

Code


marksize=4pt;
def draw_mark(expr p, a) =
    begingroup
        save t, dm; pair dm;
        t = arctime a of p;
        dm = marksize*unitvector direction t of p
        rotated 90;
        draw (-.5dm.. .5dm) shifted point t of p;
    endgroup
enddef;

def draw_marked(expr p, n) =
    begingroup
        save amid;
        amid = .5*arclength p;
        for i=-(n-1)/2 upto (n-1)/2:
            draw_mark(p, amid+.6marksize*i);
        endfor
        draw p;
    endgroup
enddef;

angle_radius=8pt;
def mark_angle(expr a, b, c, n) =
    begingroup
        save s, p; path p;
        p = unitvector(a-b){(a-b)rotated 90}..unitvector(c-b);
        s = .9marksize/length(point 1 of p - point 0 of p);
        if s < angle_radius: s:=angle_radius; fi
        draw_marked(p scaled s shifted b, n);
    endgroup
enddef;

def mark_rt_angle(expr a, b, c) =
    draw ((1,0)--(1,1)--(0,1))
    zscaled (angle_radius*unitvector(a-b)) shifted b
enddef;

beginfig(42);
pair a,b,c,d;
b=(0,0); c=(1.5in,0); a=(0,.6in);
d-c = (a-b) rotated 25;
dotlabel.lft("a",a);
dotlabel.lft("b",b);
dotlabel.bot("c",c);
dotlabel.llft("d",d);
z0=.5[a,d];
z1=.5[b,c];
(z.p-z0) dotprod (d-a) = 0;
(z.p-z1) dotprod (c-b) = 0;
draw a--d;
draw b--c;
draw z0--z.p--z1;
draw_marked(a--b, 1);
draw_marked(c--d, 1);
draw_marked(a--z.p, 2);
draw_marked(d--z.p, 2);
draw_marked(b--z.p, 3);
draw_marked(c--z.p, 3);
mark_angle(z.p, b, a, 1);
mark_angle(z.p, c, d, 1);
mark_angle(z.p, c, b, 2);
mark_angle(c, b, z.p, 2);
mark_rt_angle(z.p, z0, a);
mark_rt_angle(z.p, z1, b);
endfig;
end.

Mots clés : mpmandefdotprod3Ddocumentationsave

Cet exemple fait partie de la collection d’exemples Documentation de MetaPost (mpman).

Fichiers


doc18-42.pdf

11.28 KB

Télécharger l’archive complète


doc18-42.zip

133.46 KB