tikz add tag
Anonymous 1123
Let be a cone with hight `h` and radius of base is `r`. How can I draw a sphere  inscribed a cone? I know that, the center of sphere is incenter of the triangle `SAB` and radius of sphere is `(r*sqrt(h^2+r^2)-r^2)/h)`. 

![ScreenHunter 798.png](/image?hash=e613e1244061ff9a3d3ff2bd66de9379def4ad01792004668375d5de887140e2)
Top Answer
marmot
You did already the most complicated part, the computation of the radius. The rest is comparatively simple, also because I had a code for drawing cones on my hard drive anyway.

```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\tikzset{pics/3d/cone/.style={code={
	\tikzset{3d/cone/.cd,#1}
	\def\pv##1{\pgfkeysvalueof{/tikz/3d/cone/##1}}%
	\pgfmathsetmacro{\sdtip}{screendepth(0,0,\pv{h})}
	\pgfmathsetmacro{\aspectangle}{atan2(\sdtip,sqrt(\pv{h}*\pv{h}-\sdtip*\sdtip))}
	\path (0,0,\pv{h}) coordinate (-tip);
    \begin{scope}[x={(0,0,tan(\aspectangle))},y={($(0,0,0)!1cm!90:(0,0,\pv{h})$)}]
	 \pgfmathtruncatemacro{\itest}{abs(tan(\aspectangle)*\pv{r}/\pv{h})<1}
	 \ifnum\itest=1
	  \pgfmathsetmacro{\alphacrit}{acos(tan(\aspectangle)*\pv{r}/\pv{h})}
	  \ifdim\sdtip pt>0pt
	   \path[/tikz/3d/cone/hidden] (\alphacrit:\pv{r}) arc[start angle=\alphacrit,end
	   angle=-\alphacrit,radius=\pv{r}];
	   \path[/tikz/3d/cone/visible] (\alphacrit:\pv{r}) 
	   arc[start angle=\alphacrit,end  angle=360-\alphacrit,radius=\pv{r}]
	   -- (-tip) -- cycle;
	  \else
	   \path[/tikz/3d/cone/visible] circle[radius=\pv{r}];
	   \path[/tikz/3d/cone/visible] (\alphacrit:\pv{r}) 
	   -- (-tip) -- (360-\alphacrit:\pv{r});
	  \fi
	 \else
	  \path[/tikz/3d/cone/visible] circle[radius=\pv{r}];	 
	 \fi
    \end{scope}
	}},
	3d/cone/.cd,r/.initial=1,h/.initial=1,
	hidden/.style={draw,very thin,densely dashed},
	visible/.style=draw}
\begin{document}
\begin{tikzpicture}[,declare function={
 	r=1.5;h=2;rs=(r*sqrt(h^2+r^2)-r^2)/h);
 	}]
 \tdplotsetmaincoords{70}{110}
 \begin{scope}[tdplot_main_coords]
  \pic{3d/cone={r=r,h=h}};
  \path (0,0,rs) coordinate (cs);
 \end{scope}
 \draw[3d/cone/hidden] (cs) circle[radius=rs];
\end{tikzpicture}
\end{document}
```
![Screen Shot 2020-08-16 at 9.07.15 AM.png](/image?hash=0e076d4cb1514a9fc69ea92e31e345b58219648ccb9c31a85133d60f32dbac5b)

Of course, the sphere does not change its radius when altering the view angles, and the projection of a sphere on the screen is a circle of the radius of the sphere. So this circle won't change when we animate the view angles. 
```
\documentclass[tikz,border=3mm]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{3dtools}
\tikzset{pics/3d/cone/.style={code={
	\tikzset{3d/cone/.cd,#1}
	\def\pv##1{\pgfkeysvalueof{/tikz/3d/cone/##1}}%
	\pgfmathsetmacro{\sdtip}{screendepth(0,0,\pv{h})}
	\pgfmathsetmacro{\aspectangle}{atan2(\sdtip,sqrt(\pv{h}*\pv{h}-\sdtip*\sdtip))}
	\path (0,0,\pv{h}) coordinate (-tip);
    \begin{scope}[x={(0,0,tan(\aspectangle))},y={($(0,0,0)!1cm!90:(0,0,\pv{h})$)}]
	 \pgfmathtruncatemacro{\itest}{abs(tan(\aspectangle)*\pv{r}/\pv{h})<1}
	 \ifnum\itest=1
	  \pgfmathsetmacro{\alphacrit}{acos(tan(\aspectangle)*\pv{r}/\pv{h})}
	  \ifdim\sdtip pt>0pt
	   \path[/tikz/3d/cone/hidden] (\alphacrit:\pv{r}) arc[start angle=\alphacrit,end
	   angle=-\alphacrit,radius=\pv{r}];
	   \path[/tikz/3d/cone/visible] (\alphacrit:\pv{r}) 
	   arc[start angle=\alphacrit,end  angle=360-\alphacrit,radius=\pv{r}]
	   -- (-tip) -- cycle;
	  \else
	   \path[/tikz/3d/cone/visible] circle[radius=\pv{r}];
	   \path[/tikz/3d/cone/visible] (\alphacrit:\pv{r}) 
	   -- (-tip) -- (360-\alphacrit:\pv{r});
	  \fi
	 \else
	  \path[/tikz/3d/cone/visible] circle[radius=\pv{r}];	 
	 \fi
    \end{scope}
	}},
	3d/cone/.cd,r/.initial=1,h/.initial=1,
	hidden/.style={draw,very thin,densely dashed},
	visible/.style=draw}
\begin{document}
\foreach \Angle in {90,85,...,40,45,50,...,85}
{\begin{tikzpicture}[,declare function={
 	r=1.5;h=2;rs=(r*sqrt(h^2+r^2)-r^2)/h);
 	}]
 \path[use as bounding box] (-r,{r*cos(140)}) rectangle (r,h);
 \tdplotsetmaincoords{\Angle}{0}
 \begin{scope}[tdplot_main_coords]
  \pic{3d/cone={r=r,h=h}};
  \draw[3d/cone/hidden,canvas is xy plane at z=0] (00:r) -- (180:r);
  \path (0,0,rs) coordinate (cs);
 \end{scope}
 \draw[3d/cone/hidden] (cs) circle[radius=rs];
\end{tikzpicture}}
\end{document}
```
![ani.gif](/image?hash=72d88181867697d705180ee6f3ca64850a62d074cb0a0ba80db4fbdb02dc0e45)

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.