itacart.geodesy.inverse_geodesic
- itacart.geodesy.inverse_geodesic(lon1_deg, lat1_deg, lon2_deg, lat2_deg, *, tol=VINCENTY_TOL_RAD, max_iter=VINCENTY_MAX_ITER)[source]
Return the geodesic distance and initial azimuth between two points.
Vincenty inverse solution on the WGS84 ellipsoid.
- Parameters:
lon1_deg (
float) – Longitude of the first point, in degrees.lat1_deg (
float) – Latitude of the first point, in degrees.lon2_deg (
float) – Longitude of the second point, in degrees.lat2_deg (
float) – Latitude of the second point, in degrees.tol (
float, default:VINCENTY_TOL_RAD) – Convergence tolerance on the longitude iterate, relative to the line’s angular length up to one radian: the iteration stops when the iterate moves by less thantol * min(1, sigma)radians, or by no more than four units in its last place. Relative because a short line’s azimuth inherits the residue divided by its length, so an absolute threshold that suits a long line leaves a short one with a wrong azimuth; capped at one radian, so that a long line, near-antipodal ones included, converges as it always did.max_iter (
int, default:VINCENTY_MAX_ITER) – Iteration cap.
- Return type:
- Returns:
(distance_m, azimuth_deg), the geodesic length in metres and the forward azimuth at the first point in degrees, clockwise from north, normalised to[0, 360).- Raises:
DomainError – If any argument is not finite, or a latitude lies outside
[-90, 90].ConvergenceError – If the iteration does not converge, which for this formula means a (near-)antipodal pair. Returning an unconverged iterate would look exactly like a distance and silently poison whatever consumes it.
Note
Coincident points return
(0.0, 0.0). The azimuth is a convention there, not a bearing – the geodesic is degenerate and has no direction. Raising instead would force every caller to guard the duplicated-vertex case that vertex deduplication initacart.geometryexists to absorb.Example
>>> d, az = inverse_geodesic(0.0, 0.0, 0.0, 1.0) >>> round(d, 3), round(az, 6) (110574.389, 0.0)