mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 09:16:07 +03:00
64 bytes to check crossing 180 deg longitude
Co-Authored-By: Petr Ledvina <2318015+ledvinap@users.noreply.github.com>
This commit is contained in:
parent
1c8fc156f0
commit
fd5e34a4d4
1 changed files with 7 additions and 1 deletions
|
@ -2597,7 +2597,13 @@ void GPS_calculateDistanceAndDirectionToHome(void)
|
|||
// note that parameter order is from, to
|
||||
void GPS_distance2d(const gpsLocation_t *from, const gpsLocation_t *to, vector2_t *distance)
|
||||
{
|
||||
distance->x = (float)(to->lon - from->lon) * GPS_cosLat * EARTH_ANGLE_TO_CM; // East-West distance, positive East
|
||||
float deltaLon = (float)(to->lon - from->lon); // In case we crossed the 180° meridian
|
||||
if (deltaLon > 180.0f) {
|
||||
deltaLon -= 360.0f;
|
||||
} else if (deltaLon < -180.0f) {
|
||||
deltaLon += 360.0f;
|
||||
}
|
||||
distance->x = deltaLon * GPS_cosLat * EARTH_ANGLE_TO_CM; // East-West distance, positive East
|
||||
distance->y = (float)(to->lat - from->lat) * EARTH_ANGLE_TO_CM; // North-South distance, positive North
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue