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.

p := fullcircle scaled (2*length(loc-ori)) shifted ori ;<br />

q := freesquare xyscaled (urcorner s - llcorner s) ;<br />

l := point (xpart (p intersectiontimes (ori--loc))) of q ;<br />

setbounds s to boundingbox s enlarged -freelabeloffset ;<br />

(s shifted -l)<br />

enddef ;<br />

Watch how we temporarily enlarge the bounding box of the typeset label text. We will now test<br />

this macro on a slightly rotated circle, using labels typeset by TEX. The reverse is there purely for<br />

cosmetic reasons, to suit the label texts.<br />

defining<br />

in<br />

funny macros.<br />

and on<br />

go on<br />

Can't we?<br />

We can<br />

pickup pencircle scaled 1mm ;<br />

path p ; p := reverse fullcircle rotated -25 scaled 3cm ;<br />

draw p withcolor .625yellow ; pair cp ; cp := center p ;<br />

freedotlabel (btex \strut We can etex, point 0 of p, cp) ;<br />

freedotlabel (btex \strut go on etex, point 1 of p, cp) ;<br />

freedotlabel (btex \strut and on etex, point 2 of p, cp) ;<br />

freedotlabel (btex \strut in etex, point 3 of p, cp) ;<br />

freedotlabel (btex \strut defining etex, point 4 of p, cp) ;<br />

freedotlabel (btex \strut funny etex, point 5 of p, cp) ;<br />

freedotlabel (btex \strut macros. etex, point 6 of p, cp) ;<br />

freedotlabel (btex \strut Can't we? etex, point 7 of p, cp) ;<br />

Unfortunately we can run into problems due to rounding errors. Therefore we use a less readable<br />

but more safe expression for calculating the intersection points. Instead of using point loc as<br />

endpoint we use loc shifted over a very small distance into the direction loc from ori. In the<br />

assignment to l we replace loc by:<br />

( (1+eps) * arclength(ori--loc) * unitvector(loc-ori) )<br />

13.3 Marking angles<br />

A convenient METAPOST macro is unitvector. When we draw a line segment from the origin to<br />

the point returned by this macro, the segment has a length of 1 base point. This macro has a wide<br />

range of applications, but some basic knowlegde of vector algebra is handy. The following lines<br />

of METAPOST code demonstrate the basics behind unitvectors.<br />

Marking angles A few applications<br />

279

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

Saved successfully!

Ooh no, something went wrong!