# How do we derive the direction formula for longitude latitutude

θ = atan2( sin(Δlong).cos(lat2), cos(lat1).sin(lat2) − sin(lat1).cos(lat2).cos(Δlong) )

Does it take into account that we may be dealing with a trapezoid rather than a rectangle

http://www.movable-type.co.uk/scripts/latlong.html

-
That's one very good answer. Any other answer that do not uses matrix? –  Jim Thio Jan 27 '12 at 7:57

The title and the body contain two different questions; this is an answer to the question in the title.

First rotate around the polar axis to put the first point on the prime meridian; this doesn't change the required bearing. Denoting latitude by $\theta$ and longitude by $\phi$, the coordinates of the points are now $(\theta_1,0)$ and $(\theta_2,\Delta\phi)$, respectively. Now rotate by $\theta_1$ around an equatorial axis at $\phi=\pm\pi/2$ to take the first point to the south pole. Now the required bearing is the longitude to which the second point has been rotated.

In Cartesian coordinates, the matrix of the rotation that takes the first point to the south pole is

$$\pmatrix{-\sin\theta_1&0&\cos\theta_1\\0&1&0\\-\cos\theta_1&0&-\sin\theta_1}\;.$$

Applying this to the second point yields

$$\pmatrix{-\sin\theta_1&0&\cos\theta_1\\0&1&0\\-\cos\theta_1&0&-\sin\theta_1}\pmatrix{\cos\theta_2\cos\Delta\phi\\\cos\theta_2\sin\Delta\phi\\\sin\theta_2}=\pmatrix{\cos\theta_1\sin\theta_2-\sin\theta_1\cos\theta_2\cos\Delta\phi\\\cos\theta_2\sin\Delta\phi\\-\sin\theta_1\sin\theta_2-\cos\theta_1\cos\theta_2\cos\Delta\phi}\;.$$

Then you get the bearing by calculating the longitude of that point as $\operatorname{atan2}(y,x)$.

As regards the question in the body, the derivation uses neither rectangles nor trapezoids. You may be referring to the fact that a rectangle in latitude-longitude space has roughly the shape of a trapezoid in Euclidean space. However, it's not exactly a trapezoid, and the derivation uses neither the approximation of a trapezoid, nor the even less accurate approximation of a rectangle, but calculates the bearing exactly as the local inclination of the great circle through the two points.

-
+1 very good answer. –  Jim Thio Jan 11 '12 at 10:55
before I do pencil pushing to verify, knows other answer that's easier to derive? –  Jim Thio Jan 27 '12 at 7:57
@Jim: I don't think there's a substantially simpler form for the answer. There might be an easier way to derive this one, but I can't think of one. –  joriki Jan 27 '12 at 10:06
+1 pencil pushing commence !!!! –  Jim Thio Jan 29 '12 at 9:51