我想填充椭圆被线段截断的区域。我想填充上半部分。我不知道如何选择上半部分。
import contour; import graph; size(7cm);
import patterns;
add("hatch",hatch(2.5mm));
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);
draw(p1,linewidth(1));
path p2=buildcycle(p1,cf[0][0]);
/* dots and labels */
fill(p2,pattern("hatch"));
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);
dot((-3.999566181385855,-1.8003469843683073),dotstyle);
label("$A$", (-3.9493818181818185,-1.7070844686648494), NE * labelscalefactor);
label("$f$", (0.5339272727272717,-1.0395095367847405), NE * labelscalefactor);
clip((xmin,ymin)--(xmin,ymax)--(xmax,ymax)--(xmax,ymin)--cycle);
/* end of picture */
答案1
反转线路...
因此,不要:
path p1=(-4,-1.8003469843683073)--(5,0);
你要:
path p1=(5,0)--(-4,-1.8003469843683073);
这产生了
但是,您实际上不需要buildcycle
执行您正在做的事情,也不需要contour
使用库,也不需要将椭圆绘制为函数。这里有一个更简单的版本,您可能会觉得比较起来很有趣...
settings.outformat="pdf";
defaultpen(fontsize(10pt));
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(cf);
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);
笔记
Asymptote 提供了许多现成的命名路径,例如,
unitcircle
您可以按比例缩放以获得椭圆路径
unitcircle
上有四个“点”,从 3 点开始,以正方向为顺时针方向测量。点 2.4 是 2.4/4 = 0.6 圈。您可以使用所需的形状
subpath
来获取路径的一部分,然后使用 将其关闭回到起点-- cycle
。
我可以推荐Charles Staats 的教程。