You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Haversine distance may be using the wrong phi1 and phi2 angle #11308
The haversine distance from my understanding is supposed to work on a sphere, however, the notion on reduced latitude and flattening factors exist to deal with the non-spherical nature of the Earth (see https://en.wikipedia.org/wiki/Flattening). I am by no means an expert, I could very well be wrong.
Moreover, reading the wikipage and other implementations the transformation to a reduced latitude is not needed for the haversine distance, the latitude is used directly. Here are some references:
Haversine Distance Calculation Issue
The second image describes an issue where the implementation of the Haversine distance seems to be using "reduced latitudes" or may be confusing the Haversine formula with the Lambert formula.
The user's main concern is: Haversine distance may be using the wrong phi1 and phi2 angle.
Understanding the Formulas
The Haversine formula is used to calculate the great-circle distance between two points on a sphere (like the Earth) given their longitudes and latitudes.
The standard Haversine formula for distance d between two points (\phi_1, \lambda_1) and (\phi_2, \lambda_2) on a sphere of radius R is:
a = \sin^2\left(\frac{\phi_2 - \phi_1}{2}\right) + \cos(\phi_1) \cos(\phi_2) \sin^2\left(\frac{\lambda_2 - \lambda_1}{2}\right)
c = 2 \arctan2(\sqrt{a}, \sqrt{1-a})
d = R \cdot c
Conclusion and Next Steps
If the code is implementing the Haversine distance based on the assumption of a perfect sphere (which is what the Haversine formula is for), reduced latitudes are not needed. The use of reduced latitudes would only be necessary if the calculation were accounting for the Earth's flattening (an ellipsoidal shape).
If you are the developer or are responding to the user, here is the suggested action:
Verify the Formula: Check the source code to see if it is using \phi (geodetic latitude) or \beta (reduced latitude) in the trigonometric calculations.
Confirm the Model: If the formula is intended for an ellipsoid (flattened Earth), then using a method like Vincenty's or calculating the reduced latitude might be appropriate, but that would mean the formula is not a pure Haversine implementation.
Correct the Latitudes: If the goal is a standard Haversine calculation on a sphere, ensure the input latitudes (\phi_1 and \phi_2) are used directly.
Legitimate: The current code converts to reduced/geocentric latitude via atan((AXIS_B/AXIS_A)·tan(lat)), but standard haversine uses geographic latitude directly (per the reporter's cited references).
Two competing open PRs, and the sticking point is the Earth-radius constant:
Activity
Maanit491 commentedon Oct 1, 2024
The issue is resolved by me, please review my PR :)
Maanit491 commentedon Oct 9, 2024
Kindly review my PR @lucasalavapena
Asukasuk commentedon Dec 14, 2025
Haversine Distance Calculation Issue
The second image describes an issue where the implementation of the Haversine distance seems to be using "reduced latitudes" or may be confusing the Haversine formula with the Lambert formula.
The user's main concern is: Haversine distance may be using the wrong phi1 and phi2 angle.
Understanding the Formulas
The Haversine formula is used to calculate the great-circle distance between two points on a sphere (like the Earth) given their longitudes and latitudes.
The standard Haversine formula for distance d between two points (\phi_1, \lambda_1) and (\phi_2, \lambda_2) on a sphere of radius R is:
a = \sin^2\left(\frac{\phi_2 - \phi_1}{2}\right) + \cos(\phi_1) \cos(\phi_2) \sin^2\left(\frac{\lambda_2 - \lambda_1}{2}\right)
c = 2 \arctan2(\sqrt{a}, \sqrt{1-a})
d = R \cdot c
Conclusion and Next Steps
If the code is implementing the Haversine distance based on the assumption of a perfect sphere (which is what the Haversine formula is for), reduced latitudes are not needed. The use of reduced latitudes would only be necessary if the calculation were accounting for the Earth's flattening (an ellipsoidal shape).
If you are the developer or are responding to the user, here is the suggested action:
Verify the Formula: Check the source code to see if it is using \phi (geodetic latitude) or \beta (reduced latitude) in the trigonometric calculations.
Confirm the Model: If the formula is intended for an ellipsoid (flattened Earth), then using a method like Vincenty's or calculating the reduced latitude might be appropriate, but that would mean the formula is not a pure Haversine implementation.
Correct the Latitudes: If the goal is a standard Haversine calculation on a sphere, ensure the input latitudes (\phi_1 and \phi_2) are used directly.
fix: use geodetic latitudes in haversine distance formula
fix: update Lambert's to use corrected haversine radius for central a…
cclauss commentedon Sep 10, 2026
@priya-sundaram-dev wrote:
Legitimate: The current code converts to reduced/geocentric latitude via atan((AXIS_B/AXIS_A)·tan(lat)), but standard haversine uses geographic latitude directly (per the reporter's cited references).
Two competing open PRs, and the sticking point is the Earth-radius constant:
I'd settle the radius convention first (mean radius is the usual haversine choice), then take whichever PR is rebased to it.
fix: use geodetic latitudes in haversine distance formula (TheAlgorit…