TITLE: How do I calculate the angles between a point on a sphere and each unit vector in $\Bbb R ^3$?
QUESTION [0 upvotes]: Given the Cartesian coordinates of any point $p$ on the surface of a sphere in $\Bbb R ^3$, how do I calculate the angles between each axis $(x, y, z)$ and the vector $n$ defined by origin $o$ and $p$. 
For convenience sake I'll say that origin $o$ equals $(0,0,0)$ so that $n = p$
I begun my attempt by calculating the direction cosines, but now that I want to calculate the angles using inverse cosines, I realize that a sphere has eight octants and that cosines have 2 angles in some of them. 
Is there a more elegant way to solve this? And if so, how do I approach this?

REPLY [1 votes]: Suppose you have some point $p$ on your sphere. And the vector from the origin to that point is represented by:
$$\vec{p}=\begin{pmatrix}p_1 \\ p_2\\p_3\end{pmatrix}$$
If you want to know the angle between that vector $\vec{p}$ and any other vector 
$\vec{x}$, you can use the dot product:
$$\vec{p} \cdot \vec{x}=\lvert p\rvert \lvert q\rvert \cos \alpha$$
where $\alpha$ represents the angle between $\vec{p}$ and $\vec{x}$. Solving for $\alpha$:
$$\alpha=\cos^{-1}(\frac{\vec{p} \cdot \vec{x}}{\lvert p\rvert \lvert q\rvert})$$
Hope this helps.

REPLY [1 votes]: Compute the scalar product and divide by the norms of the vectors: in your case, this would be $\frac 1 {\| p \|} (p_x x + p_y y + p_z z)$ (assuming $\|(x,y,z)\| = 1$). This gives you the cosine of the angle you are looking for, so now apply $\arccos$ and that is your angle (between $0$ and $\pi$).
{"set_name": "stack_exchange", "score": 0, "question_id": 1320084}