Transforming linear combination of the cosine and sine function In the proof of Transforming $a\cos\left(\, x\,\right)+b\sin\left(\, x\right)$ to $r\cos\left(\,\phi - x\,\right)$
\begin{align}
a\cos\left(\, x\,\right) + b\sin\left(\, x\,\right)
&=\,\sqrt{\,a^{2} + b^{2}\,}\,
\left[\,\frac{a}{\,\sqrt{\, a^{2} + b^{2}\,}\,}\,\cos\left(\, x\,\right)
+\frac{b}{\,\sqrt{\, a^{2} + b^{2}\,}\,}\,\sin\left(\, x\,\right)\,\right]\,
\\[2mm]&=\,\sqrt{\,a^{2} + b^{2}\,}\,\left[\,
\cos\left(\,\phi\,\right)\cos\left(\, x\,\right) + \sin\left(\,\phi\,\right)\sin\left(\,x\,\right)
\,\right]
\\[2mm]&=\,\sqrt{\, a^{2} + b^{2}\,}\,\cos\left(\,\phi - x\,\right)
\end{align}
why did we factor out $\,\sqrt{\, a^{2} + b^{2}\,}\,$ where did this idea came from ?. It seems out of the blue.
 A: Start at "the other end" of the problem.  If we want
$$a\cos x+b\sin x=r\cos(\phi-x)$$
and we expand the right hand side, then what we are looking for is
$$a\cos x+b\sin x=r\cos\phi\cos x+r\sin\phi\sin x\ .$$
If this is to be true for all values of $x$ then we need
$$a=r\cos\phi\quad\hbox{and}\quad b=r\sin\phi\ .$$
Squaring and adding these equations,
$$a^2+b^2=r^2\cos^2\phi+r^2\sin^2\phi=r^2$$
and so
$$r=\sqrt{a^2+b^2}\ .$$
That's where the idea comes from to factor out $\sqrt{a^2+b^2}$.
A: The idea behind the proof comes from noting that 
$$\left(\dfrac{a}{\sqrt{a^2+b^2}}\right)^2+\left(\dfrac{b}{\sqrt{a^2+b^2}}\right)^2=1.\tag1$$
This is analogous to the Pythagorean identity 
$$\cos^2\phi+\sin^2\phi=1.\tag2$$
So for all $a$ and $b$ we can get an expression that satisfies $(2)$ by just factoring out $\sqrt{a^2+b^2}$, but in what way will this be useful? From $(1)$ and $(2)$ we can say that there exists an angle $\phi$ such that 
$$\cos\phi=\dfrac{a}{\sqrt{a^2+b^2}}\qquad\sin\phi=\dfrac{b}{\sqrt{a^2+b^2}},$$ or $$\cos\phi=\dfrac{b}{\sqrt{a^2+b^2}}\qquad\sin\phi=\dfrac{a}{\sqrt{a^2+b^2}}.$$
All of this will permit us to transform $a\cos x+b\sin x$ into an expression of the form 
$$\text{constant}\cdot(\sin\phi\cos x\pm\cos\phi\sin x),$$
or $$\text{constant}\cdot(\cos\phi\cos x\pm\sin\phi\sin x).$$
Those two are the result of the angle-addition formulas, which will enable us to write it in the form $r\cos(\phi\pm x)$ or $r\sin(\phi'\pm x)$.
In conclusion, the proof boils down to determining how to transform the coefficients of $\cos$ and $\sin$ such that they are exactly equal to the $\cos$ and $\sin$ of an angle. The rest follows from the angle-addition formulas.
