In order to satisfy the following equality: $$a\cos{\theta}+b\sin{\theta}=r\cos{\left({x-x_0}\right)}$$
$x_0 = \tan^{-1}{\frac{b}{a}},$ and $a^2 + b^2 = r^2$. The latter statement implies $r = \pm\sqrt{a^2+b^2}$. (Harmonic addition theorem)
But how should you know whether to use the positive or negative $r$?
EDIT
Through testing, I was able to find that the sign of $r$ depends on the sign of $a$. But can someone help me understand why this is?