]> git.mxchange.org Git - simgear.git/blobdiff - Math/fg_geodesy.cxx
Cygnus tools compatibility tweaks.
[simgear.git] / Math / fg_geodesy.cxx
index cbc2494159ae07b2fdc659d197eeaa03388b2b65..b6d1a214d4e4f7f9fdcb5f62a3669a47b1cc3da4 100644 (file)
@@ -10,6 +10,7 @@
 
 
 #include <math.h>
+#include <errno.h>
 
 #include <Include/fg_constants.h>
 #include <Math/fg_geodesy.hxx>
@@ -47,13 +48,22 @@ void fgGeocToGeod( double lat_geoc, double radius, double
     } else {
        t_lat = tan(lat_geoc);
        x_alpha = E*EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E);
-       mu_alpha = atan2(sqrt(RESQ_M - x_alpha*x_alpha),E*x_alpha);
+       double tmp = RESQ_M - x_alpha * x_alpha;
+       if ( tmp < 0.0 ) { tmp = 0.0; }
+       mu_alpha = atan2(sqrt(tmp),E*x_alpha);
        if (lat_geoc < 0) mu_alpha = - mu_alpha;
        sin_mu_a = sin(mu_alpha);
        delt_lambda = mu_alpha - lat_geoc;
        r_alpha = x_alpha/cos(lat_geoc);
        l_point = radius - r_alpha;
        *alt = l_point*cos(delt_lambda);
+
+       // check for domain error
+       if ( errno == EDOM ) {
+           cout << "Domain ERROR in fgGeocToGeod!!!!\n";
+           *alt = 0.0;
+       }
+
        denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
        rho_alpha = EQUATORIAL_RADIUS_M*(1-EPS)/
            (denom*denom*denom);
@@ -63,7 +73,14 @@ void fgGeocToGeod( double lat_geoc, double radius, double
        sin_lambda_sl = sin( lambda_sl );
        *sea_level_r = 
            sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
+
+       // check for domain error
+       if ( errno == EDOM ) {
+           cout << "Domain ERROR in fgGeocToGeod!!!!\n";
+           *sea_level_r = 0.0;
+       }
     }
+
 }
 
 
@@ -139,6 +156,13 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
 
 $Header$
 $Log$
+Revision 1.4  1998/11/20 01:00:36  curt
+Patch in fgGeoc2Geod() to avoid a floating explosion.
+point3d.hxx include math.h for FreeBSD
+
+Revision 1.3  1998/11/11 00:18:36  curt
+Check for domain error in fgGeoctoGeod()
+
 Revision 1.2  1998/10/16 23:36:36  curt
 c++-ifying.
 
@@ -218,6 +242,13 @@ Initial Flight Gear revision.
 
 
 // $Log$
+// Revision 1.4  1998/11/20 01:00:36  curt
+// Patch in fgGeoc2Geod() to avoid a floating explosion.
+// point3d.hxx include math.h for FreeBSD
+//
+// Revision 1.3  1998/11/11 00:18:36  curt
+// Check for domain error in fgGeoctoGeod()
+//
 // Revision 1.2  1998/10/16 23:36:36  curt
 // c++-ifying.
 //