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