From 1c867eb99dd2889141f14a5045e8ce10ecbfdd64 Mon Sep 17 00:00:00 2001 From: bcoconni Date: Sun, 3 Aug 2014 13:59:30 +0200 Subject: [PATCH] Bug fix for the issue #1497. JSBSim calculations of geodetic coordinates were producing a NaN at the North and South poles (i.e latitude +/-90deg). --- src/FDM/JSBSim/math/FGLocation.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/FDM/JSBSim/math/FGLocation.cpp b/src/FDM/JSBSim/math/FGLocation.cpp index 88a1946b7..da4183944 100644 --- a/src/FDM/JSBSim/math/FGLocation.cpp +++ b/src/FDM/JSBSim/math/FGLocation.cpp @@ -419,7 +419,15 @@ void FGLocation::ComputeDerivedUnconditional(void) const z = signz0*sqrt_q*(w+sqrt(z_term)); } Ne = a*sqrt(1+eps2*z*z/b2); - mGeodLat = asin((eps2+1.0)*(z/Ne)); + double tmp = (eps2+1.0)*(z/Ne); + // Ugly hack to work around the round-off errors when the simulation is + // started at a latitude of 90deg. + if (tmp > 1.0) + tmp = 1.0; + else if (tmp < -1.0) + tmp = -1.0; + // End of ugly hack + mGeodLat = asin(tmp); r0 = rxy; GeodeticAltitude = r0*cos(mGeodLat) + mECLoc(eZ)*sin(mGeodLat) - a2/Ne; } -- 2.39.5