mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-21 20:51:00 +00:00
Move bearing under GeoCoord
This commit is contained in:
parent
796e8c836a
commit
4a98bdd9d6
@ -366,3 +366,28 @@ float GeoCoord::latLongToMeter(double lat_a, double lng_a, double lat_b, double
|
|||||||
|
|
||||||
return (float)(6366000 * tt);
|
return (float)(6366000 * tt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Computes the bearing in degrees between two points on Earth. Ported from my
|
||||||
|
* old Gaggle android app.
|
||||||
|
*
|
||||||
|
* @param lat1
|
||||||
|
* Latitude of the first point
|
||||||
|
* @param lon1
|
||||||
|
* Longitude of the first point
|
||||||
|
* @param lat2
|
||||||
|
* Latitude of the second point
|
||||||
|
* @param lon2
|
||||||
|
* Longitude of the second point
|
||||||
|
* @return Bearing between the two points in radians. A value of 0 means due
|
||||||
|
* north.
|
||||||
|
*/
|
||||||
|
float GeoCoord::bearing(double lat1, double lon1, double lat2, double lon2)
|
||||||
|
{
|
||||||
|
double lat1Rad = toRadians(lat1);
|
||||||
|
double lat2Rad = toRadians(lat2);
|
||||||
|
double deltaLonRad = toRadians(lon2 - lon1);
|
||||||
|
double y = sin(deltaLonRad) * cos(lat2Rad);
|
||||||
|
double x = cos(lat1Rad) * sin(lat2Rad) - (sin(lat1Rad) * cos(lat2Rad) * cos(deltaLonRad));
|
||||||
|
return atan2(y, x);
|
||||||
|
}
|
@ -113,6 +113,7 @@ class GeoCoord {
|
|||||||
static void latLongToOLC(const double lat, const double lon, OLC &olc);
|
static void latLongToOLC(const double lat, const double lon, OLC &olc);
|
||||||
static void convertWGS84ToOSGB36(const double lat, const double lon, double &osgb_Latitude, double &osgb_Longitude);
|
static void convertWGS84ToOSGB36(const double lat, const double lon, double &osgb_Latitude, double &osgb_Longitude);
|
||||||
static float latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b);
|
static float latLongToMeter(double lat_a, double lng_a, double lat_b, double lng_b);
|
||||||
|
static float bearing(double lat1, double lon1, double lat2, double lon2);
|
||||||
|
|
||||||
// Lat lon alt getters
|
// Lat lon alt getters
|
||||||
int32_t getLatitude() const { return _latitude; }
|
int32_t getLatitude() const { return _latitude; }
|
||||||
|
@ -437,31 +437,6 @@ static void drawGPScoordinates(OLEDDisplay *display, int16_t x, int16_t y, const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Computes the bearing in degrees between two points on Earth. Ported from my
|
|
||||||
* old Gaggle android app.
|
|
||||||
*
|
|
||||||
* @param lat1
|
|
||||||
* Latitude of the first point
|
|
||||||
* @param lon1
|
|
||||||
* Longitude of the first point
|
|
||||||
* @param lat2
|
|
||||||
* Latitude of the second point
|
|
||||||
* @param lon2
|
|
||||||
* Longitude of the second point
|
|
||||||
* @return Bearing between the two points in radians. A value of 0 means due
|
|
||||||
* north.
|
|
||||||
*/
|
|
||||||
static float bearing(double lat1, double lon1, double lat2, double lon2)
|
|
||||||
{
|
|
||||||
double lat1Rad = toRadians(lat1);
|
|
||||||
double lat2Rad = toRadians(lat2);
|
|
||||||
double deltaLonRad = toRadians(lon2 - lon1);
|
|
||||||
double y = sin(deltaLonRad) * cos(lat2Rad);
|
|
||||||
double x = cos(lat1Rad) * sin(lat2Rad) - (sin(lat1Rad) * cos(lat2Rad) * cos(deltaLonRad));
|
|
||||||
return atan2(y, x);
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -526,7 +501,7 @@ static float estimatedHeading(double lat, double lon)
|
|||||||
if (d < 10) // haven't moved enough, just keep current bearing
|
if (d < 10) // haven't moved enough, just keep current bearing
|
||||||
return b;
|
return b;
|
||||||
|
|
||||||
b = bearing(oldLat, oldLon, lat, lon);
|
b = GeoCoord::bearing(oldLat, oldLon, lat, lon);
|
||||||
oldLat = lat;
|
oldLat = lat;
|
||||||
oldLon = lon;
|
oldLon = lon;
|
||||||
|
|
||||||
@ -654,7 +629,7 @@ static void drawNodeInfo(OLEDDisplay *display, OLEDDisplayUiState *state, int16_
|
|||||||
|
|
||||||
// FIXME, also keep the guess at the operators heading and add/substract
|
// FIXME, also keep the guess at the operators heading and add/substract
|
||||||
// it. currently we don't do this and instead draw north up only.
|
// it. currently we don't do this and instead draw north up only.
|
||||||
float bearingToOther = bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
|
float bearingToOther = GeoCoord::bearing(DegD(p.latitude_i), DegD(p.longitude_i), DegD(op.latitude_i), DegD(op.longitude_i));
|
||||||
headingRadian = bearingToOther - myHeading;
|
headingRadian = bearingToOther - myHeading;
|
||||||
drawNodeHeading(display, compassX, compassY, headingRadian);
|
drawNodeHeading(display, compassX, compassY, headingRadian);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user