
我用來Asymptote
製作圖形。我有兩條曲線定義為輪廓 C_1 和 C_2。我想填滿兩條曲線之間的區域。問題是輪廓返回guide
Asymptote 中的結構,而命令不接受此結構buildcycle
。誰能告訴我如何解決這個問題?謝謝。這是我使用的程式碼,它產生兩條曲線,但無法填滿它們之間的區域。
import graph;
import patterns;
import contour;
usepackage("mathrsfs");
size(8cm);
real eps=0.001;
real xmax=5.5,ymax=5.5;
pair af,ag;
real f(real x, real y) {return sqrt(1+x)-sqrt(x)+sqrt(1+y)-sqrt(y);}
real g(real x, real y) {return 1/sqrt(1+x)+1/sqrt(1+y);}
guide[][] Cf=contour(f,(eps,eps),(xmax,ymax),new real[] {1});
guide[][] Cg=contour(g,(eps,eps),(xmax,ymax),new real[] {1});
//these two lines are used to find intersection points
path D1=(0,ymax)--(xmax+eps,ymax);
path D2=(xmax,0)--(xmax,ymax+eps);
draw(Cf);
draw(Cg);
//path pp=buildcycle(Cf,D1,Cg,D2);
// the preceding line produces and error if commented
xaxis(Label(scale(0.75)*"$x$"),xmax=6,Arrow);
yaxis(Label(rotate(90)*scale(0.75)*"$y$"),ymax=6,Arrow);
label("$\mathscr{C}_{1}$",(xmax,0.2));
label("$\mathscr{C}_{2}$",(xmax,1.9));
label("I" ,(.2,.2));
label("II" ,(1.,1.));
label("III",(3.5,3.5));
end;
答案1
Cf
它在用和 替換 和時Cg
起作用,這樣可以獲得所需的(單一)指南。Cf[0][0]
Cg[0][0]
path pp=buildcycle(Cf[0][0],D1,Cg[0][0],D2);
請注意,我還稍微修改了D1
and D2
: 在你的定義中,D1
, D2
and pp
did不是無論如何相交。
path D1=(0,ymax-eps)--(xmax+eps,ymax-eps);
path D2=(xmax-eps,0)--(xmax-eps,ymax+eps);
有關如何使用的正確解釋contour
,請參閱製作精良(可惜不完整)漸近線教程查爾斯·斯塔茨 (Charles Staats) 著,p。 32.
import graph;
import patterns;
import contour;
usepackage("mathrsfs");
size(8cm);
real eps=0.001;
real xmax=5.5,ymax=5.5;
pair af,ag;
real f(real x, real y) {return sqrt(1+x)-sqrt(x)+sqrt(1+y)-sqrt(y);}
real g(real x, real y) {return 1/sqrt(1+x)+1/sqrt(1+y);}
guide[][] Cf=contour(f,(eps,eps),(xmax,ymax),new real[] {1});
guide[][] Cg=contour(g,(eps,eps),(xmax,ymax),new real[] {1});
//these two lines are used to find intersection points
path D1=(0,ymax-eps)--(xmax+eps,ymax-eps);
path D2=(xmax-eps,0)--(xmax-eps,ymax+eps);
path pp=buildcycle(Cf[0][0],D1,Cg[0][0],D2);
fill(pp,.8white); draw(pp);
xaxis(Label(scale(0.75)*"$x$"),xmax=6,Arrow);
yaxis(Label(rotate(90)*scale(0.75)*"$y$"),ymax=6,Arrow);
label("$\mathscr{C}_{1}$",(xmax,0.2));
label("$\mathscr{C}_{2}$",(xmax,1.9));
label("I" ,(.2,.2));
label("II" ,(1.,1.));
label("III",(3.5,3.5));
答案2
為了便於比較,這裡有一個 Metapost 版本。不支援隱式方程式或任何像 Asymptote 那樣聰明(或複雜)的contour
工具,所以我無法避免使用一些代數來獲得 OP 很樂意避免的“長表達式”。為了避免在x
接近零時溢出,我利用了以下事實:這兩條曲線關於穿過的線具有對稱性(0,0)--(1,1)
,並且 C1 穿過(9/16,9/16)
而 C2 穿過(3,3)
——因此我只使用循環來構造右側的曲線這些要點;然後我使用 MP 的reflectedabout
巨集來建立所需的上半部。
prologues := 3;
outputtemplate := "%j%c.eps";
beginfig(1);
u := 1cm;
path xx, yy, ff, gg;
xx = (1/2 left -- 6 right) scaled u;
yy = xx rotated 90;
drawarrow xx; drawarrow yy;
vardef f(expr x) =
save s; numeric s;
s = (1+sqrt(x)-sqrt(1+x))**2;
(1-2s+s**2)/(4s)
enddef;
vardef g(expr x) =
(1+x)/(2+x-2*sqrt(1+x))-1
enddef;
s = 0.05;
ff = ((9/16,9/16) for x = 9/16+s step s until 5.5: -- (x,f(x)) endfor) scaled u;
gg = ((3,3) for x = 3+s step s until 5.5: -- (x,g(x)) endfor) scaled u;
ff := reverse ff reflectedabout(origin,(1,1)) & ff;
gg := reverse gg reflectedabout(origin,(1,1)) & gg;
path A;
A = ff -- reverse gg -- cycle;
fill A withcolor .9[blue,white];
draw ff;
draw gg;
string s; s = "";
for $=0,9/16u,3u:
s := s & "I";
label.urt(s,($,$));
endfor
label.urt(btex ${\cal C}_1$ etex, point infinity of ff);
label.urt(btex ${\cal C}_2$ etex, point infinity of gg);
label.bot(btex $x$ etex, point 1 of xx);
label.lft(btex $y$ etex, point 1 of yy);
endfig;
end.
如果您也想繪製該區域的末端,您可以將 my 替換draw ff; draw gg;
為draw A
.