# Angle between GPS coordinates

I realize GPS Coordinates are spherical coordinates. However I know the earth is more of an ellipsoid. I need to compute with a fairly high degree of accuracy the pitch and yaw between two objects whose coordinates are expressed in Longitude,Latitude and Altitude.

By "pitch" I mean relative to true north, how many degrees does something at point A have to turn to face point B By "yaw" I mean relative to the ground how many degrees do I have to tilt to face the object in question. Facing the ground could be 0 degrees, the horizon 90 degrees and the sky 180 degrees for example.

There are a few answers that start to approach this but nothing I can tell quite answers it. To determine pitch/yaw you have to realize its relative to something sitting on the outside of the ellipsoid at one of the two points. Simply using |A||B|cos(theta)=A dot b doesn't work because that gives the angle between them from the perspective of the center of the earth. Also that assumes you converted gps coordinates to XYZ first. (Which is done easily enough)

-
You do have some kind of spherical coordinates on the ellipsoid, don't you? Then follow the standard procedure to get a local basis at $A$ such that one vector is normal to the ground, one vector is pointing East and the last pointing North. Wouldn't finding the components of the separation vector $\vec{AB}$ with respect to such a local basis help? – Jyrki Lahtonen Jul 2 '12 at 20:04
Yes I have spherical coordinates since GPS coordinates themselves are spherical coordinates. Yes, creating a basis at A and then using it to find relative angles to B would certainly help. But I'm unsure of the steps involved. Could you be more specific, or maybe provide a source? – wd40bomber7 Jul 2 '12 at 20:20
Sorry, I was already sleeping, when your response came. The difficulty is to convert the spherical latitude to one on ellipsoid (precise meaning left unclear at this time). Henning seems to have explained this. – Jyrki Lahtonen Jul 3 '12 at 7:32

Your general procedure would be something like

2. For each of point A and B, find the "base point" on the GPS/WGS84 reference ellipsoid that is directly below/above the point. The reference ellipsoid has an equatorial radius of $R_e = 6\,378\,137.0\;\rm m$ and a polar radius of $R_p = 6\,356\,752.314\;\rm m$. What the latitude $\phi$ and longitude $\lambda$ of the geographical coordinates specify is the direction of the local zenith, that is, the surface normal of the reference ellipsoid at the base point. There's some algebra and trigonometry to be done here -- unless I've made a mistake somewhere, the coordinates of the base point work out to $$\bigl( R_e \cos(\lambda) \cos(\psi), R_e \sin(\lambda) \cos(\psi) , R_p \sin(\psi) \bigr)$$ where $\psi = \arctan\left( \frac{R_p}{R_e} \tan \phi \right)$. But better check for yourself that this makes sense.
3. Find the actual points $A$ and $B$ in rectangular coordinates by going an appropriate distance straight upwards from the base point. Note that "upwards" means along the local normal defined by $\phi$ (not $\psi$) and $\lambda$ -- it is not straight away from the center of the earth. Subtract the resulting coordinates to find the direction of sight from A to B.
4. Use a rotation matrix created from $(\phi_A, \lambda_A)$ to convert the difference vector $B-A$ into a local coordinate system at $A$ (with basis vectors pointing due east, north, up).