tikz add tag
Anonymous 1123
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)}]
	\draw[tdplot_screen_coords,3d/hidden] (I) circle[radius=rs];
\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)
Top Answer
user 3.14159
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
    \draw[3d/screen coords,3d/hidden,ball color=blue] (I) circle[radius=rs];
	\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,
	 	 middle color=white,shading angle=70,use named path=F-1]; 
	\end{scope}	
    \fill[gray,use named path=F-2]; 
	\begin{scope}
	 \clip[use named path=F-2]; 
	 \draw[3d/screen coords,3d/visible,ball color=blue] (I) circle[radius=rs];
    \end{scope}
   \or
    \draw[3d/screen coords,3d/hidden,ball color=blue] (I) circle[radius=rs];
	 \fill[left color=gray!80!black,right color=gray!60!black,
	 	 middle color=white,shading angle=70,use named path=F-1]; 
   \or
	\begin{scope}
	 \clip[even odd clip,use named path=F-2,generous outside path]; 
	 \draw[3d/screen coords,3d/hidden,ball color=blue] (I) circle[radius=rs];
	 \fill[left color=gray!80!black,right color=gray!60!black,
	 	middle color=white,shading angle=70,use named path=F-1]; 
    \end{scope}
    \fill[gray,use named path=F-2]; 
	\begin{scope}
	 \clip[use named path=F-2]; 
	 \draw[3d/screen coords,3d/visible,ball color=blue] (I) circle[radius=rs];
    \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
```

This room is for discussion about this question.

Once logged in you can direct comments to any contributor here.

Enter question or answer id or url (and optionally further answer ids/urls from the same question) from

Separate each id/url with a space. No need to list your own answers; they will be imported automatically.