两个轮廓之间的渐近线填充区域

两个轮廓之间的渐近线填充区域

我用它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和进行了轻微修改D2:在您的定义中D1D2pp确实不是无论如何都会相交。

path D1=(0,ymax-eps)--(xmax+eps,ymax-eps);
path D2=(xmax-eps,0)--(xmax-eps,ymax+eps);

有关如何使用的正确解释contour,请参阅制作精良的(可惜不完整)Asymptote 教程作者:Charles Staats,第 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 版本。它不支持隐式方程或任何像 Asymptotecontour功能那样聪明(或复杂)的东西,所以我无法避免一些代数运算来获得 OP 乐于避免的“长表达式”。为了避免在接近零时溢出,我利用了这两个曲线关于通过的线具有对称性以及 C1 通过而 C2 通过的x事实——因此我只使用一个循环来构造这些点右侧的曲线;然后我使用 MP 的宏来创建所需的上半部分。(0,0)--(1,1)(9/16,9/16)(3,3)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.

如果您也想绘制该区域的末端,您可以用 替换我draw ff; draw gg;draw A

在此处输入图片描述

相关内容