Triple integration, sphere (electric field). The sphere $K\subseteq R^3$ with radius $R$ has a homogeneous charge density $\rho$. Find the electric field E, produced by K outside of, meaning, find the integral 
$$E(p)=\int_K\rho\frac{p-q}{\|p-q\|^3}d^3q$$  with $p\notin K. $
I was thinking of doing a triple integral in sphereical coordinates, but I am uncertain about the boundaries of the integral for r. 
$$ \int_0^{2\pi}\int_0^\pi\int_R^\infty\rho\frac{p-q}{\|p-q\|^3}r^2\sin(\theta)drd\theta d\phi. $$ 
I saw the same question asked in Physics.SE, but it didn't get a finished answer. 
Here's how far they got there: 
$\int_0^{2\pi}\int_0^\pi\int_o^R\rho\frac{\frac{p-q}{\|p-q\|}}{\|p\|^2+\|q \|^2-2cos(\theta)\|p\|\|q\|}\|q\|^2sin(\theta)dqd\theta d\phi$. 
I just wanted to post this here, because I had a similar integral in a math test couple weeks ago and couldn't find an answer back then. And I think the integral has more correlation to mathematics than physics in this case. 
Anyway, my idea was to replace $\frac{p-q}{\|p-q\|}$ with $cos(\phi)$ because I saw somewhere that a unit vector can be replace by it. But when I tried to integrate it (just to make it clear I used an online integration calculator) it couldn't be solved with non-complex solutions. 
So I suppose my step there was wrong. 
By the way, here is the post from Physics.SE: https://physics.stackexchange.com/questions/185711/electric-field-outside-a-sphere#. 
Any ideas there? 
 A: METHOD 1:
First note that we can write $\vec E(\vec p)=-\nabla \Phi(\vec p)$.  We also establish a coordinate system so that $\hat p$ is the polar axis.  Thus, we can simplify the integral substantially by writing
$$\begin{align}
\vec E(\vec p)&=\frac{1}{4\pi \epsilon_0} \int_V \rho(\vec q) \frac{\vec p-\vec q}{(p^2+q^2-2\vec p\cdot \vec q)^{3/2}} dV_q\\\\
&=-\frac{\rho}{4\pi \epsilon_0}\nabla \int_0^{2\pi}\int_0^{\pi}\int_0^R \frac{1}{\sqrt{p^2+q^2-2pq\cos \theta}} q^2\sin \theta \,dq\,d\theta \,d\phi\\\\
&=-\frac{\rho}{2 \epsilon_0}\nabla \int_0^{\pi}\int_0^R \frac{1}{\sqrt{p^2+q^2-2pq\cos \theta}} q^2\sin \theta \,dq\,d\theta \\\\
&=-\frac{\rho}{2 \epsilon_0}\nabla\,\frac{1}{p}\int_0^R\,q\left((p+q)-|p-q|\right)\,dq\\\\
&=\hat p\,\frac{\rho}{3\epsilon_0}\frac{r^3_{<}}{p^2}
\end{align}$$
where $r_{<}=p$ if $p<R$ and $r_{<}=R$ if $p>R$.

METHOD 2:
You can expand the Green's function in spherical harmonic basis functions $Y_{lm}$,and integrate term by term.  The Green's function can be expanded as
$$\frac{1}{4\pi|\vec p-\vec q|}=\sum_{\mathscr{l}=0}^{\infty}\frac{1}{2\mathscr{l}+1}\frac{r_{<}^{\mathscr{l}}}{r_{>}^{\mathscr{l}+1}}\,\sum_{m=-\mathscr{l}}^{\mathscr{l}}Y_{\mathscr{l}m}(\theta,\phi)Y^*_{\mathscr{l}m}(\theta',\phi')$$
where $Y_{\mathscr{l}m}(\theta,\phi)$ are the spherical harmonics.  Inasmuch as the spherical harmonics are orthonormal, the integration over the solid angle of the sphere is trivial as is the integration over the radial variable.  The exercise is left to the reader.

METHOD 3:
A very simple and elegant way to determine the electric field is to exploit symmetry and use Gauss's law.  To that end, note that since $\rho=\rho(p)$ and is independent of both $\theta$ and $\phi$, we infer that the Electric Field will also depend only on $p$ so that $\vec E=\vec E(p)$. In addition, symmetry arguments suggest that the Electric Field will have only a radial component.  Thus, $\vec E(\vec p)=\hat p E_p(p)$.
Next, the charge $Q$, inside a sphere of radius $p$, centered at the origin, is 
$$Q=4\pi r_{<}^3\rho/3 \tag1$$ 
where $r_{<}=p$ if $p<R$ and $r_{<}=R$ if $R<p$.
Recalling that $\vec E(\vec p)=\hat p E_p(p)$, and letting $S$ be the sphere of radius $p$ centered at the origin, we have from Gauss's Law
$$\begin{align}
\oint_S \vec E(\vec p)\cdot \hat n\,dS&=\int_0^{2\pi}\int_0^{\pi}E_p(p)\hat p\cdot \hat p p^2\sin\theta d\theta d\phi\\\\
&=4\pi p^2E_p(p)\\\\
&=4\pi r_{<}^3\frac{\rho}{3\epsilon_0}
\end{align}$$
Solving for $E_p$ yields
$$\vec E(\vec p)=\hat p \frac{\rho}{3\epsilon_0}\frac{r_{<}^3}{p^2}$$
