mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-30 13:00:57 +08:00
refactor(lat_lon_alt): use cbrt and x*x to drop double pow tables
Replaces the cube-root pow() with cbrt() (still double precision, no log lookup table) and the pow(x, 2) calls with x*x. Removing the last double pow() callers on the target lets the linker drop __pow_log_data and __exp_data (~6.3 KB flash) with no loss of geodetic precision.
This commit is contained in:
1 parent
113bee1437
commit
deaef6ee94
1 file changed
+5
-3
@@ -50,7 +50,7 @@ LatLonAlt LatLonAlt::fromEcef(const Vector3d &p_ecef)
|
||||
const double P = 4.0 / 3.0 * (E * F + 1);
|
||||
const double Q = 2 * (E * E - F * F);
|
||||
const double D = P * P * P + Q * Q;
|
||||
const double V = pow(sqrt(D) - Q, 1.0 / 3.0) - pow(sqrt(D) + Q, 1.0 / 3.0);
|
||||
const double V = cbrt(sqrt(D) - Q) - cbrt(sqrt(D) + Q);
|
||||
const double G = 0.5 * (sqrt(E * E + V) + E);
|
||||
const double T = sqrt(G * G + (F - V * G) / (2 * G - E)) - G;
|
||||
|
||||
@@ -72,7 +72,8 @@ Vector3d LatLonAlt::toEcef() const
|
||||
const double cos_lon = cos(_longitude_rad);
|
||||
const double sin_lon = sin(_longitude_rad);
|
||||
|
||||
const double r_e = Wgs84::equatorial_radius / sqrt(1.0 - std::pow(Wgs84::eccentricity * sin_lat, 2.0));
|
||||
const double ecc_sin_lat = Wgs84::eccentricity * sin_lat;
|
||||
const double r_e = Wgs84::equatorial_radius / sqrt(1.0 - ecc_sin_lat * ecc_sin_lat);
|
||||
const double r_total = r_e + static_cast<double>(_altitude);
|
||||
|
||||
return Vector3d(r_total * cos_lat * cos_lon,
|
||||
@@ -105,7 +106,8 @@ Vector2d LatLonAlt::deltaLatLonToDeltaXY(const double latitude, const float alti
|
||||
void LatLonAlt::computeRadiiOfCurvature(const double latitude, double &meridian_radius_of_curvature,
|
||||
double &transverse_radius_of_curvature)
|
||||
{
|
||||
const double tmp = 1.0 - pow(Wgs84::eccentricity * sin(latitude), 2);
|
||||
const double ecc_sin_lat = Wgs84::eccentricity * sin(latitude);
|
||||
const double tmp = 1.0 - ecc_sin_lat * ecc_sin_lat;
|
||||
const double sqrt_tmp = std::sqrt(tmp);
|
||||
meridian_radius_of_curvature = Wgs84::meridian_radius_of_curvature_numerator / (tmp * tmp * sqrt_tmp);
|
||||
transverse_radius_of_curvature = Wgs84::equatorial_radius / sqrt_tmp;
|
||||
|
||||
Reference in new issue
Block a user