X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Ftiming%2Fgeocoord.cxx;h=d3f522600643e38167c34d165e08b6cae7fcd529;hb=145a7fa1467c028f80e141a324950b2c47e34b7b;hp=a52d26d033bcd9424d936949b08503da7073c254;hpb=a7459489ff6624d5696814d0165d399220cef09d;p=simgear.git diff --git a/simgear/timing/geocoord.cxx b/simgear/timing/geocoord.cxx index a52d26d0..d3f52260 100644 --- a/simgear/timing/geocoord.cxx +++ b/simgear/timing/geocoord.cxx @@ -12,82 +12,48 @@ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * - * You should have received a copy of the GNU Library General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * **************************************************************************/ /************************************************************************* * * This file defines a small and simple class to store geocentric - * coordinates. Basically, class GeoCoord is intended as a base class for + * coordinates. Basically, class SGGeoCoord is intended as a base class for * any kind of of object, that can be categorized according to its * location on earth, be it navaids, or aircraft. This class for originally * written for FlightGear, in order to store Timezone control points. * ************************************************************************/ +#ifdef HAVE_CONFIG_H +# include +#endif + +#include #include "geocoord.h" -#include -GeoCoord::GeoCoord(const GeoCoord& other) +SGGeoCoord::SGGeoCoord(const SGGeoCoord& other) { lat = other.lat; lon = other.lon; } -// double GeoCoord::getAngle(const GeoCoord& other) const -// { -// Vector first( getX(), getY(), getZ()); -// Vector secnd(other.getX(), other.getY(), other.getZ()); -// double -// dot = VecDot(first, secnd), -// len1 = first.VecLen(), -// len2 = secnd.VecLen(), -// len = len1 * len2, -// angle = 0; -// //printf ("Dot: %f, len1: %f len2: %f\n", dot, len1, len2); -// /*Vector pPos = prevPos - Reference->prevPos; -// Vector pVel = prevVel - Reference->prevVel;*/ - - -// if ( ( (dot / len) < 1) && (dot / len > -1) && len ) -// angle = acos(dot / len); -// return angle; -// } - -// GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const -// { -// float angle, maxAngle = 180; - -// GeoCoordVectorConstIterator i, nearest; -// for (i = data.begin(); i != data.end(); i++) -// { -// angle = SGD_RADIANS_TO_DEGREES * (*i)->getAngle(ref); -// if (angle < maxAngle) -// { -// maxAngle = angle; -// nearest = i; -// } -// } -// return *nearest; -// } - - -GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const +SGGeoCoord* SGGeoCoordContainer::getNearest(const SGGeoCoord& ref) const { - sgVec3 first, secnd; - float dist, maxDist=SG_MAX; - sgSetVec3( first, ref.getX(), ref.getY(), ref.getZ()); - GeoCoordVectorConstIterator i, nearest; - for (i = data.begin(); i != data.end(); i++) + if (data.empty()) + return 0; + + float maxCosAng = -2; + SGVec3f refVec(ref.getX(), ref.getY(), ref.getZ()); + SGGeoCoordVectorConstIterator i, nearest; + for (i = data.begin(); i != data.end(); ++i) { - sgSetVec3(secnd, (*i)->getX(), (*i)->getY(), (*i)->getZ()); - dist = sgDistanceSquaredVec3(first, secnd); - if (dist < maxDist) + float cosAng = dot(refVec, SGVec3f((*i)->getX(), (*i)->getY(), (*i)->getZ())); + if (maxCosAng < cosAng) { - maxDist = dist; + maxCosAng = cosAng; nearest = i; } } @@ -95,9 +61,9 @@ GeoCoord* GeoCoordContainer::getNearest(const GeoCoord& ref) const } -GeoCoordContainer::~GeoCoordContainer() +SGGeoCoordContainer::~SGGeoCoordContainer() { - GeoCoordVectorIterator i = data.begin(); + SGGeoCoordVectorIterator i = data.begin(); while (i != data.end()) delete *i++; }