7

I would like to reproduce this picture with asymptote:

enter image description here

So far I can do it with sphere:

enter image description here

How can I draw the part of sphere using asymptote?

Edit

I was able to reproduce the picture with the answer submitted by g.kov. The code is in the answer below.

3
10

Hint

You can try to construct this object from building blocks like this one:

enter image description here

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));

The blocks can be combined, for example, like this:

enter image description here

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));
1
  • +1 I hope that i will see the complete version from u.
    – user213378
    Aug 17 '20 at 18:37
2

With the answer submitted by g.kov I was able to produce the figure I wanted. Here is the complete code:

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));

which produce:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.