]> git.mxchange.org Git - simgear.git/blob - simgear/math/polar3d.hxx
Modified Files:
[simgear.git] / simgear / math / polar3d.hxx
1 /**
2  * \file polar3d.hxx
3  * Routines to deal with polar math and transformations.
4  */
5
6 // Written by Curtis Olson, started June 1997.
7 //
8 // Copyright (C) 1997  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Library General Public
12 // License as published by the Free Software Foundation; either
13 // version 2 of the License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Library General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
23 //
24 // $Id$
25
26
27 #ifndef _POLAR3D_HXX
28 #define _POLAR3D_HXX
29
30
31 #ifndef __cplusplus
32 # error This library requires C++
33 #endif
34
35
36 #include <simgear/constants.h>
37 #include <simgear/math/point3d.hxx>
38
39 #include "SGMath.hxx"
40
41 /** 
42  * Find the Altitude above the Ellipsoid (WGS84) given the Earth
43  * Centered Cartesian coordinate vector Distances are specified in
44  * meters.
45  * @param cp point specified in cartesian coordinates
46  * @return altitude above the (wgs84) earth in meters
47  */
48 inline double sgGeodAltFromCart(const Point3D& p)
49 {
50   SGGeod geod;
51   SGGeodesy::SGCartToGeod(SGVec3<double>(p.x(), p.y(), p.z()), geod);
52   return geod.getElevationM();
53 }
54
55
56 /**
57  * Convert a polar coordinate to a cartesian coordinate.  Lon and Lat
58  * must be specified in radians.  The SG convention is for distances
59  * to be specified in meters
60  * @param p point specified in polar coordinates
61  * @return the same point in cartesian coordinates
62  */
63 inline Point3D sgPolarToCart3d(const Point3D& p)
64 {
65   SGVec3<double> cart;
66   SGGeodesy::SGGeocToCart(SGGeoc::fromRadM(p.lon(), p.lat(), p.radius()), cart);
67   return Point3D::fromSGVec3(cart);
68 }
69
70
71 /**
72  * Convert a cartesian coordinate to polar coordinates (lon/lat
73  * specified in radians.  Distances are specified in meters.
74  * @param cp point specified in cartesian coordinates
75  * @return the same point in polar coordinates
76  */
77 inline Point3D sgCartToPolar3d(const Point3D& p)
78 {
79   SGGeoc geoc;
80   SGGeodesy::SGCartToGeoc(SGVec3<double>(p.x(), p.y(), p.z()), geoc);
81   return Point3D::fromSGGeoc(geoc);
82 }
83
84
85 /**
86  * Calculate new lon/lat given starting lon/lat, and offset radial, and
87  * distance.  NOTE: starting point is specifed in radians, distance is
88  * specified in meters (and converted internally to radians)
89  * ... assumes a spherical world.
90  * @param orig specified in polar coordinates
91  * @param course offset radial
92  * @param dist offset distance
93  * @return destination point in polar coordinates
94  */
95 Point3D calc_gc_lon_lat( const Point3D& orig, double course, double dist );
96
97
98 /**
99  * Calculate course/dist given two spherical points.
100  * @param start starting point
101  * @param dest ending point
102  * @param course resulting course
103  * @param dist resulting distance
104  */
105 void calc_gc_course_dist( const Point3D& start, const Point3D& dest, 
106                                  double *course, double *dist );
107
108 #if 0
109 /**
110  * Calculate course/dist given two spherical points.
111  * @param start starting point
112  * @param dest ending point
113  * @param course resulting course
114  * @param dist resulting distance
115  */
116 void calc_gc_course_dist( const Point3D& start, const Point3D& dest, 
117                                  double *course, double *dist );
118 #endif // 0
119
120 #endif // _POLAR3D_HXX
121