]> git.mxchange.org Git - flightgear.git/blob - src/Time/geocoord.h
Various SGI portability tweaks.
[flightgear.git] / src / Time / geocoord.h
1 /* -*- Mode: C++ -*- *****************************************************
2  * geocoord.h
3  * Written by Durk Talsma. Started July 1999.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU General Public License as
7  * published by the Free Software Foundation; either version 2 of the
8  * License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18  *
19  **************************************************************************/
20
21 /*************************************************************************
22  *
23  * This file defines a small and simple class to store geocentric 
24  * coordinates. Basically, class GeoCoord is intended as a base class for
25  * any kind of of object, that can be categorized according to its 
26  * location on earth, be it navaids, or aircraft. This class for originally
27  * written for FlightGear, in order to store Timezone control points. 
28  *
29  ************************************************************************/
30
31
32 #ifndef _GEOCOORD_H_
33 #define _GEOCOORD_H_
34
35 #include <Include/compiler.h>
36
37
38 #include <math.h>
39 #include <string>
40 #include STL_IOSTREAM
41 //#include <streambuf> // looks like streambuf does not exist on linux.
42 // But it looks like it isn't used anyways -:)
43 #include <vector>
44
45 FG_USING_NAMESPACE(std);
46
47 #include "mymath.h"
48
49 class GeoCoord
50 {
51 protected:
52   float lat;
53   float lon;
54
55 public:
56   GeoCoord() { lat = 0.0; lon = 0.0;};
57   GeoCoord(float la, float lo) { lat = la; lon = lo;};
58   GeoCoord(const GeoCoord& other);
59   virtual ~GeoCoord() {};
60   
61   void set(float la, float lo) { lat = la; lon = lo; }; 
62   float getLat() const { return lat; };
63   float getLon() const { return lon; };
64   float getX()   const { return cos(DEG_TO_RAD*lat) * cos(DEG_TO_RAD*lon); };
65   float getY()   const { return cos(DEG_TO_RAD*lat) * sin(DEG_TO_RAD*lon); };
66   float getZ()   const { return sin(DEG_TO_RAD*lat); };
67
68
69   double getAngle(const GeoCoord& other) const;
70   virtual void print() {} ; 
71   virtual char *getDescription() {return 0;};
72 };
73
74 typedef vector<GeoCoord*> GeoCoordVector;
75 typedef vector<GeoCoord*>::iterator GeoCoordVectorIterator;
76 typedef vector<GeoCoord*>::const_iterator GeoCoordVectorConstIterator;
77
78 /************************************************************************
79  * GeoCoordContainer is a simple container class, that stores objects
80  * derived from GeoCoord. Basically, it is a wrapper around an STL vector,
81  * with some added functionality
82  ***********************************************************************/
83
84 class GeoCoordContainer
85 {
86 protected:
87   GeoCoordVector data;
88
89 public:
90   GeoCoordContainer() {};
91   virtual ~GeoCoordContainer();
92
93   const GeoCoordVector& getData() const { return data; };
94   GeoCoord* getNearest(const GeoCoord& ref) const;
95 };
96
97
98 #endif // _GEO_COORD_H_