2002-12-04 19:38:04 +00:00
|
|
|
// ATCProjection.cxx - A convienience projection class for the ATC/AI system.
|
|
|
|
//
|
|
|
|
// Written by David Luff, started 2002.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
#include "ATCProjection.hxx"
|
|
|
|
#include <math.h>
|
|
|
|
#include <simgear/constants.h>
|
|
|
|
|
|
|
|
FGATCProjection::FGATCProjection() {
|
2005-11-29 19:58:37 +00:00
|
|
|
_origin.setlat(0.0);
|
|
|
|
_origin.setlon(0.0);
|
|
|
|
_origin.setelev(0.0);
|
|
|
|
_correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
FGATCProjection::FGATCProjection(const Point3D& centre) {
|
2005-11-29 19:58:37 +00:00
|
|
|
_origin = centre;
|
|
|
|
_correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
|
2005-09-09 12:33:23 +00:00
|
|
|
}
|
|
|
|
|
2002-10-02 15:27:49 +00:00
|
|
|
FGATCProjection::~FGATCProjection() {
|
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
void FGATCProjection::Init(const Point3D& centre) {
|
2005-11-29 19:58:37 +00:00
|
|
|
_origin = centre;
|
|
|
|
_correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
Point3D FGATCProjection::ConvertToLocal(const Point3D& pt) {
|
2005-11-29 19:58:37 +00:00
|
|
|
double delta_lat = pt.lat() - _origin.lat();
|
|
|
|
double delta_lon = pt.lon() - _origin.lon();
|
2002-10-02 15:27:49 +00:00
|
|
|
|
2005-11-29 19:58:37 +00:00
|
|
|
double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
|
|
|
|
double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
|
2002-10-02 15:27:49 +00:00
|
|
|
|
|
|
|
return(Point3D(x,y,0.0));
|
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
Point3D FGATCProjection::ConvertFromLocal(const Point3D& pt) {
|
2005-11-29 19:58:37 +00:00
|
|
|
double delta_lat = asin(pt.y() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
|
|
|
|
double delta_lon = (asin(pt.x() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
|
|
|
|
|
|
|
|
return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, 0.0));
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**********************************************************************************/
|
|
|
|
|
|
|
|
FGATCAlignedProjection::FGATCAlignedProjection() {
|
2005-11-29 19:58:37 +00:00
|
|
|
_origin.setlat(0.0);
|
|
|
|
_origin.setlon(0.0);
|
|
|
|
_origin.setelev(0.0);
|
|
|
|
_correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
|
|
|
|
}
|
|
|
|
|
|
|
|
FGATCAlignedProjection::FGATCAlignedProjection(const Point3D& centre, double heading) {
|
|
|
|
_origin = centre;
|
|
|
|
_theta = heading * SG_DEGREES_TO_RADIANS;
|
|
|
|
_correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGATCAlignedProjection::~FGATCAlignedProjection() {
|
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
void FGATCAlignedProjection::Init(const Point3D& centre, double heading) {
|
2005-11-29 19:58:37 +00:00
|
|
|
_origin = centre;
|
|
|
|
_theta = heading * SG_DEGREES_TO_RADIANS;
|
|
|
|
_correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
Point3D FGATCAlignedProjection::ConvertToLocal(const Point3D& pt) {
|
2002-10-02 15:27:49 +00:00
|
|
|
// convert from lat/lon to orthogonal
|
2005-11-29 19:58:37 +00:00
|
|
|
double delta_lat = pt.lat() - _origin.lat();
|
|
|
|
double delta_lon = pt.lon() - _origin.lon();
|
|
|
|
double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
|
|
|
|
double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
|
2002-10-02 15:27:49 +00:00
|
|
|
|
|
|
|
// Align
|
2005-11-29 19:58:37 +00:00
|
|
|
if(_theta != 0.0) {
|
|
|
|
double xbar = x;
|
|
|
|
x = x*cos(_theta) - y*sin(_theta);
|
|
|
|
y = (xbar*sin(_theta)) + (y*cos(_theta));
|
|
|
|
}
|
2002-10-02 15:27:49 +00:00
|
|
|
|
2004-01-23 17:14:08 +00:00
|
|
|
return(Point3D(x,y,pt.elev()));
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|
|
|
|
|
2005-10-25 13:49:55 +00:00
|
|
|
Point3D FGATCAlignedProjection::ConvertFromLocal(const Point3D& pt) {
|
2003-10-19 19:38:01 +00:00
|
|
|
// de-align
|
2005-11-29 19:58:37 +00:00
|
|
|
double thi = _theta * -1.0;
|
2003-10-19 19:38:01 +00:00
|
|
|
double x = pt.x()*cos(thi) - pt.y()*sin(thi);
|
|
|
|
double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
|
|
|
|
|
|
|
|
// convert from orthogonal to lat/lon
|
2005-11-29 19:58:37 +00:00
|
|
|
double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
|
|
|
|
double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
|
2003-10-19 19:38:01 +00:00
|
|
|
|
2005-11-29 19:58:37 +00:00
|
|
|
return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, pt.elev()));
|
2002-10-02 15:27:49 +00:00
|
|
|
}
|