JuliaGeo / Geodesy.jl

Work with points defined in various coordinate systems.
MIT License
110 stars 24 forks source link

Incorrect long-distance calculation when using euclidean_distance #104

Open GermainRV opened 2 months ago

GermainRV commented 2 months ago

I need to compute the long distances (>>1000km) between two points given their coordinates (latitude, longitude) so I used the euclidean_distance function. The points are:

I computed the distance using the following code:

using Geodesy
# Define latitude and longitude for the points
P1 = LLA(21.42, -158.15)
P2 = LLA(-12.50, -76.80)

# Calculate the Euclidean distance
distance = euclidean_distance(P1, P2) / 1e3
println("Euclidean Distance: $distance km")

Te output was: Euclidean Distance: 8748.3453257146 km However, I know that the true distance should be approximately 9650 km. I confirmed this with online latitude/longitude distance calculators like NOAA Lat/Lon calculator which gave a result of approximately 9633 km.

I also tried using the Geodesics.jl package, and it provided a more accurate distance:

using Geodesics
# Define the major radius and flattening factor for the WGS84 ellipsoid
a, f = Geodesics.EARTH_R_MAJOR_WGS84, Geodesics.F_WGS84

# Calculate the geodesic distance
dist, az, baz = Geodesics.inverse(deg2rad.((-158.15, 21.42, -76.80, -12.50))..., a, f)
println("Geodesic Distance: $(dist / 1e3) km")

The output was: Geodesic Distance: 9642.42096397771 km

I have tested the euclidean_distance function with short distances, and it seems accurate. However, the error increases with long distances, so I guess there is some error propagation when dealing with longer distances. Please let me know if I am using the function incorrectly or if this is an actual computational error.

asinghvi17 commented 2 months ago

euclidean_distance seems to be the straight-line distance between two points on the Earth, going through the surface of the Earth:

https://github.com/JuliaGeo/Geodesy.jl/blob/b5a3f70471b2b288ff588e5049f435cda6a76eb4/src/distances.jl#L6-L10 https://github.com/JuliaGeo/Geodesy.jl/blob/b5a3f70471b2b288ff588e5049f435cda6a76eb4/src/distances.jl#L16

so this is probably not the right function to use here. Geodesics.jl probably has the correct ellipsoidal calculation, and if you just want the industry standard result you can use Proj.jl's geodesic API.

We