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