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

I only draw 

	%polar coordinates of visibility
	%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}]
	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\fraction{\fraction<1 ? \fraction : 1}
	% % angles for transformed lines
	% % coordinates for transformed surface lines
	% % angles for original surface lines
	\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);
\begin{scope}[tdplot_screen_coords, on background layer] 
\draw[thick] (I) circle (\r); 
%\fill[ball color=orange,opacity=1] (T) circle (\myr); 
How to get the correct result?
Top Answer
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]( when creating the shading. You will need the latest version of `3dtools`.

\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)}}};	
   \path[stored path/first coordinate of=bg] coordinate (bg0)
	 [stored path/last coordinate of=bg] coordinate (bg1);
  \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)}}};	
   \path[stored path/first coordinate of=fg] coordinate (fg0)
	 [stored path/last coordinate of=fg] coordinate (fg1);
  \begin{scope}[3d/screen coords]
	% no path
	% only hidden
	\begin{scope}[on layer=background]
	 \clip[stored path/restore path=bg];
	 \path[sphere,ball color=gray];
	% only visible
	\begin{scope}[on layer=foreground]
	 \clip[stored path/restore path=fg];
    \begin{scope}[on layer=background]
	 \clip let \p1=(bg0),\p2=(bg1),\n1={Mod(atan2(\y1,\x1),360)},
	  in (bg0) [stored path/append path=bg] -- (bg1)
	  arc[start angle=\n2,end angle=\n1,radius=R] -- cycle;
	 \path[sphere,ball color=gray]; 
    \begin{scope}[on layer=foreground]
	 \clip let \p1=(fg0),\p2=(fg1),\n1={Mod(atan2(\y1,\x1),360)},
	  in (fg0) [stored path/append path=fg] -- (fg1)
	  arc[start angle=\n2,end angle=\n1,radius=R] -- cycle;
  \path (P) pic{3d/shaded cone={r=\myr,h=-\myh}};
  \draw[3d/visible,3d/screen coords] circle[radius=R];

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.