3 * Provides a class to manage waypoints
6 // Written by Curtis Olson, started September 2000.
8 // Copyright (C) 2000 Curtis L. Olson - curt@hfrl.umn.edu
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.
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.
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.
32 # error This library requires C++
36 #include <simgear/compiler.h>
38 #include <simgear/math/SGMath.hxx>
39 #include <simgear/math/SGGeod.hxx>
45 * A class to manage waypoints.
54 * <li> WGS84 requests all bearing and distance math be done assuming a
55 * WGS84 ellipsoid world. This is the most expensive computationally,
56 * but also the most accurate.
57 * <li> SPHERICAL requests all bearing and distance math be done assuming
58 * the world is a perfect sphere. This is less compuntationally
59 * expensive than using wgs84 math and still a fairly good
60 * approximation of the real world, especially over shorter distances.
80 * Construct a waypoint
81 * @param lon destination longitude
82 * @param lat destination latitude
83 * @param alt target altitude
84 * @param mode type of coordinates/math to use
85 * @param s waypoint identifier
86 * @param n waypoint name
88 SGWayPoint( const double lon = 0.0, const double lat = 0.0,
89 const double alt = 0.0, const modetype m = WGS84,
90 const std::string& s = "", const std::string& n = "" );
93 * Construct from a geodetic position, in WGS84 coordinates
95 SGWayPoint(const SGGeod& pos, const std::string& s, const std::string& n);
101 * Calculate course and distances. For WGS84 and SPHERICAL
102 * coordinates lat, lon, and course are in degrees, alt and
103 * distance are in meters. For CARTESIAN coordinates x = lon, y =
104 * lat. Course is in degrees and distance is in what ever units x
106 * @param cur_lon (in) current longitude
107 * @param cur_lat (in) current latitude
108 * @param cur_alt (in) current altitude
109 * @param course (out) heading from current location to this waypoint
110 * @param dist (out) distance from current location to this waypoint
112 void CourseAndDistance( const double cur_lon, const double cur_lat,
113 const double cur_alt,
114 double *course, double *dist ) const;
116 void CourseAndDistance(const SGGeod& current,
117 double& course, double& dist ) const;
120 * Calculate course and distances between a specified starting waypoint
122 * @param wp (in) original waypoint
123 * @param course (out) heading from current location to this waypoint
124 * @param dist (out) distance from current location to this waypoint
126 void CourseAndDistance( const SGWayPoint &wp,
127 double *course, double *dist ) const;
129 /** @return waypoint longitude */
130 inline double get_target_lon() const { return pos.getLongitudeDeg(); }
132 /** @return waypoint latitude */
133 inline double get_target_lat() const { return pos.getLatitudeDeg(); }
135 /** @return waypoint altitude */
136 inline double get_target_alt() const { return pos.getElevationM(); }
138 inline const SGGeod& get_target() const { return pos; }
141 * This value is not calculated by this class. It is simply a
142 * placeholder for the user to stash a distance value. This is useful
143 * when you stack waypoints together into a route. You can calculate the
144 * distance from the previous waypoint once and save it here. Adding up
145 * all the distances here plus the distance to the first waypoint gives you
146 * the total route length. Note, you must update this value yourself, this
147 * is for your convenience only.
148 * @return waypoint distance holder (what ever the user has stashed here)
150 inline double get_distance() const { return distance; }
153 * Set the waypoint distance value to a value of our choice.
156 inline void set_distance( double d ) { distance = d; }
158 /** @return waypoint id */
159 inline const std::string& get_id() const { return id; }
161 /** @return waypoint name */
162 inline const std::string& get_name() const { return name; }
167 #endif // _WAYPOINT_HXX