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 General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 **************************************************************************/
21 /*************************************************************************
23 * This file defines a small and simple class to store geocentric
24 * coordinates. Basically, class SGGeoCoord 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 ************************************************************************/
33 SGGeoCoord::SGGeoCoord(const SGGeoCoord& other)
39 // double SGGeoCoord::getAngle(const SGGeoCoord& other) const
41 // Vector first( getX(), getY(), getZ());
42 // Vector secnd(other.getX(), other.getY(), other.getZ());
44 // dot = VecDot(first, secnd),
45 // len1 = first.VecLen(),
46 // len2 = secnd.VecLen(),
49 // //printf ("Dot: %f, len1: %f len2: %f\n", dot, len1, len2);
50 // /*Vector pPos = prevPos - Reference->prevPos;
51 // Vector pVel = prevVel - Reference->prevVel;*/
54 // if ( ( (dot / len) < 1) && (dot / len > -1) && len )
55 // angle = acos(dot / len);
59 // SGGeoCoord* SGGeoCoordContainer::getNearest(const SGGeoCoord& ref) const
61 // float angle, maxAngle = 180;
63 // SGGeoCoordVectorConstIterator i, nearest;
64 // for (i = data.begin(); i != data.end(); i++)
66 // angle = SGD_RADIANS_TO_DEGREES * (*i)->getAngle(ref);
67 // if (angle < maxAngle)
77 SGGeoCoord* SGGeoCoordContainer::getNearest(const SGGeoCoord& ref) const
80 float dist, maxDist=SG_MAX;
81 sgSetVec3( first, ref.getX(), ref.getY(), ref.getZ());
82 SGGeoCoordVectorConstIterator i, nearest;
83 for (i = data.begin(); i != data.end(); i++)
85 sgSetVec3(secnd, (*i)->getX(), (*i)->getY(), (*i)->getZ());
86 dist = sgDistanceSquaredVec3(first, secnd);
97 SGGeoCoordContainer::~SGGeoCoordContainer()
99 SGGeoCoordVectorIterator i = data.begin();
100 while (i != data.end())