1 /**************************************************************************
2 * fg_geodesy.c -- routines to convert between geodetic and geocentric
5 * Copied and adapted directly from LaRCsim/ls_geodesy.c
7 * See below for the complete original LaRCsim comments.
10 * (Log is kept at end of this file)
11 **************************************************************************/
16 #include <Include/fg_constants.h>
18 #include "fg_geodesy.h"
21 /* ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator */
22 #define ONE_SECOND 4.848136811E-6
25 /* fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
27 * lat_geoc Geocentric latitude, radians, + = North
28 * radius C.G. radius to earth center, ft
31 * lat_geod Geodetic latitude, radians, + = North
32 * alt C.G. altitude above mean sea level, ft
33 * sea_level_r radius from earth center to sea level at
34 * local vertical (surface normal) of C.G.
37 void fgGeocToGeod( double lat_geoc, double radius, double
38 *lat_geod, double *alt, double *sea_level_r )
40 double t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha;
41 double sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl;
43 if( ( (FG_PI_2 - lat_geoc) < ONE_SECOND ) /* near North pole */
44 || ( (FG_PI_2 + lat_geoc) < ONE_SECOND ) ) /* near South pole */
47 *sea_level_r = EQUATORIAL_RADIUS_KM*E;
48 *alt = radius - *sea_level_r;
50 t_lat = tan(lat_geoc);
51 x_alpha = E*EQUATORIAL_RADIUS_KM/sqrt(t_lat*t_lat + E*E);
52 mu_alpha = atan2(sqrt(RESQ_KM - x_alpha*x_alpha),E*x_alpha);
53 if (lat_geoc < 0) mu_alpha = - mu_alpha;
54 sin_mu_a = sin(mu_alpha);
55 delt_lambda = mu_alpha - lat_geoc;
56 r_alpha = x_alpha/cos(lat_geoc);
57 l_point = radius - r_alpha;
58 *alt = l_point*cos(delt_lambda);
59 denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
60 rho_alpha = EQUATORIAL_RADIUS_KM*(1-EPS)/
62 delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt);
63 *lat_geod = mu_alpha - delt_mu;
64 lambda_sl = atan( E*E * tan(*lat_geod) ); /* SL geoc. latitude */
65 sin_lambda_sl = sin( lambda_sl );
67 sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
72 /* fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
74 * lat_geod Geodetic latitude, radians, + = North
75 * alt C.G. altitude above mean sea level, ft
78 * sl_radius SEA LEVEL radius to earth center, ft (add Altitude to
79 * get true distance from earth center.
80 * lat_geoc Geocentric latitude, radians, + = North
84 void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
87 double lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py;
89 lambda_sl = atan( E*E * tan(lat_geod) ); /* sea level geocentric latitude */
90 sin_lambda_sl = sin( lambda_sl );
91 cos_lambda_sl = cos( lambda_sl );
92 sin_mu = sin(lat_geod); /* Geodetic (map makers') latitude */
93 cos_mu = cos(lat_geod);
95 sqrt(RESQ_KM / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
96 py = *sl_radius*sin_lambda_sl + alt*sin_mu;
97 px = *sl_radius*cos_lambda_sl + alt*cos_mu;
98 *lat_geoc = atan2( py, px );
102 /***************************************************************************
106 ----------------------------------------------------------------------------
108 FUNCTION: Converts geocentric coordinates to geodetic positions
110 ----------------------------------------------------------------------------
112 MODULE STATUS: developmental
114 ----------------------------------------------------------------------------
116 GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
118 ----------------------------------------------------------------------------
120 DESIGNED BY: E. B. Jackson
122 CODED BY: E. B. Jackson
124 MAINTAINED BY: E. B. Jackson
126 ----------------------------------------------------------------------------
128 MODIFICATION HISTORY:
132 930208 Modified to avoid singularity near polar region. EBJ
133 930602 Moved backwards calcs here from ls_step. EBJ
134 931214 Changed erroneous Latitude and Altitude variables to
135 *lat_geod and *alt in routine ls_geoc_to_geod. EBJ
136 940111 Changed header files from old ls_eom.h style to ls_types,
137 and ls_constants. Also replaced old DATA type with new
144 Revision 1.1 1998/04/08 23:22:14 curt
145 Adopted Gnu automake/autoconf system.
147 Revision 1.4 1998/01/27 00:47:59 curt
148 Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
149 system and commandline/config file processing code.
151 Revision 1.3 1998/01/19 19:27:12 curt
152 Merged in make system changes from Bob Kuehne <rpk@sgi.com>
153 This should simplify things tremendously.
155 Revision 1.2 1997/12/15 23:54:54 curt
156 Add xgl wrappers for debugging.
157 Generate terrain normals on the fly.
159 Revision 1.1 1997/07/31 23:13:14 curt
162 Revision 1.1 1997/05/29 00:09:56 curt
163 Initial Flight Gear revision.
165 * Revision 1.5 1994/01/11 18:47:05 bjax
166 * Changed include files to use types and constants, not ls_eom.h
167 * Also changed DATA type to SCALAR type.
169 * Revision 1.4 1993/12/14 21:06:47 bjax
170 * Removed global variable references Altitude and Latitude. EBJ
172 * Revision 1.3 1993/06/02 15:03:40 bjax
173 * Made new subroutine for calculating geodetic to geocentric; changed name
174 * of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
177 ----------------------------------------------------------------------------
181 [ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
182 Control and Simulation", Wiley and Sons, 1992.
186 ----------------------------------------------------------------------------
190 ----------------------------------------------------------------------------
194 ----------------------------------------------------------------------------
197 lat_geoc Geocentric latitude, radians, + = North
198 radius C.G. radius to earth center, ft
200 ----------------------------------------------------------------------------
203 lat_geod Geodetic latitude, radians, + = North
204 alt C.G. altitude above mean sea level, ft
205 sea_level_r radius from earth center to sea level at
206 local vertical (surface normal) of C.G.
208 --------------------------------------------------------------------------*/
212 /* Revision 1.1 1998/04/08 23:22:14 curt
213 /* Adopted Gnu automake/autoconf system.
215 * Revision 1.4 1998/01/27 00:47:59 curt
216 * Incorporated Paul Bleisch's <bleisch@chromatic.com> new debug message
217 * system and commandline/config file processing code.
219 * Revision 1.3 1998/01/19 19:27:12 curt
220 * Merged in make system changes from Bob Kuehne <rpk@sgi.com>
221 * This should simplify things tremendously.
223 * Revision 1.2 1997/12/15 23:54:54 curt
224 * Add xgl wrappers for debugging.
225 * Generate terrain normals on the fly.
227 * Revision 1.1 1997/07/31 23:13:14 curt