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.

280<br />

pair uv ; pickup pencircle scaled 1mm ; autoarrows := true ;<br />

draw fullcircle scaled 2cm withcolor .625red ;<br />

for i=(10,35), (-40,-20), (85,-15) :<br />

draw origin--i dashed evenly withcolor .625white ;<br />

drawarrow origin--unitvector(i) scaled 1cm withcolor .625yellow ;<br />

endfor ;<br />

draw origin withcolor .625red ;<br />

The circle has a radius of 1cm, and the three line segments are drawn from the origin in the direction<br />

of the points that are passed as arguments. Because the vector has length of 1, we scale it to<br />

the radius to let it touch the circle. By setting autoarrows we make sure that the arrowheads are<br />

scaled proportionally to the linewidth of 1 mm.<br />

An application of this macro is drawing the angle between two lines. In the METAPOST manual you<br />

can find two macros for drawing angles: mark_angle and mark_rt_angle. You may want to take<br />

a look at their definitions before we start developing our own alternatives.<br />

The previous graphic demonstrates what we want to accomplish: a circular curve indicating the<br />

angle between two straight lines. The lines and curve are drawn with the code:<br />

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

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

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

where anglebetween is defined as:<br />

def anglebetween (expr a, b) =<br />

(unitvector(a){a rotated 90} .. unitvector(b))<br />

enddef ;<br />

Both unitvectors return just a point on the line positioned 1 unit (later scaled to 1cm) from the<br />

origin. We connect these points by a curve that starts in the direction at the first point. If we omit<br />

the a rotated 90 direction specifier, we get:<br />

A few applications Marking angles

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

Saved successfully!

Ooh no, something went wrong!