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

Add "rad" and "deg" to Units #31

Closed
MuellerSeb opened this issue Apr 21, 2020 · 4 comments
Closed

Add "rad" and "deg" to Units #31

MuellerSeb opened this issue Apr 21, 2020 · 4 comments

Comments

@MuellerSeb
Copy link

It would be nice to have the possibility to also return the distance in radians or degrees.

@jdeniau
Copy link
Member

jdeniau commented Apr 21, 2020

Hi, my math is far in my memory, but if rad and deg are angle units, so how do you convert a distance to an angle ? 🤔

@jdeniau
Copy link
Member

jdeniau commented Apr 22, 2020

To rephrase what I said : the input might be in rad or deg, but the output is actually a distance,

If I look at the scikit learn implementation of haversine that you referenced in #30 their output is also in kilometers:

scikitlearn:

>>> from sklearn.metrics.pairwise import haversine_distances
>>> from math import radians
>>> bsas = [-34.83333, -58.5166646]
>>> paris = [49.0083899664, 2.53844117956]
>>> bsas_in_radians = [radians(_) for _ in bsas]
>>> paris_in_radians = [radians(_) for _ in paris]
>>> result = haversine_distances([bsas_in_radians, paris_in_radians])
>>> result * 6371000/1000  # multiply by Earth radius to get kilometers
array([[    0.        , 11099.54035582],
       [11099.54035582,     0.        ]])

haversine:

>>> bsas = (-34.83333, -58.5166646)
>>> paris = (49.0083899664, 2.53844117956)
>>> haversine(bsas, paris)
11099.555687157774

@MuellerSeb
Copy link
Author

MuellerSeb commented Apr 22, 2020

An angle in radians is simply the distance on the unit-sphere. So to get the result in rad, you simply don't multiply with the earth radius. The dependence between angle and distance in linear (that is why the circumference of a circle is r * 2pi (where 2pi is a 360 deg angle))

Edit:
and as you see in the sklearn example the result of the haversine function is multiplied with the earth radius. The result itself is in radians.

@jdeniau
Copy link
Member

jdeniau commented Aug 24, 2021

Fixed by #40

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