答案1
暗示
您可以尝试使用类似这样的构建块来构造该对象:
import graph3;
size(200,0);
currentprojection=orthographic(camera=(-24,-30,-70),
up=Z,target=Z-Z,zoom=0.9,viewportshift=(0.02,0.02));
real R=1;
triple fs(pair u){
real phi=u.x, theta=u.y;
return R*(cos(theta)*cos(phi),cos(theta)*sin(phi),sin(theta));
}
surface qXYZ=surface(fs,(0,0),(pi/2,pi/2),nu=8,nv=100,usplinetype=Spline);
surface qXY=surface((0,0,0)--arc((0,0,0),(R,0,0),(0,R,0))--cycle);
surface qXZ=surface((0,0,0)--arc((0,0,0),(R,0,0),(0,0,R))--cycle);
surface qYZ=surface((0,0,0)--arc((0,0,0),(0,R,0),(0,0,R))--cycle);
surface[] s={qXYZ,qXY,qXZ,qYZ};
draw(s,lightgray,meshpen=nullpen,render(merge=true));
这些块可以组合在一起,例如,像这样:
import graph3;
size(200,0);
currentprojection=
orthographic(camera=(-34,27,-67),up=Y,target=Z-Z,zoom=0.6,viewportshift=(0.01,0.01));
real R=1;
real a=2*R/sqrt(2);
triple fs(pair u){
real phi=u.x, theta=u.y;
return R*(cos(theta)*cos(phi),cos(theta)*sin(phi),sin(theta));
}
surface sXYZ=surface(fs,(0,0),(2pi,pi/2),nu=8,nv=100,usplinetype=Spline);
surface sXY=surface(circle((0,0,0),R));
surface qXYZ=surface(fs,(0,0),(pi/2,pi/2),nu=8,nv=100,usplinetype=Spline);
surface qXY=surface((0,0,0)--arc((0,0,0),(R,0,0),(0,R,0))--cycle);
surface qXZ=surface((0,0,0)--arc((0,0,0),(R,0,0),(0,0,R))--cycle);
surface qYZ=surface((0,0,0)--arc((0,0,0),(0,R,0),(0,0,R))--cycle);
surface[] s={sXYZ,sXY};
surface[] q={qXYZ,qXY,qXZ,qYZ};
for(int i=0;i<4;++i)
draw(rotate(i*90,X)*shift((0,0,-a))*s,orange,meshpen=nullpen,render(merge=true));
draw(rotate(( 90),Y)*shift((0,0,-a))*s,orange,meshpen=nullpen,render(merge=true));
draw(rotate((-90),Y)*shift((0,0,-a))*s,orange,meshpen=nullpen,render(merge=true));
draw(shift((-a,-a,-a))*q,red,meshpen=nullpen,render(merge=true));
draw(shift(( a,-a,-a))*rotate(90,Z)*q,deepgreen,meshpen=nullpen,render(merge=true));
draw(shift(( a, a,-a))*rotate(180,Z)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift((-a, a,-a))*rotate(270,Z)*q,lightgray,meshpen=nullpen,render(merge=true));
transform3 tr=reflect(Z-Z,X,Y);
draw(tr*shift((-a,-a,-a))*q,red,meshpen=nullpen,render(merge=true));
draw(tr*shift(( a,-a,-a))*rotate(90,Z)*q,deepgreen,meshpen=nullpen,render(merge=true));
draw(tr*shift(( a, a,-a))*rotate(180,Z)*q,blue,meshpen=nullpen,render(merge=true));
draw(tr*shift((-a, a,-a))*rotate(270,Z)*q,lightgray,meshpen=nullpen,render(merge=true));
答案2
借助 g.kov 提交的答案,我能够生成我想要的图形。以下是完整代码:
import graph3;
size(200,0);
currentprojection= orthographic(camera=(-34,27,-67),up=Y,target=Z-,zoom=0.6,viewportshift=(0.01,0.01));
real R=1.5;
real a=2*R/sqrt(2);
triple fs(pair u){real phi=u.x, theta=u.y;return R*(cos(theta)*cos(phi),cos(theta)*sin(phi),sin(theta));}
xaxis3("$x$",0,1,red);
yaxis3("$y$",0,1,deepgreen);
zaxis3("$z$",0,1,blue);
surface sXYZ=surface(fs,(0,0)(2pi,pi/2),nu=8,nv=100,usplinetype=Spline);
surface sXY=surface(circle((0,0,0),R));
surface qXYZ=surface(fs,(0,0),(pi/2,p/2),nu=8,nv=100,usplinetype=Spline);
surface qXY=surface((0,0,0)--arc((0,0,0),(R,0,0),(0,R,0))--cycle);
surface qXZ=surface((0,0,0)--arc((0,0,0),(R,0,0),(0,0,R))--cycle);
surface qYZ=surface((0,0,0)--arc((0,0,0),(0,R,0),(0,0,R))--cycle);
surface[] s={sXYZ,sXY};
surface[] q={qXYZ,qXY,qXZ,qYZ};
draw(shift((0,0,-a))*s,blue,meshpen=nullpen,render(merge=true));
draw(rotate((90),X)*shift((0,0,a))*s,blue,meshpen=nullpen,render(merge=true));
draw(rotate((180),X)*shift((0,0,a))*s,blue,meshpen=nullpen,render(merge=true));
draw(rotate((270),X)*shift((0,0,a))*s,blue,meshpen=nullpen,render(merge=true));
draw(rotate((90),Y)*shift((0,0,a))*s,blue,meshpen=nullpen,render(merge=true));
draw(rotate((-90),Y)*shift((0,0,-a))*s,blue,meshpen=nullpen,render(merge=true));
draw(shift((-a,-a,-a))*q,blue,meshpen=nullpen,render(merge=true));
draw(shift(( a,-a,a))*rotate(90,Z)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift(( a, a,a))*rotate(180,Z)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift((-a, a,-a))*rotate(270,Z)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift((-a,-a,a))*rotate(90,Y)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift(( a,-,a))*rotate(90,Z)*rotate(90,Y)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift((-a,a,a))*rotate(270,Z)*rotate(90,Y)*q,blue,meshpen=nullpen,render(merge=true));
draw(shift(( a,a,a))*rotate(180,Z)*rotate(90,Y)*q,blue,meshpen=nullpen,render(merge=true));
draw((-a,-a,-a)--( a,-a,-a)--( a, a,-a)--(-a, a,-a)--cycle,linewidth(2));
draw((-a,-a,a)--( a,-a,a)--( a, a,a)--(-a, a,a)--cycle,linewidth(2));
draw((a,-a,-a)--( a,-a,a),linewidth(2));
draw((a,a,-a)--( a,a,a),linewidth(2));
draw((-a,-a,-a)--( -a,-a,a),linewidth(2));
draw((-a,a,-a)--( -a,a,a),linewidth(2));
其生产成果为: