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.
30 #include <simgear/compiler.h>
32 #include <simgear/math/SGMath.hxx>
33 #include <simgear/math/SGGeod.hxx>
39 * A class to manage waypoints.
48 * <li> WGS84 requests all bearing and distance math be done assuming a
49 * WGS84 ellipsoid world. This is the most expensive computationally,
50 * but also the most accurate.
51 * <li> SPHERICAL requests all bearing and distance math be done assuming
52 * the world is a perfect sphere. This is less compuntationally
53 * expensive than using wgs84 math and still a fairly good
54 * approximation of the real world, especially over shorter distances.
65 // route data associated with the waypoint
73 * Construct a waypoint
74 * @param lon destination longitude
75 * @param lat destination latitude
76 * @param alt target altitude
77 * @param mode type of coordinates/math to use
78 * @param s waypoint identifier
79 * @param n waypoint name
81 SGWayPoint( const double lon = 0.0, const double lat = 0.0,
82 const double alt = 0.0, const modetype m = WGS84,
83 const std::string& s = "", const std::string& n = "" );
86 * Construct from a geodetic position, in WGS84 coordinates
88 SGWayPoint(const SGGeod& pos, const std::string& s, const std::string& n);
94 * Calculate course and distances. For WGS84 and SPHERICAL
95 * coordinates lat, lon, and course are in degrees, alt and
96 * distance are in meters. For CARTESIAN coordinates x = lon, y =
97 * lat. Course is in degrees and distance is in what ever units x
99 * @param cur_lon (in) current longitude
100 * @param cur_lat (in) current latitude
101 * @param cur_alt (in) current altitude
102 * @param course (out) heading from current location to this waypoint
103 * @param dist (out) distance from current location to this waypoint
105 void CourseAndDistance( const double cur_lon, const double cur_lat,
106 const double cur_alt,
107 double *course, double *dist ) const;
109 void CourseAndDistance(const SGGeod& current,
110 double& course, double& dist ) const;
113 * Calculate course and distances between a specified starting waypoint
115 * @param wp (in) original waypoint
116 * @param course (out) heading from current location to this waypoint
117 * @param dist (out) distance from current location to this waypoint
119 void CourseAndDistance( const SGWayPoint &wp,
120 double *course, double *dist ) const;
122 /** @return waypoint longitude */
123 inline double get_target_lon() const { return pos.getLongitudeDeg(); }
125 /** @return waypoint latitude */
126 inline double get_target_lat() const { return pos.getLatitudeDeg(); }
128 /** @return waypoint altitude */
129 inline double get_target_alt() const { return pos.getElevationM(); }
131 inline const SGGeod& get_target() const { return pos; }
136 inline void setTargetAltFt(double elev)
137 { pos.setElevationFt(elev); }
140 * This value is not calculated by this class. It is simply a
141 * placeholder for the user to stash a distance value. This is useful
142 * when you stack waypoints together into a route. You can calculate the
143 * distance from the previous waypoint once and save it here. Adding up
144 * all the distances here plus the distance to the first waypoint gives you
145 * the total route length. Note, you must update this value yourself, this
146 * is for your convenience only.
147 * @return waypoint distance holder (what ever the user has stashed here)
149 inline double get_distance() const { return _distance; }
152 * Set the waypoint distance value to a value of our choice.
155 inline void set_distance( double d ) { _distance = d; }
157 inline double get_track() const { return _track; }
158 inline void set_track(double t) { _track = t; }
160 inline double get_speed() const { return _speed; }
161 inline void set_speed(double v) { _speed = v; }
163 /** @return waypoint id */
164 inline const std::string& get_id() const { return id; }
166 /** @return waypoint name */
167 inline const std::string& get_name() const { return name; }
172 #endif // _WAYPOINT_HXX