3 * Routines to deal with polar math and transformations.
6 // Written by Curtis Olson, started June 1997.
8 // Copyright (C) 1997 Curtis L. Olson - http://www.flightgear.org/~curt
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.
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.
20 // You should have received a copy of the GNU Library General Public
21 // License along with this library; if not, write to the
22 // Free Software Foundation, Inc., 59 Temple Place - Suite 330,
23 // Boston, MA 02111-1307, USA.
33 # error This library requires C++
37 #include <simgear/constants.h>
38 #include <simgear/math/point3d.hxx>
43 * Find the Altitude above the Ellipsoid (WGS84) given the Earth
44 * Centered Cartesian coordinate vector Distances are specified in
46 * @param cp point specified in cartesian coordinates
47 * @return altitude above the (wgs84) earth in meters
49 inline double sgGeodAltFromCart(const Point3D& p)
52 SGGeodesy::SGCartToGeod(SGVec3<double>(p.x(), p.y(), p.z()), geod);
53 return geod.getElevationM();
58 * Convert a polar coordinate to a cartesian coordinate. Lon and Lat
59 * must be specified in radians. The SG convention is for distances
60 * to be specified in meters
61 * @param p point specified in polar coordinates
62 * @return the same point in cartesian coordinates
64 inline Point3D sgPolarToCart3d(const Point3D& p)
67 SGGeodesy::SGGeocToCart(SGGeoc::fromRadM(p.lon(), p.lat(), p.radius()), cart);
68 return Point3D::fromSGVec3(cart);
73 * Convert a cartesian coordinate to polar coordinates (lon/lat
74 * specified in radians. Distances are specified in meters.
75 * @param cp point specified in cartesian coordinates
76 * @return the same point in polar coordinates
78 inline Point3D sgCartToPolar3d(const Point3D& p)
81 SGGeodesy::SGCartToGeoc(SGVec3<double>(p.x(), p.y(), p.z()), geoc);
82 return Point3D::fromSGGeoc(geoc);
87 * Calculate new lon/lat given starting lon/lat, and offset radial, and
88 * distance. NOTE: starting point is specifed in radians, distance is
89 * specified in meters (and converted internally to radians)
90 * ... assumes a spherical world.
91 * @param orig specified in polar coordinates
92 * @param course offset radial
93 * @param dist offset distance
94 * @return destination point in polar coordinates
96 Point3D calc_gc_lon_lat( const Point3D& orig, double course, double dist );
100 * Calculate course/dist given two spherical points.
101 * @param start starting point
102 * @param dest ending point
103 * @param course resulting course
104 * @param dist resulting distance
106 void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
107 double *course, double *dist );
111 * Calculate course/dist given two spherical points.
112 * @param start starting point
113 * @param dest ending point
114 * @param course resulting course
115 * @param dist resulting distance
117 void calc_gc_course_dist( const Point3D& start, const Point3D& dest,
118 double *course, double *dist );
121 #endif // _POLAR3D_HXX