Integration by Substitution with $~ t=\tan^{}\left( \frac{ \theta_{} }{ 2 } \right) ~$ The angle was halved I've been encountering the problem of the below integration.
$$  \int_{0 }^{2\pi  } \frac{  d\theta   }{  R+ r \cdot \cos^{}\left(\theta_{} \right)   }  \tag{1}   $$
The official description states that the above integration formula can be calculated using substitution of integration.
$$  t=\tan^{}\left( \frac{  \theta_{}   }{  2  }  \right)  $$
$$ \therefore ~~  \int_{0 }^{2\pi  } \frac{  d\theta   }{  R+ r \cdot \cos^{}\left(\theta_{} \right)   } = \frac{  2\pi   }{  \sqrt{ R ^{2} -r ^{2}  }   }    $$
Currently I can't derive the above RHS.
I think firstly find out the form of result of calculations of indefinite integral of eqn1 is wiser way.
What I tried so far are as below.
$$  t= \tan^{}\left( \frac{  \theta_{}   }{  2  }  \right)  $$
$$  \frac{  \theta_{}   }{  2  }= \tan^{-1} \left( t \right) ~~ \leftarrow~~ \text{Thought that this approach won't work}  $$
$$  \frac{  dt  }{  d\theta   } = \sec^{2}\left( \frac{  \theta_{}   }{  2  }  \right) \cdot \frac{1}{2}  $$
$$  \frac{  2dt  }{  d\theta   } = \sec^{2}\left( \frac{  \theta_{}   }{  2  }  \right)   $$
$$  \frac{  d\theta   }{  2 dt  } =\sec^{-2}\left( \frac{  \theta_{}   }{  2  }   \right)  $$
$$  \frac{  d\theta   }{  2 dt  } = \left( \sec^{}\left( \frac{  \theta_{}   }{  2  }  \right)    \right)^{-2}  $$
$$  \frac{  d\theta   }{  2 dt  } = \left( \cos^{-1}\left( \frac{  \theta_{}   }{  2  }  \right)    \right)^{-2}  $$
$$  \frac{  d\theta   }{  2 dt  } =  \cos^{2}\left( \frac{  \theta_{}   }{  2  }  \right)     $$
$$  d\theta = 2 dt \cdot \cos^{2}\left(\frac{  \theta_{}   }{  2  } \right)  $$
First things to first, the equation1 has $~ \cos^{}\left(\theta_{} \right)  ~$ however how can I handle $~  t=\tan^{}\left( \frac{  \theta_{}   }{  2  }  \right)   ~$ ??

Try to solve the problem using the following two equations:
\begin{equation}
\cos(2x)= 2\cos^2(x)-1, \\
\cos^2(x)= \frac{1}{1+ \tan^2(x)}. 
\end{equation}
It would be better if you would work on the problem by yourself now, however, I'll write a detailed answer below this line. If you don't want to read it then don't scroll further.

We want to calculate
$$
\int _0^{2\pi}\frac{d\theta}{R+ r\cos\theta}. 
$$
Set
$$
t= \tan\left(\frac\theta2 \right),
$$
then $\theta= 2\arctan(t)$, and hence
$$
d \theta= \frac{2}{1+t^2}d t. 
$$
Moreover,
$$
\cos\theta= \cos(2\arctan t)= 2\cos^2(\arctan t)-1 = \frac{2}{1+ \tan^2(\arctan t)}-1= \frac{2}{1+t^2}-1= \frac{1-t^2}{1+t^2}.
$$
Putting these together we have
\begin{equation}
\int _0^{2\pi}\frac{d\theta}{R+ r\cos\theta}= 2\int _0^{\pi}\frac{d\theta}{R+ r\cos\theta}= 2\int_0^{+\infty} \frac{\frac{2}{1+t^2}}{R+ r\frac{1-t^2}{1+t^2}} dt= 2\int_0^{\infty} \frac{2}{R(1+t^2)+r (1-t^2)}dt=  4\int_0^\infty\frac{dt}{(R+r)+ t^2(R-r)}= \frac{4}{R+r}\int_0^\infty\frac{dt}{1+ \frac{R-r}{R+r}t^2}= \frac{4}{\sqrt{R+r}\sqrt{R-r}}\int_0^\infty \frac{du}{1+u^2}= \frac{4}{\sqrt{R^2-r^2}}[\arctan u]\Big|_0^{+\infty}= \frac{2\pi}{\sqrt{R^2-r^2}},
\end{equation}
where we used the substitution $u= \frac{\sqrt{R-r}}{\sqrt{R+r}}t$.
