Pull Constant from Atan2 Function

coordinate systemseuclidean-geometryspherical trigonometryspherical-geometrytrigonometry

I am trying to calculate intersection Latitude value based on given coordinates and intersect Longitude.

$\begin {align}
b &= \text {is bearing in radians} \\
Lat_1 &= \text {is Latitude 1} \\
Lat_2 &= \text {is Latitude 2} \\
Lon_1 &= \text {is Longitude 1} \\
Lon_2 &= \text {is Longitude 2} \\
\end {align}$

$\begin {align}
y &= \sin(Lon_2-Lon_1) \times \cos Lat_2 \\
x &= \cos Lat_1 \times \sin Lat_2-\sin Lat_1 \times \cos Lat_2 \times \cos(Lon_2-Lon_1) \\
\end {align}$

so $\text {atan2}(y, x)$ should give me the bearing between these coordinates.

If $b = \text {atan2} ((\sin(Lon_2-Lon_1) \times \cos Lat_2), (\cos Lat_1 \times \sin Lat_2- \sin Lat_1 \times \cos Lat_2 \times cos (Lon_2-Lon_1)))$

$Lat_2$ = ?

Best Answer

I notice that your formula measures latitude up and down from the equator (the geographer's convention) rather than down from the pole (the mathematical convention). Let's use your convention (relative to the equator).

I find the formulas easier to work with when I write $\phi$ for latitude and $\lambda$ for longitude. Given your initial latitude $\phi_1$ and longitude $\lambda_1$ and the bearing $b$ toward the desired point at latitude $\phi_2,$ let $$ a = \frac{\sqrt{1 - \sin^2 b \cos^2\phi_1}}{\lvert\sin b \cos\phi_1\rvert} $$ and compute the longitude $\lambda_0$ at which the latitude of the great circle is maximized as follows: $$ \lambda_0 = \lambda_1 \pm \arccos\left( \frac{\tan \phi_1}{a} \right). $$ You can determine the sign to use for $\pm$ by considering the quadrant in which the angle $b$ lies. For example, if $0 < b < 90^\circ,$ then your general direction of travel along the circle is eastward and the maximum latitude is less than halfway around the circle in your direction of travel, so you take the $+$ sign.

Finally, let $$ \lambda_2 = \lambda_0 \pm \arccos\left( \frac{\tan \phi_2}{a} \right), $$ using the angle $b$ and the direction from $\phi_1$ to $\phi_2$ to determine which sign to use for $\pm.$ For example, if $0 < b < 90^\circ$ and $\phi_2 > \phi_1,$ then you are traveling generally eastward but will reach latitude $\phi_2$ before $\phi_\max,$ so you should use the $-$ sign.


Here is a derivation of the formulas.

We have Clairaut's formula, $$ \sin \psi \cos \phi = \text{constant}, $$ where $\psi$ is the bearing along the great circle at a point at latitude $\phi,$ and the implicit equation of a great circle, $$ \tan \phi = a \cos(\lambda - \lambda_0), $$ where $\phi$ and $\lambda$ are the latitude and longitude of a point on the circle and where $a$ and $\lambda_0$ are constants. (See this question but convert the latitude to your convention).

At the minimum and maximum latitudes of a great circle, the course is $90^\circ$ or $270^\circ,$ so the absolute value of the constant in Clairaut's formula is $\cos \phi_\max,$ where $\phi_\max$ is the maximum latitude of the great circle. Plugging in your initial latitude $\phi_1$ and your bearing $b,$ $$ \cos\phi_\max = \lvert \sin b \cos \phi_1\rvert. $$ From the identity $\tan\alpha = \frac{\sqrt{1 - \cos^2\alpha}}{\cos\alpha},$ we conclude that $$ {\tan \phi_\max} = \frac{\sqrt{1 - \sin^2 b \cos^2\phi_1}}{\lvert\sin b \cos\phi_1\rvert} $$

In the implicit equation, $a$ is the maximum value of the right-hand side, while the left-hand side is maximized when $\phi = \phi_\max,$ so $$a = \tan\phi_\max.$$ Moreover, $\lambda_0$ is the longitude at which the maximum latitude is reached. Plugging in your initial conditions, $$ \tan \phi_1 = a \cos(\lambda_1 - \lambda_0), $$ where $\lambda_1$ is your initial longitude. It follows that $$ \cos(\lambda_1 - \lambda_0) = \frac{\tan \phi_1}{a} $$ and that $$ \lambda_0 = \lambda_1 \pm \arccos\left( \frac{\tan \phi_1}{a} \right). $$

Now that we know $a$ and $\lambda_0,$ we can solve for $\lambda_2$ in the equation $$ \tan \phi_2 = \tan \phi_\max \cos(\lambda_2 - \lambda_0). $$ The result is shown in the first part of this answer.


Having worked through all of that, I might still be inclined to transfer to Cartesian coordinates in order to do the work. It is simple enough to find unit vectors pointing due north and due east along the surface of the Earth at any latitude and longitude, and from those and the bearing along a great circle through that point, get a vector perpendicular to the great circle. If the coordinates of that vector are $(x_0,y_0,z_0),$ then $\lambda_0 = \text{atan2}(y_0, x_0).$ You can then get the angle $\lvert\lambda_2 - \lambda_0\rvert$ by constructing some right triangles and applying a little trig.

It's also possible to solve for $\lambda_2$ in the formula in the question, but it seems uglier to do it that way.

Related Question