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.

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}$.
