]> git.mxchange.org Git - simgear.git/blob - simgear/math/polar3d.hxx
Allow geocentric distance computations to return radians.
[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 #include <simgear/math/point3d.hxx>
36 #include "SGMath.hxx"
37
38 /**
39  * Calculate new lon/lat given starting lon/lat, and offset radial, and
40  * distance.  NOTE: starting point is specifed in radians, distance is
41  * specified in meters (and converted internally to radians)
42  * ... assumes a spherical world.
43  * @param orig specified in polar coordinates
44  * @param course offset radial
45  * @param dist offset distance
46  * @return destination point in polar coordinates
47  */
48 inline Point3D calc_gc_lon_lat(const Point3D& orig, double course, double dist)
49 { return Point3D::fromSGGeoc(orig.toSGGeoc().advanceRadM(course, dist)); }
50
51
52 /**
53  * Calculate course/dist given two spherical points.
54  * @param start starting point
55  * @param dest ending point
56  * @param course resulting course
57  * @param dist resulting distance
58  */
59 inline void calc_gc_course_dist( const Point3D& start, const Point3D& dest, 
60                                  double *course, double *dist )
61 {
62   SGGeoc gs = start.toSGGeoc();
63   SGGeoc gd = dest.toSGGeoc();
64   *course = SGGeoc::courseRad(gs, gd);
65   *dist = SGGeoc::distanceM(gs, gd);
66 }
67
68 #endif // _POLAR3D_HXX
69