I want to fill the area cut off from an ellipse by a line segment. I want to fill the upper half. I don't know how to select the upper half.

import contour; import graph; size(7cm); 
import patterns;
string blank(real x) {return "";} 
real labelscalefactor = 0.5; /* changes label-to-point distance */
pen dps = linewidth(0.7) + fontsize(10); defaultpen(dps); /* default pen style */ 
pen dotstyle = black; /* point style */ 
real xmin = -5.5, xmax = 6.86, ymin = -3.5, ymax = 3.9;  /* image dimensions */

Label laxis; laxis.p = fontsize(10); 
xaxis(xmin, xmax, Ticks(laxis,blank, Step = 1, Size = 2, NoZero),EndArrow(6), above = true); 
yaxis(ymin, ymax, Ticks(laxis, blank, Step = 1, Size = 2, NoZero),EndArrow(6), above = true); /* draws axes; NoZero hides '0' label */ 
 /* draw figures */
real implicitf1 (real x, real y) { return -1+0.1111111111111111*y^2+0.04000000000000001*x^2; } 
guide[][] cf=contour(implicitf1, (xmin,ymin), (xmax,ymax), new real[]{0}, 500);
draw(cf[0][0], linewidth(1)); 
path p1=(-4,-1.8003469843683073)--(5,0); 
path p2=buildcycle(p1,cf[0][0]);
 /* dots and labels */
dot((-5,0),linewidth(4pt) + dotstyle); 
label("$B$", (-4.960654545454545,0.07629427792915584), NE * labelscalefactor); 
dot((5,0),linewidth(4pt) + dotstyle); 
label("$C$", (5.039709090909089,0.07629427792915584), NE * labelscalefactor); 
dot((0,-3),linewidth(4pt) + dotstyle); 
label("$D$", (0.039527272727271814,-2.927792915531334), NE * labelscalefactor); 
dot((0,3),linewidth(4pt) + dotstyle); 
label("$E$", (0.039527272727271814,3.080381471389646), NE * labelscalefactor); 
label("$A$", (-3.9493818181818185,-1.7070844686648494), NE * labelscalefactor); 
label("$f$", (0.5339272727272717,-1.0395095367847405), NE * labelscalefactor); 
 /* end of picture */

With this code I get a figure with lower portion filled. I want the upper portion filled. How to do this? enter image description here

1 Answer 1


Reverse the line...

So instead of:

path p1=(-4,-1.8003469843683073)--(5,0); 

you want:

path p1=(5,0)--(-4,-1.8003469843683073); 

this produces

enter image description here

However, you don't really need buildcycle to do what you are doing, or the contour library, or to plot the ellipse as a function. Here is a simpler version that you might find interesting for comparison...

size(377, 0);

import graph;
import patterns;

xaxis("", xmin=-5.5, xmax=6, EndArrow);
yaxis("", ymin=-3.5, ymax=4, EndArrow);

path cf = xscale(5) * yscale(3) * unitcircle;
real a = 2.4;

add("bengal", hatch(2mm, blue));
filldraw(subpath(cf, 0, a) -- cycle, pattern("bengal"));
draw(point(cf, 0) -- point(cf, a));

dot("$A$", align=SW, point(cf, a));
dot("$B$", align=NW, point(cf, 2));
dot("$C$", align=NE, point(cf, 0));
dot("$D$", align=SE, point(cf, 3));
dot("$E$", align=NE, point(cf, 1));

label("$f$", (1,1), UnFill);

which produces: enter image description here


  • Asymptote provides a number of ready-made named paths such as unitcircle which you can scale as shown to get an ellipse

  • The unitcircle path has four "points" along it, starting at 3 o'clock, and measured so that positive is clockwise. Point 2.4 is 2.4/4 = 0.6 of the way round.

  • You can make the shape you want using subpath to get part of your path and then closing it back to the start with -- cycle.

I can recommend Charles Staats' tutorial.

  • I did try changing the order in the buildcycle command, but it didn't work. Thanks. Mar 28, 2019 at 11:56
  • I have gone through Charles Staat's tutorial. I had drawn the figure in geogebra, downloaded as asymptote file and edited it by hand to add shading etc. I used the ImplicitCurve() command provided by the geogebra. I have similar problem with strophoid. I have posted the question herehttps://tex.stackexchange.com/questions/484915/how-to-choose-the-correct-area-to-correct-area-to-fill-using-build-cycle-in-asym Can you please take a look? Apr 15, 2019 at 9:04
  • Correct link: tex.stackexchange.com/q/484915/15036
    – Thruston
    Apr 15, 2019 at 12:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .