Compute$\int_0^{2\pi}\frac{\cos^2\theta }{ |re^{i\theta} -z|^2}d\theta$ 
$r\gt0$, Compute
  $$\int_0^{2\pi}\frac{\cos^2\theta }{ |re^{i\theta} -z|^2}d\theta$$
  when $|z|\ne r$

The problem is related to Poisson kernel and harmonic function, but I don't know how to start, $\cos^2\theta =1/2 (1+\cos 2\theta )$.
 A: Express $z$ also in polar form, $z = s^{i\alpha}$. Then, 
$$|re^{i\theta} -z|^2=r^2+s^2-2rs\cos(\theta-\alpha)$$
and, with the variable change $t= \theta - \alpha$, the integral reads,
$$I=\int_0^{2\pi}\frac{\cos^2\theta }{ |re^{i\theta} -z|^2}d\theta
=\int_0^{2\pi}\frac{\cos^2(t+\alpha)}{ r^2+s^2-2rs\cos t}dt$$
Expand the numerator,
$$\cos^2(t+\alpha)= \frac12+\frac12 \cos2\alpha \cos2t+\frac12\sin2\alpha\sin 2t$$
to decompose the integral into three manageable pieces,
$$I=I_1+I_2+I_3\tag 1$$
where 
$$I_1=\frac12\int_0^{2\pi}\frac{ dt}{ r^2+s^2-2rs\cos t}=\frac{\pi}{|r^2-s^2|}
$$
$$I_2=\frac12\int_0^{2\pi}\frac{\cos2\alpha\cos 2t\> dt}{ r^2+s^2-2rs\cos t}
=\frac {\pi\cos2\alpha}{2r^2s^2|r^2-s^2|}\left(r^4+s^4-|r^4-s^4|\right)$$
$$I_3= \sin2\alpha\int_0^{2\pi}\frac{\cos t\sin tdt}{ r^2+s^2-2rs\cos t}
=0$$
(see derivations at end.) Plug the results into (1) to obtain
$$I=\int_0^{2\pi}\frac{\cos^2\theta d\theta }{ |re^{i\theta} -z|^2}
=\frac{\pi}{|r^2-s^2|}\left( 1+\cos2\alpha\frac{r^4+s^4-|r^4-s^4|}{2r^2s^2}\right)$$
Note that the results for $r>s$ and $r<s$ are respectively,
$$I_{r>s} =\frac{\pi}{r^2-s^2}\left( 1+\frac{s^2}{r^2}\cos2\alpha \right),\>\>\>\>\>
I_{r<s} =\frac{\pi}{s^2-r^2}\left( 1+\frac{r^2}{s^2}\cos2\alpha \right)$$

PS: Use $u = \tan\frac t2$ to integrate $I_1$ and use the result in $I_2$,
$$I_1=\frac12\int_0^{2\pi}\frac{ dt}{ r^2+s^2-2rs\cos t}
=\int_0^{\infty}\frac{du}{ (r-s)r^2+(r+s)^2u^2}$$
$$=\frac{2}{r^2-s^2}\tan^{-1}\left(\frac{r+s}{r-s}\right)\bigg|_0^\infty
=\frac{\pi}{|r^2-s^2|}
$$
$$I_2=\frac12\int_0^{2\pi}\frac{\cos2\alpha\cos2t\> dt}{ r^2+s^2-2rs\cos t}
=\cos2\alpha\left(\int_0^{2\pi}\frac{\cos^2t\> dt}{ r^2+s^2-2rs\cos t}-I_1\right)$$
$$=\cos2\alpha\left[\left(\frac{(r^2+s^2)^2}{2r^2s^2}-1\right) I_1 -\frac{1}{4r^2s^2} \int_0^{2\pi} (r^2+s^2-2rs\cos t)dt\right]$$
$$=\cos2\alpha\left[\frac{(r^4+s^4)^2}{2r^2s^2}\frac{\pi}{|r^2-s^2|}
-\frac{(r^2+s^2)\pi}{2r^2s^2}\right]$$
$$=\frac {\pi\cos2\alpha}{2r^2s^2|r^2-s^2|}\left(r^4+s^4-|r^4-s^4|\right)\tag 3
$$
A: Note that $\Re{\frac{r+ze^{-i\theta}}{r-ze^{-i\theta}}}=\frac{r^2-|z|^2}{|re^{i\theta} -z|^2}$, so the integral is $\frac{1}{r^2-|z|^2}\Re{\int_0^{2\pi}\frac{(r+ze^{-i\theta})\cos^2\theta }{ r-ze^{-i\theta}}}d\theta$
while if $r>|z|$ we have $\frac{r+ze^{-i\theta}}{r-ze^{-i\theta}}=1+2\sum_{k \ge 1}{\frac{z^k}{r^k}}e^{-ik\theta}$ and $4cos^2\theta=2+e^{2i\theta}+e^{-2i\theta}$ so 
${\int_0^{2\pi}\frac{(r+ze^{-i\theta})\cos^2\theta }{ r-ze^{-i\theta}}}d\theta=\pi+\frac{\pi z^2}{r^2}$ since we can integrate term by term by absolute convergence in $\theta$ and only two terms are non zero (the first and the one for $k=2$)
Hence the original integral is $\frac{\pi}{r^2-|z|^2}+\frac{\pi \Re z^2}{r^2(r^2-|z|^2)}$
If now $r<|z|$ (so $z \ne 0$) we have $\frac{r+ze^{-i\theta}}{r-ze^{-i\theta}}=-1-2\sum_{k \ge 1}{\frac{r^k}{z^k}}e^{ik\theta}$ and again integrating term by term we also have two terms, so the original integral is $\frac{\pi}{|z|^2-r^2}+\Re\frac{\pi r^2}{z^2(|z|^2-r^2)}$
Note that with $z=se^{i\alpha}$ we get precisely $\frac{\pi}{r^2-s^2}( 1+\frac{s^2cos 2\alpha}{r^2})$ for $r>s$ and the same expression with $r,s$ switched for $s>r$
