我有以下代码:
unitsize(1cm);
path c = circle( (0,0), 1 );
path p(int sides) {return polygon(sides);}
int sides = 3;
for(sides; sides <= 8; ++sides){
path pol = shift( (2.2sides,0) )*p(sides);
path cir = shift(2.2sides,0)*c;
pair vert[] = intersectionpoints( pol , cir );
draw(pol);
draw(cir);
for(int k = 0; k <= vert.length-1; ++k){
dot(vert[k], L = string(k), fontsize(8pt) );
}
}
path icos = shift( 2.2(sides) )*polygon(20);
path cir = shift( 2.2(sides) )*unitcircle;
pair vert[] = intersectionpoints( icos, cir );
for(int k = 0; k <= vert.length-1; ++k){
dot(vert[k]);
}
draw(icos);
draw(cir);
这将生成附图;请注意,对于奇数条边,它仅计算一个交点。我想要的是绘制多边形与其外接圆的交点;请注意,对于最后一个二十面体,我使用了unitcircle
而不是circle
,只是为了确保得到相同的结果。
我的 Asymptote 版本是 2.65,我的 Ghostscript 版本是 9.52;均打包在 Debian TeXLive 2019 发行版中。
如何获取正多边形与其外接圆的所有交点?提前致谢!
答案1
在阅读文档后,我找到了Circle
模块的例程graph
,该例程“可以生成真正的圆”(第 31 页)。使用它解决了问题。
settings.outformat="pdf";
unitsize(1cm);
import graph;
path c = Circle( (0,0), 1 );
path p(int sides) {return polygon(sides);}
int sides = 3;
for(sides; sides <= 8; ++sides){
path pol = shift( (2.2sides,0) )*p(sides);
path cir = shift(2.2sides,0)*c;
pair vert[] = intersectionpoints( pol , cir );
draw(pol);
draw(cir);
for(int k = 0; k <= vert.length-1; ++k){
dot(vert[k], L = string(k), fontsize(8pt) );
}
}
path icos = shift( 2.2(sides) )*polygon(20);
path cir = shift( 2.2(sides) )*c;
pair vert[] = intersectionpoints( icos, cir );
for(int k = 0; k <= vert.length-1; ++k){
dot(vert[k], L=string(k), fontsize(4pt));
}
draw(icos);
draw(cir);
path Ellipse(pair centre = (0,0), real xradius, real yradius){
return shift( ( centre ) )*scale( xradius, yradius )*Circle( (0,0), 1);
}
path elip = shift( 2.2(sides+1) )*Ellipse( (0,0), 1.1, 0.8 );
path cir1 = shift( 2.2(sides+1) )*c;
draw(elip);
draw(cir1);
pair verts[] = intersectionpoints( elip, cir1 );
for(int k = 0; k <= verts.length-1;++k){
dot(verts[k], L=string(k), fontsize(4pt));
}