head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.41; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.59; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.05; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.22.03; author curt; state Exp; branches; next ; desc @@ 1.4 log @Updated doxygen docs. @ text @
Main Page Class Hierarchy Compound List File List Compound Members File Members

# waypoint.cxx

    00001 // waypoint.cxx -- Class to hold data and return info relating to a waypoint
    00002 //
    00003 // Written by Curtis Olson, started September 2000.
    00004 //
    00005 // Copyright (C) 2000  Curtis L. Olson  - curt@@hfrl.umn.edu
    00006 //
    00007 // This program is free software; you can redistribute it and/or
    00008 // modify it under the terms of the GNU General Public License as
    00009 // published by the Free Software Foundation; either version 2 of the
    00010 // License, or (at your option) any later version.
    00011 //
    00012 // This program is distributed in the hope that it will be useful, but
    00013 // WITHOUT ANY WARRANTY; without even the implied warranty of
    00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00015 // General Public License for more details.
    00016 //
    00017 // You should have received a copy of the GNU General Public License
    00018 // along with this program; if not, write to the Free Software
    00019 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
    00020 //
    00021 // $Id: waypoint.cxx,v 1.6 2001/11/27 03:17:43 curt Exp $
    00022
    00023
    00024 #include <simgear/math/polar3d.hxx>
    00025 #include <simgear/math/sg_geodesy.hxx>
    00026
    00027 #include "waypoint.hxx"
    00028
    00029
    00030 // Constructor
    00031 SGWayPoint::SGWayPoint( const double lon, const double lat, const double alt,
    00032                         const modetype m, const string s ) {
    00033     target_lon = lon;
    00034     target_lat = lat;
    00035     target_alt = alt;
    00036     mode = m;
    00037     id = s;
    00038 }
    00039
    00040
    00041 // Destructor
    00042 SGWayPoint::~SGWayPoint() {
    00043 }
    00044
    00045
    00046 // Calculate course and distances.  For WGS84 and SPHERICAL
    00047 // coordinates lat, lon, and course are in degrees, alt and distance
    00048 // are in meters.  For CARTESIAN coordinates x = lon, y = lat.  Course
    00049 // is in degrees and distance is in what ever units x and y are in.
    00050 void SGWayPoint::CourseAndDistance( const double cur_lon,
    00051                                     const double cur_lat,
    00052                                     const double cur_alt,
    00053                                     double *course, double *distance ) const {
    00054     if ( mode == WGS84 ) {
    00055         double reverse;
    00056         geo_inverse_wgs_84( cur_alt, cur_lat, cur_lon, target_lat, target_lon,
    00057                             course, &reverse, distance );
    00058     } else if ( mode == SPHERICAL ) {
    00059         Point3D current( cur_lon * SGD_DEGREES_TO_RADIANS, cur_lat * SGD_DEGREES_TO_RADIANS, 0.0 );
    00060         Point3D target( target_lon * SGD_DEGREES_TO_RADIANS, target_lat * SGD_DEGREES_TO_RADIANS, 0.0 );
    00061         calc_gc_course_dist( current, target, course, distance );
    00062         *course = 360.0 - *course * SGD_RADIANS_TO_DEGREES;
    00063     } else if ( mode == CARTESIAN ) {
    00064         double dx = target_lon - cur_lon;
    00065         double dy = target_lat - cur_lat;
    00066         *course = -atan2( dy, dx ) * SGD_RADIANS_TO_DEGREES - 90;
    00067         while ( *course < 0 ) {
    00068             *course += 360.0;
    00069         }
    00070         while ( *course > 360.0 ) {
    00071             *course -= 360.0;
    00072         }
    00073         *distance = sqrt( dx * dx + dy * dy );
    00074     }
    00075 }
    00076
    00077 // Calculate course and distances between two waypoints
    00078 void SGWayPoint::CourseAndDistance( const SGWayPoint &wp,
    00079                         double *course, double *distance ) const {
    00080     CourseAndDistance( wp.get_target_lon(),
    00081                        wp.get_target_lat(),
    00082                        wp.get_target_alt(),
    00083                        course, distance );
    00084 }

@ 1.3 log @Oops, try again. @ text @d93 1 a93 1