$ A\sin\alpha + B\cos\alpha=C$ solution confusion The solution of equation:
$$ A\sin\alpha + B\cos\alpha=C$$
according to python is:
$$\alpha=2\arctan\left[\frac{A \pm \sqrt{A^2+B^2-C^2}}{B+C}\right]$$
My question is why two answers or in otherwords in which situations we choose the postive and which the negative ? Can we get rid of the plus minus sign to outside of the function inside the $\arctan$ to outside?
 A: Starting with:
$$Asin(\alpha) + Bcos(\alpha) = C,$$
divide by $cos(\alpha)$ on both sides:
$$Atan(\alpha) + B = Csec(\alpha).$$
Then, square both sides:
$$A^2tan^2(\alpha) + 2ABtan(\alpha) + B^2 = C^2sec^2(\alpha).$$
Apply a variant of the Pythagorean identity to the RHS to get:
$$A^2tan^2(\alpha)+2ABtan(\alpha) + B^2 = C^2(tan^2(\alpha)+1).$$
Regroup to get quadratic in $tan(\alpha)$:
$$(A^2 - C^2)[tan(\alpha)]^2+(2AB)[tan(\alpha)] + (B^2-C^2) = 0.$$
Apply quadratic formula and simplify:
$$tan(\alpha) = \frac{-2AB\pm\sqrt{4A^2B^2 - 4(A^2-C^2)(B^2 - C^2)}}{2(A^2 - C^2)}$$
$$ = \frac{-AB\pm \sqrt{A^2B^2 - A^2B^2+A^2C^2+B^2C^2-C^4}}{A^2-C^2}$$
$$ = \frac{-AB\pm C\sqrt{A^2+B^2-C^2}}{A^2-C^2}.$$
Hence:
$$\alpha = arctan\bigg(\frac{-AB\pm C\sqrt{A^2+B^2-C^2}}{A^2-C^2}\bigg).$$

So the plus and minus comes from the quadratic formula and represents two arguments provided $A^2+B^2\neq C^2$ (i.e. that the discriminant is nonzero). If it is zero of course there is one argument for arctan. The $\pm$ can't pull out. The quadrant in which $\alpha$ lies depends on the sign of the numerator and denominator.
A: It helps to think about this problem geometrically. You can rewrite your equation as
$$(A,B) \cdot \hat{n} = C$$
where $\hat{n} = (\sin \alpha, \cos \alpha)$ is an unknown unit vector.
If $C$ is larger than $\|(A,B)\| = \sqrt{A^2+B^2}$ (or smaller than $-\|(A,B)\|$ ) then there is no solution. If $C$ is exactly equal to $\pm \sqrt{A^2+B^2}$, then there is a unique solution $\hat{n} = \pm \frac{(A,B)}{\|(A,B)\|}$.
Otherwise, there will be two solutions $\hat{n}_1$ and $\hat{n}_2$, which differ by reflection about the line through the origin in direction $(A,B)$. In other words, $\alpha = \alpha_0 \pm \beta$, where $\alpha_0 = \angle(A,B)$ and $\beta$ is to be determined using some trigonometry.
I am not sure how "Python" (some kind of Python-based symbolic equation package?) computed your formula, and I don't know an "arctangent sum" identity that immediately moves the $\pm$ outside the arctangent. But geometrically, it's clear the form that the two solutions must take.
A: All you have to do is express everything in terms of $tan(a/2)$.
Then setting the latter =$x$ we get a binomial:
$(C+B)x^2$$-$$2Ax+C-B=0$ which gives the roots that Python gave,
provided that $A^2+B^2-C^2$ is non-negative!
