I am trying to draw [A sphere is inscribed in a truncated right circular cone](https://artofproblemsolving.com/wiki/index.php/2014_AMC_10B_Problems/Problem_23)

I tried

\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,3dtools}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=110,psi=0,theta=60},
scale=1,transform shape,
line cap=round,line join=round,
declare function={R=4;r=3/2;h=2*R*r/(R-r);rs=sqrt(R*r);}]
\path pic{3d/frustum={R=R,r=r,h=h}};
\path
(0,0,0) coordinate (O)
(0,0,h) coordinate (O')
(0,0,h/2) coordinate (I);
\begin{scope}[shift={(I)}]
\end{scope}
\end{tikzpicture}
\end{document}

I get
![ScreenHunter 16.png](/image?hash=a1b618a68cf89cd2b276051127182f7b8532f2cd61fe4a4b4578bcfbc06ec281)
How to correct dashed line or fill it?

![ScreenHunter 17.png](/image?hash=c6e25843291fb9f6c143cb2076c85530b96914a934bd5dfcaf2d632f54bd690a)

![ScreenHunter 18.png](/image?hash=dbc48291e94295c9d24c486f9a2e9833b3f434c8bd9d61ab5888aefc4b2f3bc8)
This uses the frustum, and disects its foreground path into segments that can be used for clippings.

\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,3dtools}%https://github.com/marmotghost/tikz-3dtools
% these are used to disect the foreground paths of the frustum
\newcounter{ipath}
\tikzset{step ipath/.code={\stepcounter{ipath}},
save multiple paths/.style={step ipath,
save named path={#1-\number\value{ipath}}
}}
\begin{document}
\pgfdeclarelayer{background}
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\foreach \Angle in {60,65,...,120,115,110,...,65}
{\begin{tikzpicture}[3d/install view={phi=110,psi=0,theta=\Angle},
same bounding box=A,
line cap=round,line join=round,fill opacity=0.5,
declare function={a=1;r=a*(3+sqrt(5))/2;rs=sqrt(a*r);h=2*rs;R=r;}]
\setcounter{ipath}{0}
\path[3d/visible/.append style={save multiple paths=F,on layer=foreground}]
pic{3d/frustum={R=R,r=a,h=h}};
\path (0,0,h/2) coordinate (I);
\pgfmathtruncatemacro{\itest}{1+sign(screendepth(0,0,1))}
\typeout{\itest}
\ifcase\itest
\begin{scope}
\clip[even odd clip,use named path=F-2,generous outside path];
\fill[left color=gray!80!black,right color=gray!60!black,
\end{scope}
\fill[gray,use named path=F-2];
\begin{scope}
\clip[use named path=F-2];
\end{scope}
\or
\fill[left color=gray!80!black,right color=gray!60!black,
\or
\begin{scope}
\clip[even odd clip,use named path=F-2,generous outside path];
\fill[left color=gray!80!black,right color=gray!60!black,
\end{scope}
\fill[gray,use named path=F-2];
\begin{scope}
\clip[use named path=F-2];
\end{scope}
\fi
\end{tikzpicture}}
\end{document}

![ani.gif](/image?hash=166e8f612dca16ee65aab399d59aba0d6f61560ee63223b5bdd85afba0758d0b)

P.S. This animated gif does not have the glitches which many of my previously posted animations have (but it is still far from perfect). To remove the glitches, I used a conversion script of the form

pdftoppm -r $1$3.pdf tmp_ppm_pic
convert -density $1 -delay$2 -loop 0 -alpha remove tmp_ppm_pic-*.ppm animated.gif
rm -f tmp_ppm_pic-*.ppm

where the parameters are

$1: resolution$2: delay (larger values correspond to slower animations)
\$3: name of the pdf file