Browse Source

AP_Common: move location_update to Location and rename to offset_bearing

master
Pierre Kancir 6 years ago committed by Peter Barker
parent
commit
a30404fb11
  1. 14
      libraries/AP_Common/Location.cpp
  2. 3
      libraries/AP_Common/Location.h

14
libraries/AP_Common/Location.cpp

@ -232,6 +232,20 @@ void Location::offset(float ofs_north, float ofs_east) @@ -232,6 +232,20 @@ void Location::offset(float ofs_north, float ofs_east)
}
}
/*
* extrapolate latitude/longitude given bearing and distance
* Note that this function is accurate to about 1mm at a distance of
* 100m. This function has the advantage that it works in relative
* positions, so it keeps the accuracy even when dealing with small
* distances and floating point numbers
*/
void Location::offset_bearing(float bearing, float distance)
{
const float ofs_north = cosf(radians(bearing)) * distance;
const float ofs_east = sinf(radians(bearing)) * distance;
offset(ofs_north, ofs_east);
}
float Location::longitude_scale() const
{
float scale = cosf(lat * (1.0e-7f * DEG_TO_RAD));

3
libraries/AP_Common/Location.h

@ -75,6 +75,9 @@ public: @@ -75,6 +75,9 @@ public:
// extrapolate latitude/longitude given distances (in meters) north and east
void offset(float ofs_north, float ofs_east);
// extrapolate latitude/longitude given bearing and distance
void offset_bearing(float bearing, float distance);
// longitude_scale - returns the scaler to compensate for
// shrinking longitude as you move north or south from the equator
// Note: this does not include the scaling to convert

Loading…
Cancel
Save