add tag
Anonymous 1123
I am trying to draw [SphericalWedge](https://mathworld.wolfram.com/SphericalWedge.html)
![ScreenHunter 45.png](/image?hash=1bfe8eba2b23569cbc1250a5e82119c8026a40b4368ddbe4e7c3074c916a1e70)

or [here](https://en.wikipedia.org/wiki/Spherical_wedge) 

![ScreenHunter 47.png](/image?hash=975aecca67eab4550f5a96c1cd8eec566a9c55c866417825592bfe82cb798f0f)

I tried
```
\documentclass[tikz,border=3mm]{standalone}
\usetikzlibrary{3dtools}% https://github.com/marmotghost/tikz-3dtools
\begin{document}
\begin{tikzpicture}[3d/install view={phi=110,theta=70},scale=1,line cap=butt,
		line join=round,declare function={R=3;myangle=-10;}] \path
		(0,0,0) coordinate (O)
		({R*cos(myangle)},{R*sin(myangle)},0) coordinate (A)
			({R*cos(myangle + 30)},{R*sin(myangle + 30)},0) coordinate (B)
		;
		
		\draw[3d/screen coords] (O) circle[radius=R]; 
		\path pic{3d/circle on sphere={R=R,C={(O)},n={(0,0,1)}}}; 
	\foreach \p in {A,B}
	\draw[fill=black] (\p) circle (1.2 pt);
	\foreach \p/\g in {A/-90,B/-90}
	\path (\p)+(\g:3mm) node{$\p$};	
	\end{tikzpicture}
\end{document}  
```
![ScreenHunter 46.png](/image?hash=11d947d0faba8d6c645f6ceb44b1892bb3982b93e09f7d5ab0951d92476e543c)
I can not draw two arcs passing through `A` and `B`. How can I draw SphericalWedge?
Top Answer
user 3.14159
This one is not (yet?) fully rotatable but computes the relevant critical angles. The problem with both of the screen shots posted in the question is either the horizontal circle is not the equator, or the corners of the wedge are not the poles. If the poles are at the uppermost and lowermost points of the circle representing the sphere, the equator is just a horizontal line. 

This code provides you with a consistent orthonormal projection, but has only been tested for certain ranges of the view angles. Also, `alpha` needs to be greater than `beta`, but this is just a convention (rather than a restriction).
```
\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 \myalpha/\mybeta in {0/-30,90/30,-30/-60}
{\begin{tikzpicture}[
	%declare function={R=2;alpha=0;beta=-30;},
	%declare function={R=2;alpha=90;beta=30;},
	declare function={R=2;alpha=\myalpha;beta=\mybeta;},
	compute critical angles/.code={
  % critical angles
  \pgfmathtruncatemacro{\itest}{nscreenz<0?0:1}
  \ifnum\itest=0
   \pgfmathsetmacro{\tcritA}{atan2(nscreenx*cos(alpha)+nscreeny*sin(alpha),-1*nscreenz)}
   \pgfmathsetmacro{\tcritB}{atan2(nscreenx*cos(beta)+nscreeny*sin(beta),-1*nscreenz)}
   \edef\tmin{90}
   \edef\tmax{-90}
  \else
   \pgfmathsetmacro{\tcritA}{atan2(nscreenx*cos(alpha)+nscreeny*sin(alpha),-1*nscreenz)-180}
   \pgfmathsetmacro{\tcritB}{atan2(nscreenx*cos(beta)+nscreeny*sin(beta),-1*nscreenz)-180}
   \edef\tmin{-90}
   \edef\tmax{90}
  \fi
  \path ({R*cos(alpha)*cos(\tcritA)},{R*sin(alpha)*cos(\tcritA)},{R*sin(\tcritA)}) 
   coordinate (pA)
   ({R*cos(beta)*cos(\tcritB)},{R*sin(beta)*cos(\tcritB)},{R*sin(\tcritB)})
   coordinate (pB);
  \pgfmathtruncatemacro{\mysign}{\pgfkeysvalueof{/tikz/3d/wedge/complement}==1?1:-1} 
  \pgfmathtruncatemacro{\itest}{screendepth(cos(alpha+\mysign*90),sin(alpha+\mysign*90),0)<0?0:1}
  \ifnum\itest=1
   \path[fill=gray!20,smooth] plot[variable=\t,domain=90:-90]
    ({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)});
   \draw[3d/hidden,smooth] plot[variable=\t,domain=\tcritA:\tmin]
	({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)}) -- 
	(0,0,{sign(\tmax)*R});
  \else
   \path[fill=gray!20,smooth,on layer=background] plot[variable=\t,domain=90:-90]
    ({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)});  	
   \draw[3d/hidden,smooth,on layer=background] plot[variable=\t,domain=\tcritA:\tmin]
	({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)}) -- 
	(0,0,{sign(\tmax)*R});
  \fi 
  \pgfmathtruncatemacro{\itest}{screendepth(cos(beta-\mysign*90),sin(beta-\mysign*90),0)<0?0:1}
  \ifnum\itest=1
   \path[fill=gray!20,smooth] plot[variable=\t,domain=90:-90]
    ({R*cos(beta)*cos(\t)},{R*sin(beta)*cos(\t)},{R*sin(\t)});
   \draw[3d/hidden,smooth] plot[variable=\t,domain=\tcritB:\tmin]
	({R*cos(beta)*cos(\t)},{R*sin(beta)*cos(\t)},{R*sin(\t)}) -- 
	(0,0,{sign(\tmax)*R});
  \else	
   \path[fill=gray!20,smooth,on layer=background] plot[variable=\t,domain=90:-90]
    ({R*cos(beta)*cos(\t)},{R*sin(beta)*cos(\t)},{R*sin(\t)});
   \draw[3d/hidden,smooth,on layer=background] plot[variable=\t,domain=\tcritB:\tmin]
	({R*cos(beta)*cos(\t)},{R*sin(beta)*cos(\t)},{R*sin(\t)}) -- 
	(0,0,{sign(\tmax)*R});
  \fi 
	},3d/wedge/.cd,complement/.initial=0,
	/tikz/.cd,fill opacity=0.8]
 %
 \begin{scope}[3d/install view={phi=110,psi=0,theta=70}]
  \tikzset{3d/wedge/complement=1,compute critical angles}
  \path[save named path=wedge,smooth] plot[variable=\t,domain=\tcritA:\tmax]
	({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)})
	-- plot[variable=\t,domain=\tmax:\tcritB]
	({R*cos(beta)*cos(\t)},{R*sin(beta)*cos(\t)},{R*sin(\t)})
    [3d/screen coords] let \p1=(pA),\p2=(pB),
    \n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)} in
  	 arc[start angle=\n2,end angle=\n1,radius=R];
  \path[3d/visible,3d/screen coords] circle[radius=R]; 	 
  \begin{scope}
   \clip[use named path=wedge]; 
   \path[3d/visible,3d/screen coords,ball color=blue] circle[radius=R]; 
  \end{scope}	 
  \draw[use named path=wedge]; 
  \draw[3d/visible,3d/screen coords] circle[radius=R]; 
  \draw[3d/hidden/.append style={on layer=background}] 
  	pic{3d/circle on sphere={R=2,n={(0,0,1)}}};	
 \end{scope} 
 %	
 \begin{scope}[3d/install view={phi=110,psi=0,theta=70},xshift=5cm]
  \tikzset{compute critical angles}
  \draw[3d/hidden,smooth] plot[variable=\t,domain=\tcritA:\tmin]
   ({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)}) -- 
   (0,0,{sign(\tmax)*R});
  \path[save named path=wedge,smooth] plot[variable=\t,domain=\tcritA:\tmax]
	({R*cos(alpha)*cos(\t)},{R*sin(alpha)*cos(\t)},{R*sin(\t)})
	-- plot[variable=\t,domain=\tmax:\tcritB]
	({R*cos(beta)*cos(\t)},{R*sin(beta)*cos(\t)},{R*sin(\t)})
    [3d/screen coords] let \p1=(pA),\p2=(pB),
    \n1={atan2(\y1,\x1)},\n2={atan2(\y2,\x2)} in
  	 arc[start angle=\n2,end angle=\n1,radius=R];
  \begin{scope}
   \clip[even odd clip,3d/screen coords,use named path=wedge] circle[radius=R];  
   \path[3d/visible,3d/screen coords,ball color=blue] circle[radius=R]; 
  \end{scope}	 
  \draw[use named path=wedge]; 
  \draw[3d/visible,3d/screen coords] circle[radius=R]; 
  \draw[3d/hidden/.append style={on layer=background}] 
  	pic{3d/circle on sphere={R=2,n={(0,0,1)}}};	
 \end{scope}
\end{tikzpicture}}
\end{document}
```
![ani.gif](/image?hash=1c8bce4a52de47d8d8fb3467336871477fa54f25652e665ef439c04cd142a7da)
Answer #2
joulev
Before marmot comes up with an excellent, fully 3d solution, which should definitely be preferred over this one, I will just post here a 3d-ish 2d solution for fun :) (after all 99% of 3d Ti*k*Z figures in the world are just 2d faking 3d anyway)

```
\documentclass[tikz,margin=3mm]{standalone}
\usetikzlibrary{intersections,calc}
\begin{document}
\begin{tikzpicture}
    \fill[gray!20] (0,-3) arc (270:90:.7cm and 3cm);
    \fill[gray!50] (0,-3) arc (270:90:.7cm and 3cm)
                          arc (90:270:1.5cm and 3cm);
    \draw (0,0) circle (3cm);
    \draw[dashed] (0,-3) -- (0,3);
    \draw[dashed] (3,0) arc (0:180:3cm and .5cm);
    \draw[name path=hori] (3,0) arc (0:-180:3cm and .5cm);
    \draw[name path=ver1] (0,-3) arc (270:90:.7cm and 3cm);
    \draw[name path=ver2] (0,-3) arc (270:90:1.5cm and 3cm);
    \draw[dashed,name intersections={of=hori and ver1,by=x}] (x) -- (0,0)
        node[midway,below right,inner sep=1pt] {$r$};
    \draw[dashed,name intersections={of=hori and ver2,by=y}] (y) -- (0,0);
    \draw[<-] ($($(x)!.3!(y)$)!.55!(0,0)$) to[bend left=30] ++ (1,1)
        node[right] {$\theta$};
\end{tikzpicture}
\end{document}
```

![image.png](/image?hash=b11c72e54e0d75c9890995dc7e5f6c5bd330569548252a9351c8d7f5173032f9)

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.