geocoord.h

00001 /* -*- Mode: C++ -*- *****************************************************
00002  * geocoord.h
00003  * Written by Durk Talsma. Started July 1999.
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 GeoCoord 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 
00031 
00032 #ifndef _GEOCOORD_H_
00033 #define _GEOCOORD_H_
00034 
00035 #include <simgear/compiler.h>
00036 
00037 
00038 #include <math.h>
00039 #include <vector>
00040 
00041 SG_USING_NAMESPACE(std);
00042 
00043 #include <simgear/constants.h>
00044 
00045 class SGGeoCoord
00046 {
00047 protected:
00048   float lat;
00049   float lon;
00050 
00051 public:
00052   SGGeoCoord() { lat = 0.0; lon = 0.0;};
00053   SGGeoCoord(float la, float lo) { lat = la; lon = lo;};
00054   SGGeoCoord(const SGGeoCoord& other);
00055   virtual ~SGGeoCoord() {};
00056   
00057   void set(float la, float lo) { lat = la; lon = lo; }; 
00058   float getLat() const { return lat; };
00059   float getLon() const { return lon; };
00060   float getX()   const { return cos(SGD_DEGREES_TO_RADIANS*lat) * cos(SGD_DEGREES_TO_RADIANS*lon); };
00061   float getY()   const { return cos(SGD_DEGREES_TO_RADIANS*lat) * sin(SGD_DEGREES_TO_RADIANS*lon); };
00062   float getZ()   const { return sin(SGD_DEGREES_TO_RADIANS*lat); };
00063 
00064 
00065   virtual const char * getDescription() {return 0;};
00066 };
00067 
00068 typedef vector<SGGeoCoord*> SGGeoCoordVector;
00069 typedef vector<SGGeoCoord*>::iterator SGGeoCoordVectorIterator;
00070 typedef vector<SGGeoCoord*>::const_iterator SGGeoCoordVectorConstIterator;
00071 
00072 /************************************************************************
00073  * SGGeoCoordContainer is a simple container class, that stores objects
00074  * derived from SGGeoCoord. Basically, it is a wrapper around an STL vector,
00075  * with some added functionality
00076  ***********************************************************************/
00077 
00078 class SGGeoCoordContainer
00079 {
00080 protected:
00081   SGGeoCoordVector data;
00082 
00083 public:
00084   SGGeoCoordContainer() {};
00085   virtual ~SGGeoCoordContainer();
00086 
00087   const SGGeoCoordVector& getData() const { return data; };
00088   SGGeoCoord* getNearest(const SGGeoCoord& ref) const;
00089 };
00090 
00091 
00092 #endif // _GEO_COORD_H_

Generated on Mon Dec 17 09:30:54 2007 for SimGear by  doxygen 1.5.1