1 /***************************************************************************
5 ----------------------------------------------------------------------------
7 FUNCTION: Converts geocentric coordinates to geodetic positions
9 ----------------------------------------------------------------------------
11 MODULE STATUS: developmental
13 ----------------------------------------------------------------------------
15 GENEALOGY: Written as part of LaRCSim project by E. B. Jackson
17 ----------------------------------------------------------------------------
19 DESIGNED BY: E. B. Jackson
21 CODED BY: E. B. Jackson
23 MAINTAINED BY: E. B. Jackson
25 ----------------------------------------------------------------------------
31 930208 Modified to avoid singularity near polar region. EBJ
32 930602 Moved backwards calcs here from ls_step. EBJ
33 931214 Changed erroneous Latitude and Altitude variables to
34 *lat_geod and *alt in routine ls_geoc_to_geod. EBJ
35 940111 Changed header files from old ls_eom.h style to ls_types,
36 and ls_constants. Also replaced old DATA type with new
43 Revision 1.1 1999/06/17 18:07:34 curt
46 Revision 1.1.1.1 1999/04/05 21:32:45 curt
47 Start of 0.6.x branch.
49 Revision 1.3 1998/07/08 14:41:37 curt
52 Revision 1.2 1998/01/19 18:40:25 curt
53 Tons of little changes to clean up the code and to remove fatal errors
54 when building with the c++ compiler.
56 Revision 1.1 1997/05/29 00:09:56 curt
57 Initial Flight Gear revision.
59 * Revision 1.5 1994/01/11 18:47:05 bjax
60 * Changed include files to use types and constants, not ls_eom.h
61 * Also changed DATA type to SCALAR type.
63 * Revision 1.4 1993/12/14 21:06:47 bjax
64 * Removed global variable references Altitude and Latitude. EBJ
66 * Revision 1.3 1993/06/02 15:03:40 bjax
67 * Made new subroutine for calculating geodetic to geocentric; changed name
68 * of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
71 ----------------------------------------------------------------------------
75 [ 1] Stevens, Brian L.; and Lewis, Frank L.: "Aircraft
76 Control and Simulation", Wiley and Sons, 1992.
80 ----------------------------------------------------------------------------
84 ----------------------------------------------------------------------------
88 ----------------------------------------------------------------------------
91 lat_geoc Geocentric latitude, radians, + = North
92 radius C.G. radius to earth center, ft
94 ----------------------------------------------------------------------------
97 lat_geod Geodetic latitude, radians, + = North
98 alt C.G. altitude above mean sea level, ft
99 sea_level_r radius from earth center to sea level at
100 local vertical (surface normal) of C.G.
102 --------------------------------------------------------------------------*/
104 #include "ls_types.h"
105 #include "ls_constants.h"
106 #include "ls_geodesy.h"
109 /* ONE_SECOND is pi/180/60/60, or about 100 feet at earths' equator */
110 #define ONE_SECOND 4.848136811E-6
111 #define HALF_PI 0.5*PI
114 void ls_geoc_to_geod( SCALAR lat_geoc, SCALAR radius, SCALAR *lat_geod,
115 SCALAR *alt, SCALAR *sea_level_r )
117 SCALAR t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha;
118 SCALAR sin_mu_a, denom,delt_lambda, lambda_sl, sin_lambda_sl;
120 if( ( (HALF_PI - lat_geoc) < ONE_SECOND ) /* near North pole */
121 || ( (HALF_PI + lat_geoc) < ONE_SECOND ) ) /* near South pole */
123 *lat_geod = lat_geoc;
124 *sea_level_r = EQUATORIAL_RADIUS*E;
125 *alt = radius - *sea_level_r;
129 t_lat = tan(lat_geoc);
130 x_alpha = E*EQUATORIAL_RADIUS/sqrt(t_lat*t_lat + E*E);
131 mu_alpha = atan2(sqrt(RESQ - x_alpha*x_alpha),E*x_alpha);
132 if (lat_geoc < 0) mu_alpha = - mu_alpha;
133 sin_mu_a = sin(mu_alpha);
134 delt_lambda = mu_alpha - lat_geoc;
135 r_alpha = x_alpha/cos(lat_geoc);
136 l_point = radius - r_alpha;
137 *alt = l_point*cos(delt_lambda);
138 denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a);
139 rho_alpha = EQUATORIAL_RADIUS*(1-EPS)/
141 delt_mu = atan2(l_point*sin(delt_lambda),rho_alpha + *alt);
142 *lat_geod = mu_alpha - delt_mu;
143 lambda_sl = atan( E*E * tan(*lat_geod) ); /* SL geoc. latitude */
144 sin_lambda_sl = sin( lambda_sl );
145 *sea_level_r = sqrt(RESQ
146 /(1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
151 void ls_geod_to_geoc( SCALAR lat_geod, SCALAR alt,
152 SCALAR *sl_radius, SCALAR *lat_geoc )
154 SCALAR lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py;
156 lambda_sl = atan( E*E * tan(lat_geod) ); /* sea level geocentric latitude */
157 sin_lambda_sl = sin( lambda_sl );
158 cos_lambda_sl = cos( lambda_sl );
159 sin_mu = sin(lat_geod); /* Geodetic (map makers') latitude */
160 cos_mu = cos(lat_geod);
161 *sl_radius = sqrt(RESQ
162 /(1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl));
163 py = *sl_radius*sin_lambda_sl + alt*sin_mu;
164 px = *sl_radius*cos_lambda_sl + alt*cos_mu;
165 *lat_geoc = atan2( py, px );