Find $\int^r_{-r} \sqrt{r^2 - x^2} \:dx$ where r is a positive constant. #2 Find $\int^r_{-r} \sqrt{r^2 - x^2} \:dx$ where r is a positive constant. 
This question is related to but different from Find $\int^r_{-r} \sqrt{r^2 - x^2} \:dx$ where r is a positive constant..

Textbook Solution
$\int^r_{-r} \sqrt{r^2 - x^2} \:dx$
Using $x = r\sin(\theta)$ it follows that $dx = r\cos(\theta) \:d\theta$. In addition we need to take into account that $x = \pm r$ results in $\theta = \pm \pi/2$. Therefore we get:
$\int^r_{-r} \sqrt{r^2 - x^2} \:dx = \int^{\pi/2}_{-\pi/2} r\cos(\theta)r\cos(\theta)\:d\theta$.

How did the textbook get from $\int^r_{-r} \sqrt{r^2 - x^2} \:dx$ to $\int^{\pi/2}_{-\pi/2} r\cos(\theta)r\cos(\theta)\:d\theta$? I understand how to get the change in the limits of integration, but I cannot find any way to reproduce $r\cos(\theta)r\cos(\theta)$ from $\sqrt{r^2 - x^2}$.
I would greatly appreciate it if people could please take the time to clarify this.
 A: Note that this is the equation of the upper half of a circle centred at the origin. The result should be $\frac{\pi r^2}{2}$, or half the area of a circle with radius $r$.
A: Integration by substitution for single variable works like this

Let $I\subseteq \mathbb{R}$ be an interval and $\phi:[a,b]\to I$ be a differentiable function with integrable derivative. Suppose that $f : I \to \mathbb{R}$ is a continuous function. Then
  $$\int_{\phi(a)}^{\phi(b)}f(x)~dx = \int_a^b f(\phi(t))\phi'(t)~dt$$

In the integral you give, setting $\phi(t)=r\sin t$ and $f(x) = \sqrt{r^2 - x^2}$ can simplify the integral for you to solve it. So, the limits of your integral will change accordingly i.e.
$$-r = \phi(a) = r\sin a \\ r = \phi(b) = r\sin b$$
So, $a = -\dfrac{\pi}{2}$ and $b = \dfrac{\pi}{2}$. Also, 
$$f(\phi(t))\phi'(t) = r\cos t \cdot r\cos t \tag{Using Pythagoras' theorem}$$
Now, your integral simplifies to
$$\int^r_{-r} \sqrt{r^2 - x^2} ~dx = \int_{-\pi/2}^{\pi/2} r\cos t \cdot r\cos t ~dt$$
Although you will rarely see people use substitution like this, it is worth knowing what is going on behind the scenes.
