我在用着渐近线绘制一些图形,我需要在两个图形的交点处放置一个点path3[]
,但该命令intersectionpoint()
不起作用path3[]
。我该怎么办?
答案1
该函数的内置三维版本intersectionpoints
返回两个路径的交点数组3d
。要获取两个数组的交点path3[]
,可以使用一个简单的函数intersectionpoints3
,该函数检查并累积交点的所有组合:
import three;
currentprojection=orthographic(camera=(-5,1.5,4),up=Y,target=O,zoom=1);
triple[] intersectionpoints3(path3[] p,path3[] q){
triple[] r=new triple[];
triple[] s;
for(path3 pk:p){
for(path3 qj:q){
s=intersectionpoints(pk,qj);
if(s.length>0)r.append(s);
}
}
return r;
}
size(200);
path3[] p=box(O,(1,1,1));
path3[] q=(-0.5,0,0.5)--(1.5,0,0.5)..(2,0.5,0.5)..(1.5,1,0.5)
^^(1.5,1,0.5)--(-0.5,1,0.5)..(-1,0.5,0.5)..(-0.5,0,0.5);
draw(p,darkblue);
draw(q,orange);
dot(intersectionpoints3(p,q),red);