head 1.4; access; symbols; locks; strict; comment @# @; 1.4 date 2002.09.07.01.50.39; author curt; state Exp; branches; next 1.3; 1.3 date 2002.08.31.19.01.56; author curt; state Exp; branches; next 1.2; 1.2 date 2002.08.31.18.54.03; author curt; state Exp; branches; next 1.1; 1.1 date 2002.02.15.17.21.59; 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

# route.cxx

    00001 // route.cxx -- Class to manage a list of waypoints (route)
    00002 //
    00003 // Written by Curtis Olson, started October 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: route.cxx,v 1.2 2000/10/23 14:57:29 curt Exp $
    00022
    00023
    00024 #include <plib/sg.h>
    00025
    00026 #include <simgear/math/vector.hxx>
    00027
    00028 #include "route.hxx"
    00029
    00030
    00031 // constructor
    00032 SGRoute::SGRoute() {
    00033     route.clear();
    00034 }
    00035
    00036
    00037 // destructor
    00038 SGRoute::~SGRoute() {
    00039 }
    00040
    00041
    00042 // Calculate perpendicular distance from the current route segment
    00043 // This routine assumes all points are laying on a flat plane and
    00044 // ignores the altitude (or Z) dimension.  For best results, use with
    00045 // CARTESIAN way points.
    00046 double SGRoute::distance_off_route( double x, double y ) const {
    00047     if ( current_wp > 0 ) {
    00048         int n0 = current_wp - 1;
    00049         int n1 = current_wp;
    00050         sgdVec3 p, p0, p1, d;
    00051         sgdSetVec3( p, x, y, 0.0 );
    00052         sgdSetVec3( p0,
    00053                     route[n0].get_target_lon(), route[n0].get_target_lat(),
    00054                     0.0 );
    00055         sgdSetVec3( p1,
    00056                     route[n1].get_target_lon(), route[n1].get_target_lat(),
    00057                     0.0 );
    00058         sgdSubVec3( d, p0, p1 );
    00059
    00060         return sqrt( sgdClosestPointToLineDistSquared( p, p0, d ) );
    00061
    00062     } else {
    00063         // We are tracking the first waypoint so there is no route
    00064         // segment.  If you add the current location as the first
    00065         // waypoint and the actual waypoint as the second, then we
    00066         // will have a route segment and calculate distance from it.
    00067
    00068         return 0;
    00069     }
    00070 }

@ 1.3 log @Oops, try again. @ text @d79 1 a79 1