AP_Common: Location: add offset(Vector3p &ned_offset)

This commit is contained in:
Peter Barker 2023-09-06 14:03:29 +10:00 committed by Andrew Tridgell
parent 6e1e1f6596
commit a9c62fa565
3 changed files with 24 additions and 0 deletions

View File

@ -306,6 +306,14 @@ void Location::offset(ftype ofs_north, ftype ofs_east)
offset_latlng(lat, lng, ofs_north, ofs_east);
}
// extrapolate latitude/longitude given distances (in meters) north
// and east. Note that this is metres, *even for the altitude*.
void Location::offset(const Vector3p &ofs_ned)
{
offset_latlng(lat, lng, ofs_ned.x, ofs_ned.y);
alt += -ofs_ned.z * 100; // m -> cm
}
/*
* extrapolate latitude/longitude given bearing and distance
* Note that this function is accurate to about 1mm at a distance of

View File

@ -79,6 +79,9 @@ public:
// extrapolate latitude/longitude given distances (in meters) north and east
static void offset_latlng(int32_t &lat, int32_t &lng, ftype ofs_north, ftype ofs_east);
void offset(ftype ofs_north, ftype ofs_east);
// extrapolate latitude/longitude given distances (in meters) north
// and east. Note that this is metres, *even for the altitude*.
void offset(const Vector3p &ofs_ned);
// extrapolate latitude/longitude given bearing and distance
void offset_bearing(ftype bearing_deg, ftype distance);

View File

@ -113,6 +113,19 @@ TEST(Location, LocOffsetDouble)
}
}
TEST(Location, LocOffset3DDouble)
{
Location loc {
-353632620, 1491652373, 60000, Location::AltFrame::ABSOLUTE
};
// this is ned, so our latitude should change, and our new
// location should be above the original:
loc.offset(Vector3d{1000, 0, -10});
EXPECT_EQ(loc.lat, -353542788);
EXPECT_EQ(loc.lng, 1491652373);
EXPECT_EQ(loc.alt, 61000);
}
TEST(Location, Tests)
{
Location test_location;