# Empty areas in figure and optimal curve fitting

I need to create a logo (well, a part of it) as an outline. The relevant part in MetaPost looks:

``````beginfig(1)
path ellipse;
ellipse = fullcircle xscaled 5in yscaled 1in;
for k = 0 step 45 until 135:
fill ellipse rotated k;
endfor;

for k = 0 step 45 until 135:
unfill ellipse scaled 0.8 rotated k;
endfor;

endfig;
end.
``````

With this I got

because `unfill` is just a fill with white.

I would like to get an eps, pdf, or svg with empty area inside. Like this:

Of course, if would be nice if the curves be optimal because otherwise the logo would make some unpleasant surprises while used in texts. The optimal solution is just two path: one consisting of 16 Bézier curves going anticlockwise followed by another internal path consisting of 16 smaller Bézier curves.

Right now I just exported black and white logo to 6000dpi png and used the program `autotrace` to get the curves. Is there a more elegant way to do it?

• I think that the only way to do this in Metapost will be to define a path and a pen that gives you the desired outline. Metapost cannot convert the intersection of two filled regions into a path. Sep 8, 2017 at 13:44

I'm no MetaPost wizard, but after a little experimentation I got this result.

``````beginfig(1)
path ellipse, segment, outline, outside, inside;
pair start, stop;

ellipse = fullcircle xscaled 5in yscaled 1in;
stop := ellipse intersectionpoint (ellipse rotated 45);
start := (ellipse rotated -45) intersectionpoint ellipse;
segment := (ellipse cutbefore start) -- (ellipse cutafter stop);
outline := segment for k = 45 step 45 until 315: -- segment rotated k endfor -- cycle;

outside := outline;
inside := outline scaled 0.8;

fill outside -- (reverse inside) -- cycle;
endfig;
``````

I modified your code to get the flowery shape into a path variable `outline`. Then I used a trick to only fill in the area inbetween the two curves. I don't know a proper reference for it; the Metafun manual (section 1.5) does talk about it, saying

This feature depends on the POSTSCRIPT way of filling closed paths, which comes down to filling either the left or the right hand side of a curve.

Notice the `reverse`, which serves a critical role: it reverses the orientation of the inner path. If you `draw` instead of `fill` the shape, you'll see some more of what's going on.

As @Aditya alludes to, MetaPost can't really `unfill` areas. But in special cases you can use this approach to get around that limitation.