4

enter image description herePlease help me, I want to delete the sphere that is inside the cylinder. How can I do this? This is my code.

import solids;
size(10cm,0);
currentprojection=perspective(camera=(5,-4,2));
viewportmargin=(.5cm,.5cm);
path3[] p=reverse(scale3(2)*unitcircle3)^^shift(.9999,0,0)*unitcircle3;
triple f(pair p){
    real x=1+cos(p.x);
    real y=sin(p.x);
    real z=p.y*sqrt(4.0001-x^2-y^2);
    return (x,y,z);
}
draw(surface(p,planar=true),lightcyan+opacity(0.6));
draw(surface(f,(0,0),(2pi+.0001,1),100,Spline),lightcyan+opacity(0.8));

triple fs(pair u){ real phi=u.x, theta=u.y; real x=cos(theta)cos(phi); real y=cos(theta)sin(phi); real z=sin(theta); return 2*(x,y,z); } surface s=surface(fs,(0,0),(pi+0.0001,pi),nu=8,nv=100,usplinetype=Spline); draw(s,lightcyan+opacity(0.5),meshpen=nullpen);

real x(real t) {return 1+cos(t);} real y(real t) {return sin(t);} real z(real t) {return sqrt(4.0001-(1+cos(t))^2-(sin(t))^2);} path3 pf=graph(x,y,z,0,2*pi,operator ..); draw(pf,red);

Black Mild
  • 17,569
PT Sinh
  • 49

1 Answers1

15

Welcome to TeX.SE!!

I know you're looking for an asymptote solution. But, meanwhile I left here a very simple TikZ one:

\documentclass[tikz,border=2mm]{standalone}
\usetikzlibrary{perspective}

\tikzset { cylinder back/.style={left color=blue,right color=white,fill opacity=0.3}, cylinder front/.style={left color=white,right color=blue,fill opacity=0.6}, sphere/.style={shading=ball,ball color=red,fill opacity=0.7} }

\begin{document} \begin{tikzpicture}[isometric view,rotate around z=180,line join=round] % tangent points \coordinate (R1) at ({cos(135)},{1+sin(135)},0); % right, bottom \coordinate (L2) at ({cos(-45)},{1+sin(-45)},{sqrt(2-2sin(-45))}); % left, top % base circle \draw[gray] (0,0) circle (2); % cylinder \draw[cylinder back] (R1) arc (135:315:1) -- (L2) -- plot[domain=315:135,samples=37]({cos(\x)},{1+sin(\x)},{sqrt(2-2sin(\x))}) -- cycle; \draw[cylinder front] (R1) arc (135:-45:1) -- (L2) -- plot[domain=-45:135,samples=37]({cos(\x)},{1+sin(\x)},{sqrt(2-2sin(\x))}) -- cycle; % sphere
\draw[sphere] (0,2) arc (90:-45:2) arc (180:0:2cm) arc (135:90:2) plot[domain=0:360,samples=73]({cos(\x)},{1+sin(\x)},{sqrt(2-2
sin(\x))}); \end{tikzpicture} \end{document}

enter image description here

Juan Castaño
  • 28,426