]> git.mxchange.org Git - simgear.git/blob - simgear/math/fg_geodesy.hxx
Added simgear/magvar which impliments WMM 2000 world magnetic variance model.
[simgear.git] / simgear / 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
10
11 #ifndef _FG_GEODESY_HXX
12 #define _FG_GEODESY_HXX
13
14
15 #ifndef __cplusplus                                                          
16 # error This library requires C++
17 #endif                                   
18
19
20 #include <simgear/math/point3d.hxx>
21 #include <simgear/math/polar3d.hxx>
22
23
24 // fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r)
25 //     INPUTS:  
26 //         lat_geoc     Geocentric latitude, radians, + = North
27 //         radius       C.G. radius to earth center (meters)
28 //
29 //     OUTPUTS:
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)
34
35 void fgGeocToGeod( double lat_geoc, double radius, double
36                    *lat_geod, double *alt, double *sea_level_r );
37
38
39 // fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc )
40 //     INPUTS:  
41 //         lat_geod     Geodetic latitude, radians, + = North
42 //         alt          C.G. altitude above mean sea level (meters)
43 //
44 //     OUTPUTS:
45 //         sl_radius    SEA LEVEL radius to earth center (meters)
46 //                      (add Altitude to get true distance from earth center.
47 //         lat_geoc     Geocentric latitude, radians, + = North
48 //
49
50 void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius,
51                       double *lat_geoc );
52
53
54 // convert a geodetic point lon(radians), lat(radians), elev(meter) to
55 // a cartesian point
56
57 inline Point3D fgGeodToCart(const Point3D& geod) {
58     double gc_lon, gc_lat, sl_radius;
59
60     // printf("A geodetic point is (%.2f, %.2f, %.2f)\n", 
61     //        geod[0], geod[1], geod[2]);
62
63     gc_lon = geod.lon();
64     fgGeodToGeoc(geod.lat(), geod.radius(), &sl_radius, &gc_lat);
65
66     // printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon, 
67     //        gc_lat, sl_radius+geod[2]);
68
69     Point3D pp = Point3D( gc_lon, gc_lat, sl_radius + geod.radius());
70     return fgPolarToCart3d(pp);
71 }
72
73
74 // given, alt, lat1, lon1, az1 and distance (s), calculate lat2, lon2
75 // and az2.  Lat, lon, and azimuth are in degrees.  distance in meters
76 int geo_direct_wgs_84 ( double alt, double lat1, double lon1, double az1, 
77                         double s, double *lat2, double *lon2,  double *az2 );
78
79
80 // given alt, lat1, lon1, lat2, lon2, calculate starting and ending
81 // az1, az2 and distance (s).  Lat, lon, and azimuth are in degrees.
82 // distance in meters
83 int geo_inverse_wgs_84( double alt, double lat1, double lon1, double lat2,
84                         double lon2, double *az1, double *az2, double *s );
85
86
87 /***************************************************************************
88
89         TITLE:  ls_geodesy
90         
91 ----------------------------------------------------------------------------
92
93         FUNCTION:       Converts geocentric coordinates to geodetic positions
94
95 ----------------------------------------------------------------------------
96
97         MODULE STATUS:  developmental
98
99 ----------------------------------------------------------------------------
100
101         GENEALOGY:      Written as part of LaRCSim project by E. B. Jackson
102
103 ----------------------------------------------------------------------------
104
105         DESIGNED BY:    E. B. Jackson
106         
107         CODED BY:       E. B. Jackson
108         
109         MAINTAINED BY:  E. B. Jackson
110
111 ----------------------------------------------------------------------------
112
113         MODIFICATION HISTORY:
114         
115         DATE    PURPOSE                                         BY
116         
117         930208  Modified to avoid singularity near polar region.        EBJ
118         930602  Moved backwards calcs here from ls_step.                EBJ
119         931214  Changed erroneous Latitude and Altitude variables to 
120                 *lat_geod and *alt in routine ls_geoc_to_geod.          EBJ
121         940111  Changed header files from old ls_eom.h style to ls_types, 
122                 and ls_constants.  Also replaced old DATA type with new
123                 SCALAR type.                                            EBJ
124
125         CURRENT RCS HEADER:
126
127 $Header$
128
129  * Revision 1.5  1994/01/11  18:47:05  bjax
130  * Changed include files to use types and constants, not ls_eom.h
131  * Also changed DATA type to SCALAR type.
132  *
133  * Revision 1.4  1993/12/14  21:06:47  bjax
134  * Removed global variable references Altitude and Latitude.   EBJ
135  *
136  * Revision 1.3  1993/06/02  15:03:40  bjax
137  * Made new subroutine for calculating geodetic to geocentric; changed name
138  * of forward conversion routine from ls_geodesy to ls_geoc_to_geod.
139  *
140
141 ----------------------------------------------------------------------------
142
143         REFERENCES:
144
145                 [ 1]    Stevens, Brian L.; and Lewis, Frank L.: "Aircraft 
146                         Control and Simulation", Wiley and Sons, 1992.
147                         ISBN 0-471-61397-5                    
148
149
150 ----------------------------------------------------------------------------
151
152         CALLED BY:      ls_aux
153
154 ----------------------------------------------------------------------------
155
156         CALLS TO:
157
158 ----------------------------------------------------------------------------
159
160         INPUTS: 
161                 lat_geoc        Geocentric latitude, radians, + = North
162                 radius          C.G. radius to earth center, ft
163
164 ----------------------------------------------------------------------------
165
166         OUTPUTS:
167                 lat_geod        Geodetic latitude, radians, + = North
168                 alt             C.G. altitude above mean sea level, ft
169                 sea_level_r     radius from earth center to sea level at
170                                 local vertical (surface normal) of C.G.
171
172 --------------------------------------------------------------------------*/
173
174
175 #endif // _FG_GEODESY_HXX