29.11.2012 Views

MetaFun - Pragma ADE

MetaFun - Pragma ADE

MetaFun - Pragma ADE

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Because in most cases we want the length to be consistent between figures and because passing<br />

two paths is more convenient than passing three points, the final definition looks slightly different.<br />

numeric anglelength ; anglelength := 20pt ;<br />

vardef anglebetween (expr a, b, str) = % path path string<br />

save endofa, endofb, common, curve, where ;<br />

pair endofa, endofb, common ; path curve ; numeric where ;<br />

endofa := point length(a) of a ;<br />

endofb := point length(b) of b ;<br />

if round point 0 of a = round point 0 of b :<br />

common := point 0 of a ;<br />

else :<br />

common := a intersectionpoint b ;<br />

fi ;<br />

where := turningnumber (common--endofa--endofb--cycle) ;<br />

curve := (unitvector (endofa-common){(endofa-common) rotated (where*90)} ..<br />

unitvector (endofb-common)) scaled anglelength shifted common ;<br />

draw thefreelabel(str,point .5 of curve,common) withcolor black ;<br />

curve<br />

enddef ;<br />

This macro has a few more if's than its predecessor. First we test if the label is a string, and if so,<br />

we calculate the picture ourselves, otherwise we leave this to the user.<br />

path a, b, c, d, e, f ;<br />

a := origin--( 2cm, 1cm) ; b := origin--( 1cm, 2cm) ;<br />

c := origin--(-2cm, 2cm) ; d := origin--(-2cm,-1cm) ;<br />

e := origin--(-1cm,-2cm) ; f := origin--( 1cm,-2cm) ;<br />

for i=a, b, c, d, e, f : drawarrow i ; endfor ;<br />

anglelength := 1.0cm ; drawoptions(withcolor .625red) ;<br />

drawarrow anglebetween(a,b,btex $\alpha $ etex) ;<br />

drawarrow anglebetween(c,d,btex $\gamma $ etex) ;<br />

drawarrow anglebetween(e,f,btex $\epsilon$ etex) ;<br />

anglelength := 1.5cm ; drawoptions(withcolor .625yellow) ;<br />

drawdblarrow anglebetween(b,c,btex $\beta $ etex) ;<br />

drawarrow reverse anglebetween(d,e,btex $\delta $ etex) ;<br />

drawarrow anglebetween(a,f,btex $\zeta $ etex) ;<br />

Because anglebetween returns a path, you can apply transformations to it, like reversing. Close<br />

reading of the previous code learns that the macro handles both directions.<br />

Marking angles A few applications<br />

283

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!