mavextra: correct radian conversion in distance_lat_lon function #903
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #635
As pointed out in issue #635, there is an error in the distance_lat_lon function in mavextra, as
cos(lat1)
andcos(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:
After fix:
Movable Type Scripts website: 261.1 km (to 4 SF)