1 /* -*- Mode: C++ -*- *****************************************************
3 * Written by Durk Talsma. Started March 1998.
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.
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.
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.
19 **************************************************************************/
21 /*************************************************************************
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.
29 ************************************************************************/
32 GeoCoord::GeoCoord(const GeoCoord& other)
38 double GeoCoord::getAngle(const GeoCoord& other) const
40 Vector first( getX(), getY(), getZ());
41 Vector secnd(other.getX(), other.getY(), other.getZ());
43 dot = VecDot(first, secnd),
44 len1 = first.VecLen(),
45 len2 = secnd.VecLen(),
48 //printf ("Dot: %f, len1: %f len2: %f\n", dot, len1, len2);
49 /*Vector pPos = prevPos - Reference->prevPos;
50 Vector pVel = prevVel - Reference->prevVel;*/
53 if ( ( (dot / len) < 1) && (dot / len > -1) && len )
54 angle = acos(dot / len);
58 GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const
60 float angle, maxAngle = 180;
62 GeoCoordVectorConstIterator i, nearest;
63 for (i = data.begin(); i != data.end(); i++)
65 angle = RAD_TO_DEG * (*i)->getAngle(ref);
76 GeoCoordContainer::~GeoCoordContainer()
78 GeoCoordVectorIterator i = data.begin();
79 while (i != data.end())