1 /* -*- Mode: C++ -*- *****************************************************
3 * Written by Durk Talsma. Started March 1998.
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.
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.
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.
20 **************************************************************************/
22 /*************************************************************************
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.
30 ************************************************************************/
34 GeoCoord::GeoCoord(const GeoCoord& other)
40 // double GeoCoord::getAngle(const GeoCoord& other) const
42 // Vector first( getX(), getY(), getZ());
43 // Vector secnd(other.getX(), other.getY(), other.getZ());
45 // dot = VecDot(first, secnd),
46 // len1 = first.VecLen(),
47 // len2 = secnd.VecLen(),
50 // //printf ("Dot: %f, len1: %f len2: %f\n", dot, len1, len2);
51 // /*Vector pPos = prevPos - Reference->prevPos;
52 // Vector pVel = prevVel - Reference->prevVel;*/
55 // if ( ( (dot / len) < 1) && (dot / len > -1) && len )
56 // angle = acos(dot / len);
60 // GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const
62 // float angle, maxAngle = 180;
64 // GeoCoordVectorConstIterator i, nearest;
65 // for (i = data.begin(); i != data.end(); i++)
67 // angle = SGD_RADIANS_TO_DEGREES * (*i)->getAngle(ref);
68 // if (angle < maxAngle)
78 GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const
81 float dist, maxDist=SG_MAX;
82 sgSetVec3( first, ref.getX(), ref.getY(), ref.getZ());
83 GeoCoordVectorConstIterator i, nearest;
84 for (i = data.begin(); i != data.end(); i++)
86 sgSetVec3(secnd, (*i)->getX(), (*i)->getY(), (*i)->getZ());
87 dist = sgDistanceSquaredVec3(first, secnd);
98 GeoCoordContainer::~GeoCoordContainer()
100 GeoCoordVectorIterator i = data.begin();
101 while (i != data.end())