如何删除圆柱体内的球体?

如何删除圆柱体内的球体?

在此处输入图片描述请帮帮我,我想删除圆柱体内的球体。我该怎么做?这是我的代码。

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

答案1

欢迎来到 TeX.SE!!

我知道你在寻找渐近线解决方案。但与此同时,我在这里留下了一个非常简单的 TiZ一:

\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-2*sin(-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-2*sin(\x))}) -- cycle; 
  \draw[cylinder front] (R1) arc (135:-45:1) -- (L2) --
     plot[domain=-45:135,samples=37]({cos(\x)},{1+sin(\x)},{sqrt(2-2*sin(\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}

在此处输入图片描述

相关内容