00001 /* -*- Mode: C++ -*- ***************************************************** 00002 * geocoord.h 00003 * Written by Durk Talsma. Started March 1998. 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Library General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Library General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU General Public License 00016 * along with this program; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 00018 * 00019 **************************************************************************/ 00020 00021 /************************************************************************* 00022 * 00023 * This file defines a small and simple class to store geocentric 00024 * coordinates. Basically, class SGGeoCoord is intended as a base class for 00025 * any kind of of object, that can be categorized according to its 00026 * location on earth, be it navaids, or aircraft. This class for originally 00027 * written for FlightGear, in order to store Timezone control points. 00028 * 00029 ************************************************************************/ 00030 #ifdef HAVE_CONFIG_H 00031 # include <simgear_config.h> 00032 #endif 00033 00034 #include <simgear/math/SGMath.hxx> 00035 #include "geocoord.h" 00036 00037 SGGeoCoord::SGGeoCoord(const SGGeoCoord& other) 00038 { 00039 lat = other.lat; 00040 lon = other.lon; 00041 } 00042 00043 SGGeoCoord* SGGeoCoordContainer::getNearest(const SGGeoCoord& ref) const 00044 { 00045 if (data.empty()) 00046 return 0; 00047 00048 float maxCosAng = -2; 00049 SGVec3f refVec(ref.getX(), ref.getY(), ref.getZ()); 00050 SGGeoCoordVectorConstIterator i, nearest; 00051 for (i = data.begin(); i != data.end(); ++i) 00052 { 00053 float cosAng = dot(refVec, SGVec3f((*i)->getX(), (*i)->getY(), (*i)->getZ())); 00054 if (maxCosAng < cosAng) 00055 { 00056 maxCosAng = cosAng; 00057 nearest = i; 00058 } 00059 } 00060 return *nearest; 00061 } 00062 00063 00064 SGGeoCoordContainer::~SGGeoCoordContainer() 00065 { 00066 SGGeoCoordVectorIterator i = data.begin(); 00067 while (i != data.end()) 00068 delete *i++; 00069 }