]> git.mxchange.org Git - simgear.git/blob - simgear/route/waypoint.hxx
Doxygen.
[simgear.git] / simgear / route / waypoint.hxx
1 /** 
2  * \file waypoint.hxx
3  * Provides a class to manage waypoints
4  */
5
6 // Written by Curtis Olson, started September 2000.
7 //
8 // Copyright (C) 2000  Curtis L. Olson  - curt@hfrl.umn.edu
9 //
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
14 //
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // 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., 675 Mass Ave, Cambridge, MA 02139, USA.
23 //
24 // $Id$
25
26
27 #ifndef _WAYPOINT_HXX
28 #define _WAYPOINT_HXX
29
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35
36 #ifdef HAVE_CONFIG_H
37 #  include <config.h>
38 #endif
39
40 #include <simgear/compiler.h>
41
42 #include STL_STRING
43
44 SG_USING_STD(string);
45
46
47 /**
48  * A class to manage waypoints.
49  */
50
51 class SGWayPoint {
52
53 public:
54
55     /**
56      * Waypoint mode.
57      * <li> WGS84 requests all bearing and distance math be done assuming a
58      *      WGS84 ellipsoid world.  This is the most expensive computationally,
59      *      but also the most accurate.
60      * <li> SPHERICAL requests all bearing and distance math be done assuming
61      *      the world is a perfect sphere.  This is less compuntationally
62      *      expensive than using wgs84 math and still a fairly good
63      *      approximation of the real world, especially over shorter distances.
64      * <li> CARTESIAN requests all math be done assuming the coordinates specify
65      *      position in a Z = up world.
66      */
67     enum modetype { 
68         WGS84 = 0,
69         SPHERICAL = 1,
70         CARTESIAN = 2
71     };
72
73 private:
74
75     modetype mode;
76
77     double target_lon;
78     double target_lat;
79     double target_alt;
80     double distance;
81
82     string id;
83
84 public:
85
86     /** Default constructor */
87     SGWayPoint();
88
89     /**
90      * Construct a waypoint
91      * @param lon destination longitude
92      * @param lat destination latitude
93      * @param alt target altitude
94      * @param mode type of coordinates/math to use
95      * @param s waypoint identifier
96      */
97     SGWayPoint( const double lon, const double lat, const double alt,
98                 const modetype m = WGS84, const string s = "" );
99
100     /** Destructor */
101     ~SGWayPoint();
102
103     /**
104      * Calculate course and distances.  For WGS84 and SPHERICAL
105      * coordinates lat, lon, and course are in degrees, alt and
106      * distance are in meters.  For CARTESIAN coordinates x = lon, y =
107      * lat.  Course is in degrees and distance is in what ever units x
108      * and y are in.
109      * @param cur_lon (in) current longitude
110      * @param cur_lat (in) current latitude
111      * @param cur_alt (in) current altitude
112      * @param course (out) heading from current location to this waypoint
113      * @param distance (out) distance from current location to this waypoint
114      */
115     void CourseAndDistance( const double cur_lon, const double cur_lat,
116                             const double cur_alt,
117                             double *course, double *distance ) const;
118
119     /**
120      * Calculate course and distances between a specified starting waypoint
121      * and this waypoint.
122      * @param wp (in) original waypoint
123      * @param course (out) heading from current location to this waypoint
124      * @param distance (out) distance from current location to this waypoint
125      */
126     void CourseAndDistance( const SGWayPoint &wp,
127                             double *course, double *distance ) const;
128
129     /** @return waypoint mode */
130     inline modetype get_mode() const { return mode; }
131
132     /** @return waypoint longitude */
133     inline double get_target_lon() const { return target_lon; }
134
135     /** @return waypoint latitude */
136     inline double get_target_lat() const { return target_lat; }
137
138     /** @return waypoint altitude */
139     inline double get_target_alt() const { return target_alt; }
140
141     /**
142      * This value is not calculated by this class.  It is simply a
143      * placeholder for the user to stash a distance value.  This is useful
144      * when you stack waypoints together into a route.  You can calculate the
145      * distance from the previous waypoint once and save it here.  Adding up
146      * all the distances here plus the distance to the first waypoint gives you
147      * the total route length.  Note, you must update this value yourself, this
148      * is for your convenience only.
149      * @return waypoint distance holder (what ever the user has stashed here)
150      */
151     inline double get_distance() const { return distance; }
152
153     /**
154      * Set the waypoint distance value to a value of our choice.
155      * @param d distance 
156      */
157     inline void set_distance( double d ) { distance = d; }
158
159     /** @return waypoint id */
160     inline string get_id() const { return id; }
161
162 };
163
164
165 #endif // _WAYPOINT_HXX