[metapost] Cannot fill sector

Stephan Hennig mailing_list at arcor.de
Sun Nov 14 19:37:17 CET 2010

Am 14.11.2010 17:55, schrieb Yasir Malik:

> I still do not know Metapost cannot find a common path between the
> two lines and the halfcircle.

Try reversing the direction of either argument to buildcycle.  In your 
code both have opposing directions.  That leads MetaPost into the wrong 
direction after finding the first intersection point, failing to close 
the cycle.

> As a aside, from my original post, Metapost would generate a
> compilation error when I chose to rotate p0 by 10 degrees instead of
> 72. Maybe this is an issue of floating point arithmetic being off
> (could be related to my original question of not being able to fill
> the sector)?

MetaPost does fixed point arithmetic, BTW.  But the problem is indeed 
numeric precision.  The 'triangle' path is a bit too short to intersect 
the half-circle from MetaPost's point of view.  A solution is to make 
the 'triangle' rays longer and cut them again before/during drawing.

Best regards,
Stephan Hennig

u = 1cm;
pair o, p[];
path halfcirc, area, triangle;
numeric diam;
diam = 10u;

o := (0, 0);
p0 := (diam, 0);
p0 := p0 rotated 10;
p1 := p0 rotated 72;
triangle = reverse (p0--o--p1);

halfcirc = halfcircle scaled diam;

draw halfcirc;
draw triangle cutbefore fullcircle cutafter fullcircle;

area = buildcycle(triangle, halfcirc);
fill area withgreyscale .7;


More information about the metapost mailing list