1 // fg_geodesy.cxx -- routines to convert between geodetic and geocentric
4 // Copied and adapted directly from LaRCsim/ls_geodesy.c
6 // See below for the complete original LaRCsim comments.
9 // (Log is kept at end of this file)
15 #include <Include/fg_constants.h>
16 #include <Math/fg_geodesy.hxx>
17 #include <Math/point3d.hxx>
20 // ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator
21 #define ONE_SECOND 4.848136811E-6
24 // fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
26 // lat_geoc Geocentric latitude, radians, + = North
27 // radius C.G. radius to earth center (meters)
30 // lat_geod Geodetic latitude, radians, + = North
31 // alt C.G. altitude above mean sea level (meters)
32 // sea_level_r radius from earth center to sea level at
33 // local vertical (surface normal) of C.G. (meters)
36 void fgGeocToGeod( double lat_geoc, double radius, double
37 *lat_geod, double *alt, double *sea_level_r )
39 double t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha;
40 double sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl;
42 if( ( (FG_PI_2 - lat_geoc) < ONE_SECOND ) // near North pole
43 || ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) // near South pole
46 *sea_level_r = EQUATORIAL_RADIUS_M*E;
47 *alt = radius - *sea_level_r;
49 t_lat = tan(lat_geoc);
50 x_alpha = E*EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E);
51 mu_alpha = atan2(sqrt(RESQ_M - x_alpha*x_alpha),E*x_alpha);
52 if (lat_geoc < 0) mu_alpha = - mu_alpha;
53 sin_mu_a = sin(mu_alpha);
54 delt_lambda = mu_alpha - lat_geoc;
55 r_alpha = x_alpha/cos(lat_geoc);
56 l_point = radius - r_alpha;
57 *alt = l_point*cos(delt_lambda);
59 // check for domain error
60 if ( errno == EDOM ) {
61 cout << "Domain ERROR in fgGeocToGeod!!!!\n";
65 denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
66 rho_alpha = EQUATORIAL_RADIUS_M*(1-EPS)/
68 delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt);
69 *lat_geod = mu_alpha - delt_mu;
70 lambda_sl = atan( E*E * tan(*lat_geod) ); // SL geoc. latitude
71 sin_lambda_sl = sin( lambda_sl );
73 sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
75 // check for domain error
76 if ( errno == EDOM ) {
77 cout << "Domain ERROR in fgGeocToGeod!!!!\n";
85 // fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
87 // lat_geod Geodetic latitude, radians, + = North
88 // alt C.G. altitude above mean sea level (meters)
91 // sl_radius SEA LEVEL radius to earth center (meters)
92 // (add Altitude to get true distance from earth center.
93 // lat_geoc Geocentric latitude, radians, + = North
97 void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
100 double lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py;
102 lambda_sl = atan( E*E * tan(lat_geod) ); // sea level geocentric latitude
103 sin_lambda_sl = sin( lambda_sl );
104 cos_lambda_sl = cos( lambda_sl );
105 sin_mu = sin(lat_geod); // Geodetic (map makers') latitude
106 cos_mu = cos(lat_geod);
108 sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
109 py = *sl_radius*sin_lambda_sl + alt*sin_mu;
110 px = *sl_radius*cos_lambda_sl + alt*cos_mu;
111 *lat_geoc = atan2( py, px );
115 /***************************************************************************
119 ----------------------------------------------------------------------------
121 FUNCTION: Converts geocentric coordinates to geodetic positions
123 ----------------------------------------------------------------------------
125 MODULE STATUS: developmental
127 ----------------------------------------------------------------------------
129 GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
131 ----------------------------------------------------------------------------
133 DESIGNED BY: E. B. Jackson
135 CODED BY: E. B. Jackson
137 MAINTAINED BY: E. B. Jackson
139 ----------------------------------------------------------------------------
141 MODIFICATION HISTORY:
145 930208 Modified to avoid singularity near polar region. EBJ
146 930602 Moved backwards calcs here from ls_step. EBJ
147 931214 Changed erroneous Latitude and Altitude variables to
148 *lat_geod and *alt in routine ls_geoc_to_geod. EBJ
149 940111 Changed header files from old ls_eom.h style to ls_types,
150 and ls_constants. Also replaced old DATA type with new
157 Revision 1.3 1998/11/11 00:18:36 curt
158 Check for domain error in fgGeoctoGeod()
160 Revision 1.2 1998/10/16 23:36:36 curt
163 Revision 1.1 1998/10/16 19:30:40 curt
164 Renamed .c -> .h so we can start adding c++ supporting routines.
166 Revision 1.6 1998/07/08 14:40:07 curt
167 polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx
168 Updated fg_geodesy comments to reflect that routines expect and produce
171 Revision 1.5 1998/04/25 22:06:23 curt
172 Edited cvs log messages in source files ... bad bad bad!
174 Revision 1.4 1998/01/27 00:47:59 curt
175 Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
176 system and commandline/config file processing code.
178 Revision 1.3 1998/01/19 19:27:12 curt
179 Merged in make system changes from Bob Kuehne <rpk@sgi.com>
180 This should simplify things tremendously.
182 Revision 1.2 1997/12/15 23:54:54 curt
183 Add xgl wrappers for debugging.
184 Generate terrain normals on the fly.
186 Revision 1.1 1997/07/31 23:13:14 curt
189 Revision 1.1 1997/05/29 00:09:56 curt
190 Initial Flight Gear revision.
192 * Revision 1.5 1994/01/11 18:47:05 bjax
193 * Changed include files to use types and constants, not ls_eom.h
194 * Also changed DATA type to SCALAR type.
196 * Revision 1.4 1993/12/14 21:06:47 bjax
197 * Removed global variable references Altitude and Latitude. EBJ
199 * Revision 1.3 1993/06/02 15:03:40 bjax
200 * Made new subroutine for calculating geodetic to geocentric; changed name
201 * of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
204 ----------------------------------------------------------------------------
208 [ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
209 Control and Simulation", Wiley and Sons, 1992.
213 ----------------------------------------------------------------------------
217 ----------------------------------------------------------------------------
221 ----------------------------------------------------------------------------
224 lat_geoc Geocentric latitude, radians, + = North
225 radius C.G. radius to earth center, ft
227 ----------------------------------------------------------------------------
230 lat_geod Geodetic latitude, radians, + = North
231 alt C.G. altitude above mean sea level, ft
232 sea_level_r radius from earth center to sea level at
233 local vertical (surface normal) of C.G.
235 --------------------------------------------------------------------------*/
239 // Revision 1.3 1998/11/11 00:18:36 curt
240 // Check for domain error in fgGeoctoGeod()
242 // Revision 1.2 1998/10/16 23:36:36 curt
245 // Revision 1.1 1998/10/16 19:30:40 curt
246 // Renamed .c -> .h so we can start adding c++ supporting routines.
248 // Revision 1.6 1998/07/08 14:40:07 curt
249 // polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx
250 // Updated fg_geodesy comments to reflect that routines expect and produce
253 // Revision 1.5 1998/04/25 22:06:23 curt
254 // Edited cvs log messages in source files ... bad bad bad!
256 // Revision 1.4 1998/01/27 00:47:59 curt
257 // Incorporated Paul Bleisch's <pbleisch@acm.org> new debug message
258 // system and commandline/config file processing code.
260 // Revision 1.3 1998/01/19 19:27:12 curt
261 // Merged in make system changes from Bob Kuehne <rpk@sgi.com>
262 // This should simplify things tremendously.
264 // Revision 1.2 1997/12/15 23:54:54 curt
265 // Add xgl wrappers for debugging.
266 // Generate terrain normals on the fly.
268 // Revision 1.1 1997/07/31 23:13:14 curt