# Simple Trig inverse problem

Suppose we have $x=\sin a \cos b, y=\sin a\sin b, z=\cos a$. I want to invert them to get $a,b$ in terms of $x,y,z$. At first sight it appears very simple, for example my first reaction would be to say that $a= \cos^{-1} z, b= \cos^{-1}{\left(x\over \sqrt{1-z^2}\right)}$. But it doesn't feel right for example that I used only $x,z$ for $b$ since $y$ also involves $b$. I think the inverse like this might not give the right range of angles, since where $\sin,\cos$ are positive don't necessarily overlap. How might I find $a,b$ in terms of more variables? I have to get $a$ to be unique in $(0,\pi)$ and $b$ unique in $(0,2\pi)$.

-
Your inverses are correct. There is no $y$ in the picture since $x$,$y$, $z$ are constrained to move on a sphere i.e. $x^2 + y^2 + z^2 = 1$. –  user17762 Mar 11 '12 at 22:31

$a= \cos^{-1} z$ and $\frac{y}{x} = \tan(b) \Rightarrow b=\tan^{-1} \frac{y}{x}$
Your formula is correct when $y$ is positive. But when $y$ is negative, $$b=2\pi -\arccos\left(\frac{x}{\sqrt{1-z^2}}\right).$$
Remark: Alternately, one can use $\arctan$ to almost compute $b$. But again adjustment needs to be made, depending on the sign of $y$. In a computing setting, you may be able to use the two-variable $\text{atan}$ function, which deals with the sign issue automatically.