Given latitude/longitude of two points on the Moon
(lat1, lon1) and
(lat2, lon2), compute the distance between the two points in kilometers, by using any formula that gives the same result as the haversine formula.
- Four integer values
lat1, lon1, lat2, lon2in degree (angle) or
- four decimal values
ϕ1, λ1, ϕ2, λ2in radians.
Distance in kilometers between the two points (decimal with any precision or rounded integer).
ris the radius of the sphere (assume that the Moon's radius is 1737 km),
ϕ1latitude of point 1 in radians
ϕ2latitude of point 2 in radians
λ1longitude of point 1 in radians
λ2longitude of point 2 in radians
dis the circular distance between the two points
Other possible formulas
d = r * acos(sin ϕ1 sin ϕ2 + cos ϕ1 cos ϕ2 cos(λ2 - λ1))@miles' formula.
d = r * acos(cos(ϕ1 - ϕ2) + cos ϕ1 cos ϕ2 (cos(λ2 - λ1) - 1))@Neil's formula.
Example where inputs are degrees and output as rounded integer
42, 9, 50, 2 --> 284 50, 2, 42, 9 --> 284 4, -2, -2, 1 --> 203 77, 8, 77, 8 --> 0 10, 2, 88, 9 --> 2365
- The input and output can be given in any convenient format.
- Specify in the answer whether the inputs are in degrees or radians.
- No need to handle invalid latitude/longitude values
- Either a full program or a function are acceptable. If a function, you can return the output rather than printing it.
- If possible, please include a link to an online testing environment so other people can try out your code!
- Standard loopholes are forbidden.
- This is code-golf so all usual golfing rules apply, and the shortest code (in bytes) wins.