1 // ATCProjection.cxx - A convienience projection class for the ATC/AI system.
3 // Written by David Luff, started 2002.
5 // Copyright (C) 2002 David C Luff - david.luff@nottingham.ac.uk
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
25 #include "ATCProjection.hxx"
27 #include <simgear/constants.h>
29 FGATCProjection::FGATCProjection() {
33 _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
36 FGATCProjection::FGATCProjection(const Point3D& centre) {
38 _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
41 FGATCProjection::~FGATCProjection() {
44 void FGATCProjection::Init(const Point3D& centre) {
46 _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
49 Point3D FGATCProjection::ConvertToLocal(const Point3D& pt) {
50 double delta_lat = pt.lat() - _origin.lat();
51 double delta_lon = pt.lon() - _origin.lon();
53 double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
54 double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
56 return(Point3D(x,y,0.0));
59 Point3D FGATCProjection::ConvertFromLocal(const Point3D& pt) {
60 double delta_lat = asin(pt.y() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
61 double delta_lon = (asin(pt.x() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
63 return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, 0.0));
66 /**********************************************************************************/
68 FGATCAlignedProjection::FGATCAlignedProjection() {
72 _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
75 FGATCAlignedProjection::FGATCAlignedProjection(const Point3D& centre, double heading) {
77 _theta = heading * SG_DEGREES_TO_RADIANS;
78 _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
81 FGATCAlignedProjection::~FGATCAlignedProjection() {
84 void FGATCAlignedProjection::Init(const Point3D& centre, double heading) {
86 _theta = heading * SG_DEGREES_TO_RADIANS;
87 _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
90 Point3D FGATCAlignedProjection::ConvertToLocal(const Point3D& pt) {
91 // convert from lat/lon to orthogonal
92 double delta_lat = pt.lat() - _origin.lat();
93 double delta_lon = pt.lon() - _origin.lon();
94 double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
95 double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
100 x = x*cos(_theta) - y*sin(_theta);
101 y = (xbar*sin(_theta)) + (y*cos(_theta));
104 return(Point3D(x,y,pt.elev()));
107 Point3D FGATCAlignedProjection::ConvertFromLocal(const Point3D& pt) {
109 double thi = _theta * -1.0;
110 double x = pt.x()*cos(thi) - pt.y()*sin(thi);
111 double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
113 // convert from orthogonal to lat/lon
114 double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
115 double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
117 return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, pt.elev()));