X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fmath%2FSGGeodesy.cxx;h=9971829af315ce299bd8ca95abce973de0196069;hb=6a7c2000027cd22eea603e936ddbad1a5bfc8b04;hp=05d76f0ed408e0b8577a44f05e25bb7c4d11ef91;hpb=07a450894437e356f10b486d9a94c6103443941e;p=simgear.git diff --git a/simgear/math/SGGeodesy.cxx b/simgear/math/SGGeodesy.cxx index 05d76f0e..9971829a 100644 --- a/simgear/math/SGGeodesy.cxx +++ b/simgear/math/SGGeodesy.cxx @@ -57,7 +57,7 @@ const double SGGeodesy::POLRAD = _POLRAD; #define E2 fabs(1 - _SQUASH*_SQUASH) static double a = _EQURAD; static double ra2 = 1/(_EQURAD*_EQURAD); -static double e = sqrt(E2); +//static double e = sqrt(E2); static double e2 = E2; static double e4 = E2*E2; @@ -84,6 +84,14 @@ SGGeodesy::SGCartToGeod(const SGVec3& cart, SGGeod& geod) double q = Z*Z*(1-e2)*ra2; double r = 1/6.0*(p+q-e4); double s = e4*p*q/(4*r*r*r); +/* + s*(2+s) is negative for s = [-2..0] + slightly negative values for s due to floating point rounding errors + cause nan for sqrt(s*(2+s)) + We can probably clamp the resulting parable to positive numbers +*/ + if( s >= -2.0 && s <= 0.0 ) + s = 0.0; double t = pow(1+s+sqrt(s*(2+s)), 1/3.0); double u = r*(1+t+1/t); double v = sqrt(u*u+e4*q); @@ -315,7 +323,7 @@ static int _geo_inverse_wgs_84( double lat1, double lon1, double lat2, double sinphi2 = sin(phi2), cosphi2 = cos(phi2); if( (fabs(lat1-lat2) < testv && - ( fabs(lon1-lon2) < testv) || fabs(lat1-90.0) < testv ) ) + ( fabs(lon1-lon2) < testv)) || (fabs(lat1-90.0) < testv ) ) { // TWO STATIONS ARE IDENTICAL : SET DISTANCE & AZIMUTHS TO ZERO */ *az1 = 0.0; *az2 = 0.0; *s = 0.0;