Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect long-distance calculation when using euclidean_distance #104

Open
GermainRV opened this issue Jul 10, 2024 · 1 comment
Open

Comments

@GermainRV
Copy link

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:

  • P1(21.42, -158.15)
  • P2(-14.02, -75.73)

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
Copy link
Member

asinghvi17 commented Jul 10, 2024

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

The straight-line distance between points `a` and `b`. Uses `datum` to perform
transformations as necessary, and unlike other *Geodesy* functions, this
defaults to use the common WGS-84 datum for convenience.
"""
euclidean_distance(a::T, b::T) where {T <: AbstractVector} = norm(a-b)

euclidean_distance(a::LLA, b, datum = wgs84) = euclidean_distance(ECEFfromLLA(datum)(a), b, datum)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants