# Set up integral in spherical coordinates outside cylinder but inside sphere

I have the equation of a cylinder and the equation of a sphere given:

Cylinder: $x^2+y^2=4$

Sphere: $x^2+y^2+z^2=25$

I'm asked to set this up in cylindrical and spherical coordinates. Cylindrical was easy enough, but I'm having some trouble figuring out the limits for spherical.

My first thought: $\int\limits_0^{2\pi}\int\limits_0^\pi\int\limits_2^5\rho^2\sin\phi\ d\rho\ d\phi\ d\theta$

I thought that in spherical $\rho$ is basically the radius so setting it from 2 to 5 would exclude the area of the cylinder but apparently it is not that simple. Below is the answer my teacher gave and I'm not exactly sure what she did.

Correct integral in spherical: $2\int\limits_0^{2\pi}\int\limits_{cos^{-1}(\frac{\sqrt{21}}{5})}^{\pi/2}\int\limits_{2\csc(\phi)}^5\rho^2\sin\phi\ d\rho\ d\phi\ d\theta$

The picture when graphed is just a sphere with radius 5 and a cylinder that cuts through the middle. I'm not sure how my teacher got limits like $cos^{-1}(\frac{\sqrt{21}}{5})$ or $2\csc(\phi)$

The sphere and the cylinder intersect where $r=2$ and $\rho=5$, so $r=\rho\sin\phi\implies5\sin\phi=2\implies$

$\phi=\sin^{-1}\frac{2}{5}=\cos^{-1}\frac{\sqrt{21}}{5}$.

(Alternatively, $x^2+y^2=4$ and $x^2+y^2+z^2=25\implies$

$z^2=21\implies\rho^{2}\cos^{2}\phi=21\implies25\cos^{2}\phi=21\implies\cos\phi=\frac{\sqrt{21}}{5}\implies\phi=\cos^{-1}\frac{\sqrt{21}}{5}.)$

A line segment starting at the origin and passing through the cylinder intersects the cylinder where

$r=2$, so $\rho\sin\phi=2\implies \rho=\frac{2}{\sin\phi}=2\csc\phi$, so this gives the lower limit for $\rho$.