add tag
Anonymous 1123
I am trying to draw a Spherical Cone [like this](https://mathworld.wolfram.com/SphericalCone.html) 
![ScreenHunter 50.png](/image?hash=53952a647168d62f18ba543dda8e7a9ca9992bb208c19276f3b148254509ddb6)

I only draw 

```
\documentclass[border=2mm,tikz]{standalone}
\usepackage{tikz-3dplot}
\usetikzlibrary{calc,backgrounds}
\usepackage{pgfplots}
\begin{document}
	%polar coordinates of visibility
	\pgfmathsetmacro\th{65}
	\pgfmathsetmacro\az{110}
	\tdplotsetmaincoords{\th}{\az}
	%parameters of the cone
	\pgfmathsetmacro\r{3} %radius of sphere
	\pgfmathsetmacro\R{(2 * sqrt(2) * \r) / 3} %radius of base
	\pgfmathsetmacro\v{(4 * \r) / 3} %hight of cone
	\begin{tikzpicture} [scale=1, tdplot_main_coords, axis/.style={blue,thick}]
	\path
	coordinate (O) at (0,0,0)
	coordinate (I) at (0,0,{sqrt(\r*\r - \R*\R)})
	coordinate (B) at (0,\R,0)
	coordinate (A) at (60:\R)
	coordinate (S) at (0,0,\v)
	coordinate (C) at  ($(O)-(A)$)
	coordinate (M) at ($(A)!.5!(B)$)
	coordinate (H) at ($(M)!1/2!(S)$)
	;
	
	\foreach \v/\position in { O/left,A/below,S/right,I/left} {\draw[draw =black, fill=black] (\v) circle (1pt) node [\position=0.2mm] {$\v$};
	}
	
		\draw[dashed] (S)--(O)  --(A)-- cycle (I) -- (A);
	\pgfmathsetmacro\cott{{cot(\th)}}
	\pgfmathsetmacro\fraction{\R*\cott/\v}
	
	\pgfmathsetmacro\fraction{\fraction<1 ? \fraction : 1}
	
	\pgfmathsetmacro\angle{{acos(\fraction)}}
	
	% % angles for transformed lines
	\pgfmathsetmacro\PhiOne{180+(\az-90)+\angle}
	\pgfmathsetmacro\PhiTwo{180+(\az-90)-\angle}
	
	% % coordinates for transformed surface lines
	\pgfmathsetmacro\sinPhiOne{{sin(\PhiOne)}}
	\pgfmathsetmacro\cosPhiOne{{cos(\PhiOne)}}
	\pgfmathsetmacro\sinPhiTwo{{sin(\PhiTwo)}}
	\pgfmathsetmacro\cosPhiTwo{{cos(\PhiTwo)}}
	
	% % angles for original surface lines
	\pgfmathsetmacro\sinazp{{sin(\az-90)}}
	\pgfmathsetmacro\cosazp{{cos(\az-90)}}
	\pgfmathsetmacro\sinazm{{sin(90-\az)}}
	\pgfmathsetmacro\cosazm{{cos(90-\az)}}
	
	\draw[dashed] (0,0,\v) -- (\R*\cosPhiOne,\R*\sinPhiOne,0);
	\draw[dashed] (0,0,\v) -- (\R*\cosPhiTwo,\R*\sinPhiTwo,0);
	
\begin{scope}[canvas is xy plane at z=0]
\draw[dashed] (\tdplotmainphi:\R) arc(\tdplotmainphi:\tdplotmainphi+180:\R);

\draw[thick] (\tdplotmainphi:\R) coordinate(BR) arc(\tdplotmainphi:\tdplotmainphi-180:\R) coordinate(BL);
\end{scope}
	
	
\begin{scope}[tdplot_screen_coords, on background layer] 
\draw[thick] (I) circle (\r); 
%\fill[ball color=orange,opacity=1] (T) circle (\myr); 
\end{scope}
\end{tikzpicture}
\end{document}
```
How to get the correct result?
Top Answer
user 3.14159
This is a code that works for many angles, but not for all. The reason that it does not work for all is that Ti*k*Z has conventions of returning angles that regularly cause headache for me. In principle it should be easy to fix this, but at this point I do not have time for that. The view angle chosen in your screen shot works, of course.

On the bright side I added some functional shading that allows one to shade cones. The shading is not really realistic, but perhaps better than nothing. I benefitted a lot from [this post](https://tex.stackexchange.com/a/333409) when creating the shading. You will need the latest version of `3dtools`.

```
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{calc,decorations.pathreplacing,3dtools}%https://github.com/marmotghost/tikz-3dtools
\begin{document}
\pgfdeclarelayer{background} 
\pgfdeclarelayer{foreground}
\pgfsetlayers{background,main,foreground}
\foreach \Angle in {5,15,...,235} 
{\begin{tikzpicture}[declare function={R=2;},line cap=round,line join=round,
	sphere/.style={ball color=blue,3d/screen coords,fill opacity=0.8,
		insert path={(0,0) circle[radius=R]}}]
 \begin{scope}[3d/install view={phi=110,psi=0,theta=\Angle}]
  \path  (0,0,0) coordinate (O) (0,0,1) coordinate (P);
  \draw[stored path/reset coordinate index,
  	3d/hidden/.style={store path=bg},
  	3d/visible/.append style={on layer=foreground}]   	
	pic{3d/circle on sphere={R=2,P={(P)}}};	
  \pgfmathtruncatemacro{\Nhid}{tikztdindexoflastcoordinate}
  \ifnum\Nhid>0
   \path[stored path/first coordinate of=bg] coordinate (bg0)
	 [stored path/last coordinate of=bg] coordinate (bg1);
  \fi	
  \draw[stored path/reset coordinate index,
  	3d/hidden/.append style={on layer=background},
  	3d/visible/.style={store path=fg}]		
	pic{3d/circle on sphere={R=2,P={(P)}}};	
  \pgfmathtruncatemacro{\Nvis}{tikztdindexoflastcoordinate}	
  \ifnum\Nvis>0
   \path[stored path/first coordinate of=fg] coordinate (fg0)
	 [stored path/last coordinate of=fg] coordinate (fg1);
  \fi	
  \pgfmathtruncatemacro{\itest}{(\Nhid>0?1:0)+(\Nvis>0?2:0)}
  \begin{scope}[3d/screen coords]
   \ifcase\itest
	% no path
   \or
	% only hidden
	\begin{scope}[on layer=background]
	 \clip[stored path/restore path=bg];
	 \path[sphere,ball color=gray];
	\end{scope}
   \or
	% only visible
	\begin{scope}[on layer=foreground]
	 \clip[stored path/restore path=fg];
	 \path[sphere];
	\end{scope} 
   \or
    \begin{scope}[on layer=background]
	 \clip let \p1=(bg0),\p2=(bg1),\n1={Mod(atan2(\y1,\x1),360)},
	 	\n2={Mod(atan2(\y2,\x2),360)}
	  in (bg0) [stored path/append path=bg] -- (bg1)
	  arc[start angle=\n2,end angle=\n1,radius=R] -- cycle;
	 \path[sphere,ball color=gray]; 
	\end{scope}
    \begin{scope}[on layer=foreground]
	 \clip let \p1=(fg0),\p2=(fg1),\n1={Mod(atan2(\y1,\x1),360)},
	 	\n2={Mod(atan2(\y2,\x2),360)}
	  in (fg0) [stored path/append path=fg] -- (fg1)
	  arc[start angle=\n2,end angle=\n1,radius=R] -- cycle;
	 \path[sphere]; 
	\end{scope}
   \fi
  \end{scope}
  \pgfmathsetmacro{\myh}{tddistance("(O)","(P)")}
  \pgfmathsetmacro{\myr}{sqrt(R*R-\myh*\myh)}
  \path (P) pic{3d/shaded cone={r=\myr,h=-\myh}};
  \draw[3d/visible,3d/screen coords] circle[radius=R];
 \end{scope} 
\end{tikzpicture}}
\end{document}
```
![ani.gif](/image?hash=55f00d5868b1392d193e32b8933cf2c29af6c63b295665b56221b6c6781b812a)

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.