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

Compute distances in geodetic coordinates #154

Closed
santisoler opened this issue Mar 6, 2020 · 10 comments · Fixed by #172
Closed

Compute distances in geodetic coordinates #154

santisoler opened this issue Mar 6, 2020 · 10 comments · Fixed by #172
Labels
enhancement Idea or request for a new feature good first issue Good for newcomers (doesn’t require deep knowledge of the project)

Comments

@santisoler
Copy link
Member

santisoler commented Mar 6, 2020

Description of the desired feature

Currently Harmonica has functions to compute distances between points defined in Cartesian coordinates or in spherical geocentric coordinates. Would be nice if we add a function to compute Euclidean distances between points whose coordinates are defined in geodetic (ellipsoidal) coordinates (don't confuse it with great circle distances).
Worth noting that the geodetic coordinates depend on the reference ellipsoid, so we would need to pass a boule.Ellipsoid to the new function along with the coordinates of the two points.
This may allow to compute gravitational and magnetic effects of point masses directly on geodetic coordinates without the need to convert them into spherical. Also it could enable us to build a separate equivalent layer class, a EQLHarmonicGeodetic for example, that interpolates harmonic data given in geodetic coordinates.

Some articles that may give insights of how to compute such distances are:

Are you willing to help implement and maintain this feature? Yes

@santisoler santisoler added enhancement Idea or request for a new feature help wanted labels Mar 9, 2020
@leouieda leouieda added the good first issue Good for newcomers (doesn’t require deep knowledge of the project) label Mar 9, 2020
@birocoles
Copy link
Member

I can help

@leouieda
Copy link
Member

That would be great @birocoles!

@santisoler
Copy link
Member Author

I can help

Awesome! I couldn't find any closed-form expression for computing the Euclidean distance between two points defined in geocentric coordinates on the papers mentioned above. What I mean is that for computing the Euclidean distance both papers somewhat convert the coordinates to spherical and then compute the distance. @birocoles, are you aware of a closed-form expression for it?

@birocoles
Copy link
Member

The closed form is very ugly. It can be found at Vajda et al (2004), eq 15.

Apparently, transforming coordinates to Cartesian and then compute the distance is more efficient. But it should be investigated.

@santisoler
Copy link
Member Author

Thanks @birocoles for the reference.

It seems they are just converting to Cartesian (no projecting, Cartesian coordinates with the origin on the center of the Earth) and then replacing the X, Y and Z into the distance expression.

My intuition tells me this:

  • Converting from geodetic to spherical and then computing distance should be less efficient that converting to Cartesian (geocentric Cartesian) and then computing the distance. I think the first approach involves the evaluation of more trigonometric functions.
  • We should corroborate if the closed-form expression spare us from computing some trigonometric functions. If so, then it would definitely be more efficient than computing Cartesian coordinates and then the distance.

@santisoler
Copy link
Member Author

I think the closed-form expression is a little bit more efficient.

Converting to geocentic Cartesian
If we want to convert geodetic coordinates to geocentric Cartesian and the compute the distance, we should use the following equations for both point_1 and point_2:
imagen

This means we need to evaluate 4 different trigonometric functions for each point, resulting in the evaluation of 8 trigonometric functions for computing the distance.

Closed-form formula
If we decide to use the closed-form formula we only need to evaluate 5 trigonometric functions:
imagen

So I suppose this will be more efficient than converting to Cartesian.
Do you agree?

@birocoles
Copy link
Member

birocoles commented Mar 19, 2020

I think we need to implement both formulas and use them not only for comparing the computation times, but also the results. The results must be the same. What do you think?

@santisoler
Copy link
Member Author

That's a very good idea.
So I think we should create a new distance_geodetic function that computes the Euclidean distance using the closed-form formula, and some test functions that uses the coordinates conversions to test its results. The code for performing coordinates conversion will be much easier to read, so we can safely use it to test the API function.

@santisoler
Copy link
Member Author

@birocoles Would you like to tackle this (if you have time, obviously)? If not, don't worry, I can start writing the PR and we can continue the discussion over there. Again, no hurries.

@birocoles
Copy link
Member

Ok @santisoler , I can tackle this. I will include more functions for converting coordinates in coordinates.py and then implement the distance in geodetic coordinates. I will create a first PR for this coordinate conversions.

leouieda pushed a commit to fatiando/boule that referenced this issue Jul 10, 2020
Add `boule.Ellipsoid.prime_vertical_radius` (usually represented by N) instead
of calculating it in the coordinate conversion method. This is useful in other
areas (e.g. fatiando/harmonica#154). Method uses pre-computed sine of latitude
to avoid repeated computations of sines in other methods using this. The
definition is from Vermeille (2002; https://doi.org/10.1007/s00190-002-0273-6)
and Vajda (2004).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Idea or request for a new feature good first issue Good for newcomers (doesn’t require deep knowledge of the project)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants