Skip to content
New issue

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

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

Already on GitHub? # to your account

mavextra: correct radian conversion in distance_lat_lon function #903

Merged

Conversation

shancock884
Copy link
Contributor

fix #635
As pointed out in issue #635, there is an error in the distance_lat_lon function in mavextra, as cos(lat1) and cos(lat2) were being applied to the value in degrees not radians.
This PR fixes this, using the code proposed by @gitdillo, by ensuring all function inputs are converted before use.

I chose not to use the code from the gps_distance function in mp_util.py (as linked @khancyr), as the mp_util function calculates the rhumb line distance, rather than the great-circle distance, and I did not want to alter the original author's intent of the function.

I also added extra words to the comments of all 3 similar functions in mavextra.py and the radius_of_earth variable, to make it more clear which formula and earth radius are being used.

I checked a few spot points before and after against the Movable Type Scripts website. For example:
Before fix:

>>> import pymavlink.mavextra
>>> pymavlink.mavextra.distance_lat_lon(51,0,53,2)
125501.69695239903

After fix:

>>> import pymavlink.mavextra
>>> pymavlink.mavextra.distance_lat_lon(51,0,53,2)
261134.12945358222

Movable Type Scripts website: 261.1 km (to 4 SF)

@tridge
Copy link
Contributor

tridge commented Jan 12, 2024

thanks!

@tridge tridge merged commit f2bfe88 into ArduPilot:master Jan 12, 2024
12 checks passed
@shancock884 shancock884 deleted the iss635-mavextra-dist_lat_lon-err branch January 12, 2024 08:10
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

mavextra: error in distance estimation
2 participants