settings.outformat="pdf";
size(3cm,0);
draw((3,0) -- (0,0) -- (3,4));
draw(arc((0,0), (2,0), (3,4)),
arrow=Arrow(TeXHead), red);
draw(arc((0,0), (2,0), (3,4), direction=CW),
arrow=Arrow(TeXHead), blue);
dot((0,0)); dot((2,0)); dot((3,4));
While this looks good at first glance, Janet is distressed that upon magnification,
the two arrow tips both cross into the black line rather than stopping at its edge.
Here is the code to fix this using the optional parameter
margin=
for the
draw()
command:
settings.outformat="pdf";
size(3cm,0);
draw((3,0) -- (0,0) -- (3,4));
real linewidth = linewidth(currentpen);
/* A path drawn with margin=ArrowMargins will
be shortened at the end by 0.5 linewidth
and at the beginning by the full
linewidth. */
margin ArrowMargins = TrueMargin(linewidth, 0.5 linewidth);
draw(arc((0,0), (2,0), (3,4)), arrow=Arrow(TeXHead), red,
margin=ArrowMargins);
draw(arc((0,0), (2,0), (3,4), direction=CW),
arrow=Arrow(TeXHead), blue, margin=ArrowMargins);
The dots have been omitted to show the full effect, which will nevertheless be
visible only on close inspection (probably with high zoom).
2.9 Filling a region
Next, Janet would like to fill the region under the half-parabola. This may be
accomplished by creating a cyclic path and filling it with the fill command:
settings.outformat="pdf";
unitsize(1cm);
draw((-.1,0) -- (2,0), arrow=Arrow(TeXHead));
draw((0,-.1) -- (0,2), arrow = Arrow(TeXHead));
draw((0,0){up} .. (1,1) .. (2,sqrt(2)));
fill((0,0){up} .. (1,1) .. (2,sqrt(2))
-- (2,0) -- cycle);
15