]> git.mxchange.org Git - simgear.git/blob - simgear/math/sg_geodesy.hxx
this simple patch will enable the direct use of Point3D::get_n() instead of making...
[simgear.git] / simgear / math / sg_geodesy.hxx
1 #ifndef _SG_GEODESY_HXX
2 #define _SG_GEODESY_HXX
3
4 #include <simgear/math/point3d.hxx>
5
6 /** 
7  * Convert from geocentric coordinates to geodetic coordinates
8  * @param lat_geoc (in) Geocentric latitude, radians, + = North
9  * @param radius (in) C.G. radius to earth center (meters)
10  * @param lat_geod (out) Geodetic latitude, radians, + = North
11  * @param alt (out) C.G. altitude above mean sea level (meters)
12  * @param sea_level_r (out) radius from earth center to sea level at
13  *        local vertical (surface normal) of C.G. (meters)
14  */
15 void sgGeocToGeod(double lat_geoc, double radius,
16                   double *lat_geod, double *alt, double *sea_level_r);
17
18
19 /**
20  * Convert from geodetic coordinates to geocentric coordinates.
21  * WARNING: this function is non-reversible.  Due to the fact that
22  * "up" is a different direction for geocentric and geodetic frames,
23  * you can not simply add your "alt" parameter to the "sl_radius"
24  * result and get back (via sgGeodToGeoc()) to the coordinates you
25  * started with.  The error under normal conditions will be of
26  * centimeter order; whether that is important or not is application
27  * dependent. Consider using sgGeodToCart() instead.
28  *
29  * @param lat_geod (in) Geodetic latitude, radians, + = North
30  * @param alt (in) C.G. altitude above mean sea level (meters)
31  * @param sl_radius (out) SEA LEVEL radius to earth center (meters)
32  * @param lat_geoc (out) Geocentric latitude, radians, + = North
33  */
34 void sgGeodToGeoc(double lat_geod, double alt,
35                   double *sl_radius, double *lat_geoc );
36
37 /**
38  * Convert a cartesian point to a geodetic lat/lon/altitude.
39  *
40  * @param xyz (in) Pointer to cartesian point.
41  * @param lat (out) Latitude, in radians
42  * @param lon (out) Longitude, in radians
43  * @param alt (out) Altitude, in meters above the WGS84 ellipsoid
44  */
45 void sgCartToGeod(const double* xyz, double* lat, double* lon, double* alt);
46
47 /**
48  * Convert a cartesian point to a geodetic lat/lon/altitude.
49  * Alternate form using Point3D objects.
50  *
51  * @param cartesian point
52  * @return geodetic point
53  */
54 inline Point3D sgCartToGeod(const Point3D& p)
55 {
56     double lat, lon, alt, xyz[3];
57     xyz[0] = p.x(); xyz[1] = p.y(); xyz[2] = p.z(); 
58     sgCartToGeod(xyz, &lat, &lon, &alt);
59     return Point3D(lon, lat, alt);
60 }
61
62
63 /**
64  * Convert a geodetic lat/lon/altitude to a cartesian point.
65  *
66  * @param lat (in) Latitude, in radians
67  * @param lon (in) Longitude, in radians
68  * @param alt (in) Altitude, in meters above the WGS84 ellipsoid
69  * @param xyz (out) Pointer to cartesian point.
70  */
71 void sgGeodToCart(double lat, double lon, double alt, double* xyz);
72
73 /**
74  * Convert a geodetic lat/lon/altitude to a cartesian point.
75  * Alternate form using Point3D objects.
76  *
77  * @param geodetic point
78  * @return cartesian point
79  */
80 inline Point3D sgGeodToCart(const Point3D& geod)
81 {
82     double xyz[3];
83     sgGeodToCart(geod.lat(), geod.lon(), geod.elev(), xyz);
84     return Point3D(xyz[0], xyz[1], xyz[2]);
85 }
86
87 /**
88  * Given a starting position and an offset radial and distance,
89  * calculate an ending positon on a wgs84 ellipsoid.
90  * @param alt (in) meters
91  * @param lat1 (in) degrees
92  * @param lon1 (in) degrees
93  * @param az1 (in) degrees
94  * @param s (in) distance in meters
95  * @param lat2 (out) degrees
96  * @param lon2 (out) degrees
97  * @param az2 (out) return course in degrees
98  */
99 int geo_direct_wgs_84 ( double alt, double lat1,
100                         double lon1, double az1, 
101                         double s, double *lat2, double *lon2,
102                         double *az2 );
103
104
105 /**
106  * Given an altitude and two sets of (lat, lon) calculate great circle
107  * distance between them as well as the starting and ending azimuths.
108  * @param alt (in) meters
109  * @param lat1 (in) degrees
110  * @param lon1 (in) degrees
111  * @param lat2 (in) degrees
112  * @param lon2 (in) degrees
113  * @param az1 (out) start heading degrees
114  * @param az2 (out) end heading degrees
115  * @param s (out) distance meters
116  */
117 int geo_inverse_wgs_84( double alt, double lat1,
118                         double lon1, double lat2,
119                         double lon2, double *az1, double *az2,
120                         double *s );
121
122 #endif // _SG_GEODESY_HXX