Calculation of $\int \sin^2 x\frac{\sin x-\cos x}{\sin x+\cos x}dx$ 
Calculation of $\displaystyle \int\frac{\sin^2 x\cos x}{
\sin x+\cos x}dx$ and $\displaystyle \int^{\pi}_{0}\frac{1}{1-2a\cos x+a^2}dx, ,0<a<1$

$\bf{Attempt}$ For (a) $\displaystyle \frac{1}{2}\int\frac{\sin^2 x\bigg[(\sin x+\cos x)+(\sin x-\cos x)\bigg]}{\sin x+\cos x}dx $
$\displaystyle =\frac{1}{4}\int (1+\cos 2x)dx+\frac{1}{2}\int \sin^2 x\frac{\sin x-\cos x}{\sin x+\cos x}dx$
could some help me how to solve $\displaystyle \int \sin^2 x\frac{\sin x-\cos x}{\sin x+\cos x}dx$
For (b) Can we solve it any geometrical way like taking unit circle . thanks
 A: For (a), 
\begin{eqnarray}
&&\int\frac{\sin^2 x\cos x}{\sin x+\cos x}dx\\
&=&\int \frac{\sin^2x(\cos^2x-\sin x\cos x)}{\cos^2x-\sin^2x}dx\\
&=&\frac14\int \frac{(1-\cos(2x))(1+\cos(2x)-\sin(2x))}{\cos(2x)}dx\\
&=&\frac14\int\frac{1-\cos^2(2x)-(1-\cos(2x))\sin(2x)}{\cos(2x)}dx\\
&=&\frac14\int(\sec(2x)-\cos(2x)-\tan(2x)+\sin(2x))dx\\
&=&\frac14(\frac12\ln(\frac{\cos x+\sin x}{\cos x-\sin x})-\frac12\sin(2x)+\frac12\ln(\cos (2x))-\frac12\cos(2x))+C\\
&=&\frac18(\ln(\frac{\cos x+\sin x}{\cos x-\sin x})-\sin(2x)+\ln(\cos(2 x))-\cos(2x))+C\\
&=&\frac18(2\ln(\cos x+\sin x)-\sin(2x)-\cos(2x))+C.
\end{eqnarray}
For (b), let $t=\tan\frac{x}{2}$ and then
\begin{eqnarray}
&&\int^{\pi}_{0}\frac{1}{1-2a\cos x+a^2}dx\\
&=&\int^{\pi}_{0}\frac{1}{1-2a\frac{1-\tan^2\frac x2}{1+\tan^2\frac x2}+a^2}dx\\
&=&\int_0^\infty\frac{1}{1-2a\frac{1-t^2}{1+t^2}+a^2}\frac{2}{1+t^2}dt\\
&=&\int_0^\infty\frac{1}{(1+a)^2t^2+(1-a)^2}dt\\
&=&\frac{2}{(1+a)^2}\int_0^\infty\frac1{t^2+(\frac{(1-a}{1+a})^2}dt\\
&=&\frac{2}{(1+a)^2}\frac{1+a}{1-a}\arctan\frac{t}{\frac{1-a}{1+a}}\bigg|_{0}^\infty\\
&=&\frac{\pi}{1-a^2}.
\end{eqnarray}
A: Hint:
$$1-2a\cos x+a^2 =e^{-ix}( e^{ix}(1+a^2)-a(e^{2ix}+1)) = \frac{z(1+a^2)-a(z^2+1)} z $$
with $e^{ix} = z$ that it $dx= \frac{-idz}{z}$
Hence, 
$$\displaystyle \int^{\pi}_{0}\frac{1}{1-2a\cos x+a^2}dx, =-i\int_{\gamma}\frac{dz}{z(1+a^2)-a(z^2+1)} ,0<a<1$$
Where, $$\gamma =\{e^{ix}: x\in (0,\pi)\}$$
Now consider $$\Gamma =\{e^{ix}: x\in (0,\pi)\}\cup [-1,1]$$
and apply Cauchy formula for 
$$\oint_{\Gamma}\frac{dz}{z(1+a^2)-a(z^2+1)} \equiv \oint_{\Gamma}f(z)dz = 2i\pi\sum Res(f,)$$
where, $$f(z)=\frac{1}{z(1+a^2)-a(z^2+1)}$$
So the only think remain is to compute the polar and Residues. can you take it from here?
