# Calculating $\int_0^\pi \sin^2t\;dt$ using the residue theorem

I want to use the residue theorem to calculate $$I:=\int_0^\pi \sin^2t\;dt$$ Since $\sin^2$ is an even function, we've got $$I=\frac{1}{2}\int_0^{2\pi}\sin^2t\;dt$$

The solution of this exercise defines $$f(z):=\frac{1}{iz}\left(\frac{1}{2i}\left(z-\frac{1}{z}\right)\right)^2=-\frac{1}{4i}\left(z-\frac{2}{z}+\frac{1}{z^3}\right)$$ concludes that $$\operatorname{res}(f,0)=\left(-\frac{1}{4i}\right)\cdot (-2)=\frac{1}{2i}$$ and $$I=\frac{1}{2}\left\{2\pi i\cdot \frac{1}{2i}\right\}=\frac{\pi}{2}$$ I don't understand what they're doing; especially $f$ seems to have no relationship to the original integrand.

My approach was to try to write the integral as a contour integral: I hoped something like $$\frac{1}{2i}\int_{|z|=1}\frac{\sin^2z}{z}dz$$ would be worth a consideration. However, this integral is $0$; so, not exactly $I$.

Once you have written the integral as $I=\frac12\int_0^{2\pi}\sin^2t dt$, make the change of variables $z=e^{it}$, which gives $$dt=\frac{dz}{iz},\qquad \sin t=\frac{z-z^{-1}}{2i}.$$