In this question, it is shown that
$$A \sin(x) + B \cos (x) = R \sin ( x + \theta )$$
for $A,B$ real and positive, with
$$R = \sqrt{A^2 + B^2}$$
$$\theta = \arctan \left( \frac{B}{A} \right)$$
This is performed solving the system
$$\left\{ \begin{array}{c} R \cos (\theta) = A\\ R \sin (\theta) = B \end{array} \right. $$
for $R$ and $\theta$. What if, instead, $A$ and/or $B$ are real, but not positive?
Some trivial test on WolframAlpha shows that the $\arctan \left( \frac{B}{A} \right)$ term is computed the same way, considering the sign of $A$ and $B$.
$R$ is instead negative if $A$ or both $A$ and $B$ are negative. It is obtained by squaring and summing the two equations in the system and I can't figure out how a sign can be considered in this operation.
Let $A = R \cos \theta$ and $B = R \sin \theta$
So, $y = A \sin x + B \cos x = R \cos \theta \sin x+ R \sin \theta \cos x = R \sin(x + \theta)$
Also, $R^2 = A^2 + B^2$ or $R = \sqrt{A^2 + B^2}$
Let
$$\alpha = \tan^{-1} \left| \frac{B}{A} \right|$$
so that $\alpha \in [0,\pi/2]$
Let us assume $R$ to be always positive (conventional).
So we now have 4 cases.
CASE 1
$A \ge 0$ and $B \ge 0$
In this case, $R \cos \theta \ge 0$ and $R \sin \theta \ge 0$
Being $R>0$, this implies $\sin \theta \ge 0$ and $\cos \theta \ge 0$
So, $\theta \in [0 ,\pi/2]$
and
$$\alpha = \theta$$
CASE2
$A \le 0$ and $B \ge 0$
In this case, $R \cos \theta \le 0$ and $R \sin \theta \ge 0$
As $R>0$, $\sin \theta \ge 0$ and $\cos \theta \le 0$
So, $\theta \in [ \pi/2, \pi]$
$\alpha = \pi - \theta$
or $$\theta = \pi - \alpha$$
CASE3
$A \le 0$ and $B \le 0$
In this case, $R \cos \theta \le 0$ and $R \sin \theta \le 0$
As $R>0$, $\sin \theta \le 0$ and $\cos \theta \le0$
So, $\theta \in [ \pi, 3\pi/2]$ or $\theta \in [ -\pi/2, -\pi]$.
$$\alpha = \theta - \pi$$
or $$\theta = \alpha + \pi$$
CASE4
$A \ge 0$ and $B \le 0$
In this case, $R \cos \theta \ge 0$ and $R \sin \theta \le 0$
As $R>0$, $\sin \theta \le 0$ and $\cos \theta \ge 0$
So, $\theta \in [3\pi/2, 2\pi]$ or $\theta \in [-\pi/2,0]$.
$$\alpha = - \theta$$
or
$$ \theta = - \alpha$$
So, at last $$y = R \sin( x + \theta)$$
Find the signs of $A$ and $B$, then the principal value $\alpha$. Then according to the quadrant, find $\theta$ in terms of $\alpha$ and substitute in the above expression.