Can these definite integrals be expressed in closed form? In my research, I recently came across the integral
$$
I(a,b) = \int_{\theta_1}^{\theta_2} \frac{\sin^2 \theta}{(a \sin \theta - b \cos \theta)^2}\,\mathrm{d}\theta,
$$
where the range of integration $[\theta_1, \theta_2]$ is defined slightly differently in the two cases I'm interested in:


*

*Case I:  $[\theta_1, \theta_2] = \{ \theta \in [0, \pi]: a \sin \theta - b \cos \theta > 1 \}$

*Case II:  $[\theta_1, \theta_2] = \{ \theta \in [0, \pi]: a \sin \theta - b \cos \theta > b \}$


The constants $a$ and $b$ are positive, but other than that they are arbitrary.
In the case $b = 1$, these two cases are the same, the lower bound of integration is $\theta_1 = 2 \tan^{-1} (1/a)$, the upper bound is $\theta_2 = \pi$, and the integral evaluates to
$$
I(a,1) = \frac{a + (a^2 - 1) \tan^{-1} a}{(a^2 + 1)^2}
$$
(thanks to Mathematica.)  
However, I haven't been able to find nearly so nice an expression for the integrand in the cases where $b \neq 1$.  The bounds of integration can be found by solving a quadratic equation for $\cos \theta$, but the expressions aren't "nice".  Mathematica is little help, since it has trouble finding an antiderivative that works in both Quadrant I and Quadrant II.  (It also throws imaginary numbers into the results;  they cancel out when you simplify the resulting expressions, but are rather unsightly all the same.)
If all else fails, I can numerically integrate this;  but I'm wondering if there are any slick mathematical substitutions I can use to make my life easier.
 A: Hint:
Set $t=\tan \theta$ and note that
$$\cos^2\theta=\frac1{1+\tan^2\theta},\quad\sin^2\theta=\frac{\tan^2\theta}{1+\tan^2\theta},\quad \sin 2\theta=\frac{2\tan\theta}{1+\tan^2\theta}.$$
A: $a\sin\theta + b\cos\theta = \sqrt {a^2+b^2}\cos (\theta -\arctan \frac {a}{b})$
$\frac {1}{a^2+b^2} \int \sin^2\theta\sec^2(\theta - \arctan \frac {a}{b}) \ d\theta\\
\phi = \theta - \arctan \frac {a}{b}\\
\frac {1}{a^2+b^2} \int \sin^2(\phi+\arctan \frac {a}{b})\sec^2\phi \ d\theta\\
\frac {1}{a^2+b^2} \int (\sin\phi\cos\arctan \frac {a}{b} + \cos\phi\sin\arctan \frac {a}{b})^2\sec^2 \phi d\phi\\
\sin\arctan \frac {a}{b} = \frac {a}{\sqrt {a^2+b^2}},\cos\arctan \frac {a}{b} = \frac {b}{\sqrt {a^2+b^2}}\\
\frac {1}{a^2+b^2} \int \frac {b^2}{a^2+b^2}\sin^2\phi + \frac {2ab}{a^2+b^2}\sin\phi\cos\phi + \frac {a^2}{a^2+b^2}\cos^2\phi)\sec^2 \phi d\phi\\
\frac {1}{a^2+b^2} \int \frac {b^2}{a^2+b^2}\tan^2\phi + \frac {2ab}{a^2+b^2}\tan\phi + \frac {a^2}{a^2+b^2}d\phi\\
\frac {1}{a^2+b^2} \int \frac {b^2}{a^2+b^2}\sec^2\phi + \frac {2ab}{a^2+b^2}\tan\phi + \frac {a^2-b^2}{a^2+b^2}d\phi\\
\frac {1}{(a^2+b^2)^2} (b^2\tan\phi + 2ab \ln |\sec\phi| + (a^2-b^2)\phi)\\
\frac {1}{(a^2+b^2)^2} (b^2\tan(\theta_2 - \arctan \frac ab) - b^2\tan(\theta_1 - \arctan \frac ab) + 2ab \ln |\sec(\theta_2 - \arctan \frac ab)| - 2ab \ln |\sec(\theta_1 - \arctan \frac ab)| + (a^2-b^2)(\theta_2-\theta_1))$
A: The substitution $t = \tan \theta$ was awkward in this case, since the angles being integrated over were in both Quadrants I and II ($\theta \in [0, \pi]$), and so would have required splitting the range.  Instead, a substitution $u = \cot \theta$ (note that $\cot \theta$ is continuous over $[0,\pi]$) turned out to be effective:
$$
I(a,b) = \int_{\theta_1}^{\theta_2} \frac{\mathrm{d}\theta}{(a - b \cot \theta)^2} = - \int_{u_1}^{u_2} \frac{\mathrm{d}u}{(1 + u^2)(a - b u)^2}$$
The integrand can then be expanded in partial fractions:
$$
\frac{1}{(1+u^2)(a - bu)^2} = \frac{1}{(a^2 + b^2)^2} \left[\frac{b^2(a^2 + b^2)}{(a - bu)^2} + \frac{2 a b^2}{a - bu} + \frac{a^2 - b^2 + 2 a b u}{1 + u^2} \right]
$$
These individual terms can then be integrated using standard techniques.
