We know from the further trigonometry section that if we set:
\displaystyle t = \tan \frac x 2
(for x \ne \pi, 3 \pi, \ldots) then we have:
\displaystyle \sin x = \frac {2t} {1 + t^2}
and:
\displaystyle \cos x = \frac {1 - t^2} {1 + t^2}
We can use therefore use the substitution \displaystyle t = \tan \frac x 2 to rewrite trigonometric integrals as integrals of rational functions, (ie. fractions involving polynomials) which can succumb to straightforward integration techniques, like partial fractions.
Note that we have:
\displaystyle \frac {\mathrm dt} {\mathrm dx} = \frac 1 2 \sec^2 \frac x 2
To write this in terms of t, remember the identity:
\displaystyle 1 + \tan^2 \theta = \sec^2 \theta
Setting \theta = \dfrac x 2 and dividing by 2 we have:
\displaystyle \frac 1 2 \sec^2 \frac x 2 = \frac 1 2 \left(1 + \tan^2 \frac x 2\right) = \frac 1 2 \left(1 + t^2\right)
So we have:
\displaystyle \frac {\mathrm dt} {\mathrm dx} = \frac 1 2 \left(1 + t^2\right)
and so, informally:
\displaystyle \mathrm dx = \frac 2 {1 + t^2} \mathrm dt
We therefore have that, using integration by substitution:
\displaystyle \int f(\cos \theta, \sin \theta) \mathrm d\theta = 2 \int f \left(\frac {1 - t^2} {1 + t^2}, \frac {2t} {1 + t^2}\right) \frac {\mathrm dt} {1 + t^2}
for any suitable function f.
To take an explicit example, consider for example:
\displaystyle \int \frac 1 {\sin \theta + \cos \theta} \mathrm d\theta
Substituting \displaystyle t = \tan \frac x 2 we get:
\begin{align*}\int \frac 1 {\sin \theta + \cos \theta} \mathrm d\theta & = \int \frac 1 {\frac {2t} {1 + t^2} + \frac {1 - t^2} {1 + t^2}} \times \frac 2 {1 + t^2} \mathrm dt \\ & = 2 \int \frac 1 {2t + 1 - t^2} \mathrm dt\end{align*}
To evaluate this new integral, we can complete the square and write:
\begin{align*}2t + 1 - t^2 & = -(t^2 - 2t - 1) \\ & = -\left((t - 1)^2 - 2\right) \\ & = 2 - (t - 1)^2\end{align*}
So we have:
\displaystyle 2 \int \frac 1 {2 - (t - 1)^2} \mathrm dt
We want to apply the identity:
\displaystyle 2 \int \frac 1 {a^2 - x^2} \mathrm dx = \frac 1 a \ln \left|\frac {a + x} {a - x}\right| + C
Setting u = t - 1 our integral becomes:
\displaystyle 2 \int \frac 1 {\left(\sqrt 2\right)^2 - u^2} \mathrm du
So applying the above identity we have:
\begin{align*}\int \frac 1 {\sin \theta + \cos \theta} \mathrm d\theta & = 2 \int \frac 1 {\left(\sqrt 2\right)^2 - u^2} \mathrm du \\ & = \frac 1 {\sqrt 2} \ln \left|\frac {\sqrt 2 + u} {\sqrt 2 - u}\right| + C \\ & = \frac 1 {\sqrt 2} \ln \left|\frac {\sqrt 2 + t - 1} {\sqrt 2 - t + 1}\right| + C \\ & = \boxed{\frac 1 {\sqrt 2} \ln \left|\frac {\sqrt 2 + \tan \frac x 2 - 1} {\sqrt 2 - \tan \frac x 2 + 1}\right| + C}\end{align*}