Measuring misalignment between two positions on sky Let's say I have the (RA,Dec) for two positions on the sky. I want to measure the position angle between these two positions. In other words, if I had the Cartesian coordinate vectors for these two positions (say [x,y,z]) then I think the position angle PA would simply be the dot product of the two vectors, so basically cos(PA). However, RA and Dec are spherical coordinates (corresponding to $\phi$ and $\theta$ respectively), not Cartesian coordinates. How do I get cos(PA) between the two positions on the sky if I only have their (RA,Dec) instead of [x,y,z]? 

https://en.wikipedia.org/wiki/Position_angle


  Position angle, usually abbreviated PA, is [a] convention for measuring angles on the sky in astronomy. The International Astronomical Union defines it as the angle measured relative to the north celestial pole (NCP), turning positive into the direction of the right ascension. In the standard (non-flipped) images this is a counterclockwise measure relative to the axis into the direction of positive declination.
Assuming you mean the angle between the meridian line through A and the great circle that goes through points A and B, then it goes something like this.

Define vectors from the origin to A and B assuming they lie on a unit sphere, such that $x_A= \cos \delta_A \cos \phi_A$, $ y_A = \cos \delta_A \sin \phi_A$ and $z_A= \sin \delta_A$, and similar for B. Here $\phi$ refers to right Ascension and $\delta$ is declination.

The great circles in question define planes that pass through the origin. A normal to the plane defined by OAB is given by the vector product $\vec{n_1}=\vec{A}\times \vec{B}$. Similarly a great circle passing through the O, A and the NCP $(0, 0, 1)$ has a normal of $\vec{n_2}= \vec{A}\times (0,0,1) = (y_A, -x_A, 0)$.

The angle you are looking for is the angle between these two normal vectors, which can be found from scalar product in the usual way.
$$\cos \theta = \frac{\vec{n_1}\cdot \vec{n_2}}{|n_1||n_2|}=\frac{\cos \phi_{A}(y_{A}z_{B} - y_{B}z_A) + \sin \phi_{A}(x_Az_B - x_Bz_A)}{|\vec{A}\times \vec{B}|}$$