]> git.mxchange.org Git - simgear.git/blob - Math/fg_geodesy.hxx
FreeBSD support.
[simgear.git] / Math / fg_geodesy.hxx
1 // fg_geodesy.hxx -- routines to convert between geodetic and geocentric 
2 //                   coordinate systems.
3 //
4 // Copied and adapted directly from LaRCsim/ls_geodesy.c
5 //
6 // See below for the complete original LaRCsim comments.
7 //
8 // $Id$
9 // (Log is kept at end of this file)
10
11
12 #ifndef _FG_GEODESY_HXX
13 #define _FG_GEODESY_HXX
14
15
16 #ifndef __cplusplus                                                          
17 # error This library requires C++
18 #endif                                   
19
20
21 #include <Math/point3d.hxx>
22 #include <Math/polar3d.hxx>
23
24
25 // fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
26 //     INPUTS:  
27 //         lat_geoc     Geocentric latitude, radians, + = North
28 //         radius       C.G. radius to earth center (meters)
29 //
30 //     OUTPUTS:
31 //         lat_geod     Geodetic latitude, radians, + = North
32 //         alt          C.G. altitude above mean sea level (meters)
33 //         sea_level_r  radius from earth center to sea level at
34 //                      local vertical (surface normal) of C.G. (meters)
35
36 void fgGeocToGeod( double lat_geoc, double radius, double
37                    *lat_geod, double *alt, double *sea_level_r );
38
39
40 // fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
41 //     INPUTS:  
42 //         lat_geod     Geodetic latitude, radians, + = North
43 //         alt          C.G. altitude above mean sea level (meters)
44 //
45 //     OUTPUTS:
46 //         sl_radius    SEA LEVEL radius to earth center (meters)
47 //                      (add Altitude to get true distance from earth center.
48 //         lat_geoc     Geocentric latitude, radians, + = North
49 //
50
51 void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
52                       double *lat_geoc );
53
54
55 // convert a geodetic point lon(radians), lat(radians), elev(meter) to
56 // a cartesian point
57
58 inline Point3D fgGeodToCart(const Point3D& geod) {
59     Point3D cp;
60     Point3D pp;
61     double gc_lon, gc_lat, sl_radius;
62
63     // printf("A geodetic point is (%.2f, %.2f, %.2f)\n", 
64     //        geod[0], geod[1], geod[2]);
65
66     gc_lon = geod.lon();
67     fgGeodToGeoc(geod.lat(), geod.radius(), &sl_radius, &gc_lat);
68
69     // printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon, 
70     //        gc_lat, sl_radius+geod[2]);
71
72     pp = Point3D(gc_lon, gc_lat, sl_radius + geod.radius());
73     cp = fgPolarToCart3d(pp);
74     
75     // printf("A cart point is (%.8f, %.8f, %.8f)\n", cp.x, cp.y, cp.z);
76
77     return(cp);
78 }
79
80
81 /***************************************************************************
82
83         TITLE:  ls_geodesy
84         
85 ----------------------------------------------------------------------------
86
87         FUNCTION:       Converts geocentric coordinates to geodetic positions
88
89 ----------------------------------------------------------------------------
90
91         MODULE STATUS:  developmental
92
93 ----------------------------------------------------------------------------
94
95         GENEALOGY:      Written as part of LaRCSim project by E. B. Jackson
96
97 ----------------------------------------------------------------------------
98
99         DESIGNED BY:    E. B. Jackson
100         
101         CODED BY:       E. B. Jackson
102         
103         MAINTAINED BY:  E. B. Jackson
104
105 ----------------------------------------------------------------------------
106
107         MODIFICATION HISTORY:
108         
109         DATE    PURPOSE                                         BY
110         
111         930208  Modified to avoid singularity near polar region.        EBJ
112         930602  Moved backwards calcs here from ls_step.                EBJ
113         931214  Changed erroneous Latitude and Altitude variables to 
114                 *lat_geod and *alt in routine ls_geoc_to_geod.          EBJ
115         940111  Changed header files from old ls_eom.h style to ls_types, 
116                 and ls_constants.  Also replaced old DATA type with new
117                 SCALAR type.                                            EBJ
118
119         CURRENT RCS HEADER:
120
121 $Header$
122 $Log$
123 Revision 1.3  1998/10/18 01:17:11  curt
124 Point3D tweaks.
125
126 Revision 1.2  1998/10/16 23:36:37  curt
127 c++-ifying.
128
129 Revision 1.1  1998/10/16 19:30:42  curt
130 Renamed .c -> .h so we can start adding c++ supporting routines.
131
132 Revision 1.4  1998/07/08 14:40:08  curt
133 polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx
134 Updated fg_geodesy comments to reflect that routines expect and produce
135   meters.
136
137 Revision 1.3  1998/04/21 17:03:48  curt
138 Prepairing for C++ integration.
139
140 Revision 1.2  1998/01/22 02:59:38  curt
141 Changed #ifdef FILE_H to #ifdef _FILE_H
142
143 Revision 1.1  1997/07/31 23:13:14  curt
144 Initial revision.
145
146 Revision 1.1  1997/05/29 00:09:56  curt
147 Initial Flight Gear revision.
148
149  * Revision 1.5  1994/01/11  18:47:05  bjax
150  * Changed include files to use types and constants, not ls_eom.h
151  * Also changed DATA type to SCALAR type.
152  *
153  * Revision 1.4  1993/12/14  21:06:47  bjax
154  * Removed global variable references Altitude and Latitude.   EBJ
155  *
156  * Revision 1.3  1993/06/02  15:03:40  bjax
157  * Made new subroutine for calculating geodetic to geocentric; changed name
158  * of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
159  *
160
161 ----------------------------------------------------------------------------
162
163         REFERENCES:
164
165                 [ 1]    Stevens, Brian L.; and Lewis, Frank L.: "Aircraft 
166                         Control and Simulation", Wiley and Sons, 1992.
167                         ISBN 0-471-61397-5                    
168
169
170 ----------------------------------------------------------------------------
171
172         CALLED BY:      ls_aux
173
174 ----------------------------------------------------------------------------
175
176         CALLS TO:
177
178 ----------------------------------------------------------------------------
179
180         INPUTS: 
181                 lat_geoc        Geocentric latitude, radians, + = North
182                 radius          C.G. radius to earth center, ft
183
184 ----------------------------------------------------------------------------
185
186         OUTPUTS:
187                 lat_geod        Geodetic latitude, radians, + = North
188                 alt             C.G. altitude above mean sea level, ft
189                 sea_level_r     radius from earth center to sea level at
190                                 local vertical (surface normal) of C.G.
191
192 --------------------------------------------------------------------------*/
193
194
195 #endif // _FG_GEODESY_HXX
196
197
198 // $Log$
199 // Revision 1.3  1998/10/18 01:17:11  curt
200 // Point3D tweaks.
201 //
202 // Revision 1.2  1998/10/16 23:36:37  curt
203 // c++-ifying.
204 //
205 // Revision 1.1  1998/10/16 19:30:42  curt
206 // Renamed .c -> .h so we can start adding c++ supporting routines.
207 //
208 // Revision 1.4  1998/07/08 14:40:08  curt
209 // polar3d.[ch] renamed to polar3d.[ch]xx, vector.[ch] renamed to vector.[ch]xx
210 // Updated fg_geodesy comments to reflect that routines expect and produce
211 //   meters.
212 //
213 // Revision 1.3  1998/04/21 17:03:48  curt
214 // Prepairing for C++ integration.
215 //
216 // Revision 1.2  1998/01/22 02:59:38  curt
217 // Changed #ifdef FILE_H to #ifdef _FILE_H
218 //
219 // Revision 1.1  1997/07/31 23:13:14  curt
220 // Initial revision.
221 //
222