<s>[INST] Computing to volume of ball intersection with cone and another ball I am trying to calculate the integral $\ \int\int\int_V z dV $ where $\ V $ is the volume inside the ball $\ x^2 + y^2 + (z-2)^2 = 4 $ and also inside the cone $\ z^2 = x^2 + y^2 $ and outside the ball $\ x^2 + y^2 + z^2 = 4 $ .
So my attempt it to set the limits of $\ z $ integral from the lower ball to the higher ball. so $\ z $ should start at $\ \sqrt{4-x^2-y^2} $ and ends at $\ \sqrt{4-x^2-y^2} + 2 $ and the project of the intersection of cone with the ball is a circle with radius of $\ \sqrt{2} $ and so $ x $ will go from $\ - \sqrt{2-y^2} $ to $ \sqrt{2-y^2} $ and $\ y $ from $\ -\sqrt{2} $ to $ \sqrt{2} $
I don't know how to convert though. What should be $\ \theta, \phi , r $ ? trying to use the formula the outcome doesn't seem reasonable.
Thanks
 [/INST] $x = rsin\theta cos\phi$
$y = rsin\theta sin\phi$
$z = rcos\theta$
$x^2+y^2+z^2 = r^2$
$dxdydz = r^2sin\theta \ dr \ d\theta \ d\phi$ 
Case1:
$x^2+y^2+z^2 = r^2 = 4$
$$r = 2$$
Case2:
$x^2+y^2+(z-2)^2 = x^2+y^2+z^2 - 4z +4 = 4$
$r^2 - 4rcos\theta = 0$
$$r = 4cos\theta$$
(refer the graph for $r\not=0$)
$\theta$ varies from $0$ to $\pi/4$
and 
$\phi$ varies from $0$ to $2\pi$


Solution:
$ I = \int^{2\pi}_{\phi = 0} \ \int^{\pi/4}_{\theta = 0}\ \int^{4\cos\theta}_{r=2} r^3\cos\theta \ \sin\theta dr \ d\theta \ d\phi$
$I = [\int^{2\pi}_{\phi = 0}d\phi]\ \int^{\pi/4}_{\theta = 0}\bigg[\frac{r^4}{4}\bigg]^{4cos\theta}_2 sin\theta cos\theta d\theta$
$I = [2\pi].\frac{1}{4}\bigg[\int^{\pi/4}_{\theta = 0}\big[4^4cos^4\theta.cos\theta.sin\theta d\theta] + \int^{\pi/4}_{\theta = 0}\big[(-2^4)sin\theta.cos\theta.d\theta\big]\bigg]$
$I = \frac{\pi}{2}\bigg[\int^{\pi/4}_{\theta = 0}\big[4^4cos^5\theta d(- cos\theta)] + \int^{\pi/4}_{\theta = 0}\big[(-2^3)sin2\theta d\theta\big]\bigg]$
$I = \frac{\pi}{2}\bigg[\big[\frac{- 4^4cos^6\theta}{6}]^{\pi/4}_0 + 2^3\big[\frac{\cos 2\theta}{2}\big]^{\pi/4}_0\bigg]$
$I = \frac{\pi}{2}\bigg[\frac{-128}{3}(\frac{1}{8} -1) + 4(0 -1)\bigg]$
$I = \frac{\pi}{2}\big[\frac{112}{3} - 4 \big]$
$I = \frac{\pi}{2}(\frac{100}{3})$
Thus, $$I = \frac{50\pi}{3} $$

Proof of the value:
$x = rsin\theta cos\phi$
$y = rsin\theta sin\phi$
$z = rcos\theta$
Computing partial derivatives,
$x_r = sin\theta cos\phi \ , x_{\theta} = rcos\theta cos\phi \ , x_{\phi} = -rsin\theta sin \phi$
$y_r = sin\theta sin\phi \ , y_{\theta} = rcos\theta sin\phi \ , y_{\phi} = rsin\theta cos \phi$
$z_r = cos\theta  \ , z_{\theta} = -rsin\theta  , z_{\phi} = 0$
$J = \
\begin{vmatrix}
sin\theta cos\phi  & rcos\theta cos\phi  & -rsin\theta sin \phi \\
sin\theta sin\phi &  rcos\theta sin\phi  &  rsin\theta cos \phi \\
cos\theta & -rsin\theta & 0
\end{vmatrix} $
Expanding along third row, 
$J = cos\theta[r^2cos\theta sin\theta cos^2\phi \ + r^2cos\theta sin\theta sin^2\phi] + rsin\theta[rsin^2\theta cos^2\phi + rsin^2\theta sin^2\phi]$
$J = r^2sin\theta[cos^2\theta(cos^2\phi+sin^2\phi)] + r^2sin\theta[sin^2\theta(cos^2\phi+sin^2\phi)]$
$J = r^2sin\theta[cos^2\theta+sin^2\theta] = r^2sin\theta$
$$dxdydz = |J|dr d\theta d\phi = r^2sin\theta dr d\theta d\phi$$
</s>