]> git.mxchange.org Git - flightgear.git/blob - src/Time/geocoord.cxx
Added first stab at a socket class.
[flightgear.git] / src / Time / geocoord.cxx
1 /* -*- Mode: C++ -*- *****************************************************
2  * geocoord.h
3  * Written by Durk Talsma. Started March 1998.
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 #include "geocoord.h"
31
32 GeoCoord::GeoCoord(const GeoCoord& other)
33 {
34   lat = other.lat;
35   lon = other.lon;
36 }
37
38 double GeoCoord::getAngle(const GeoCoord& other) const
39 {
40   Vector first(      getX(),       getY(),       getZ());
41   Vector secnd(other.getX(), other.getY(), other.getZ());
42     double
43       dot = VecDot(first, secnd),
44       len1 = first.VecLen(),
45       len2 = secnd.VecLen(),
46       len = len1 * len2,
47       angle = 0;
48     //printf ("Dot: %f, len1: %f len2: %f\n", dot, len1, len2);
49     /*Vector pPos = prevPos - Reference->prevPos;
50       Vector pVel = prevVel - Reference->prevVel;*/
51
52
53     if ( ( (dot / len) < 1) && (dot / len > -1) && len )
54         angle = acos(dot / len);
55     return angle;
56 }
57
58 GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const
59 {
60   float angle, maxAngle = 180;
61
62   GeoCoordVectorConstIterator i, nearest;
63   for (i = data.begin(); i != data.end(); i++)
64     {
65       angle = RAD_TO_DEG * (*i)->getAngle(ref);
66       if (angle < maxAngle)
67         {
68           maxAngle = angle;
69           nearest = i;
70         }
71     }
72   return *nearest;
73 }
74
75
76 GeoCoordContainer::~GeoCoordContainer()
77 {
78     GeoCoordVectorIterator i = data.begin();
79   while (i != data.end())
80     delete *i++;
81 }