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.

These definitions of anglebetween are far from perfect. If we don't start in the origin, we get the<br />

curve in the wrong place and when we swap both points, we get the wrong curve.<br />

The solution for the displacement is given in the METAPOST manual and looks like this (we package<br />

the macro a bit different):<br />

def anglebetween (expr endofa, endofb, common, length) =<br />

(unitvector (endofa-common){(endofa-common) rotated 90} ..<br />

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

enddef ;<br />

As you can see, we compensate for the origin of both vectors. This macro is called with a few more<br />

parameters. We need to pass the length, since we want to add the shift to the macro and the shift<br />

takes place after the scaling.<br />

pair a, b, c ; a := (2cm,-1cm) ; b := (3cm,1cm) ; c := (-1cm,.5cm) ;<br />

drawarrow c--a ; drawarrow c--b ;<br />

drawarrow anglebetween(a,b,c,1cm) withcolor .625red ;<br />

That the results are indeed correct, is demonstrated by the output of following example:<br />

However, when we swap the points, we get:<br />

This means that instead of rotating over 90 degrees, we have to rotate over −90 or 270 degrees.<br />

That way the arrow will also point in the other direction. There are undoubtedly more ways to<br />

determine the direction, but the following method also demonstrates the use of turningnumber,<br />

which reports the direction of a path. For this purpose we compose a dummy cyclic path.<br />

vardef anglebetween (expr endofa, endofb, common, length) =<br />

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

show tn ;<br />

Marking angles A few applications<br />

281

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

Saved successfully!

Ooh no, something went wrong!