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 FGATCAlignedProjection::FGATCAlignedProjection() {
30 _origin.setLatitudeRad(0);
31 _origin.setLongitudeRad(0);
32 _origin.setElevationM(0);
33 _correction_factor = cos(_origin.getLatitudeRad());
36 FGATCAlignedProjection::FGATCAlignedProjection(const SGGeod& centre, double heading) {
38 _theta = heading * SG_DEGREES_TO_RADIANS;
39 _correction_factor = cos(_origin.getLatitudeRad());
42 FGATCAlignedProjection::~FGATCAlignedProjection() {
45 void FGATCAlignedProjection::Init(const SGGeod& centre, double heading) {
47 _theta = heading * SG_DEGREES_TO_RADIANS;
48 _correction_factor = cos(_origin.getLatitudeRad());
51 SGVec3d FGATCAlignedProjection::ConvertToLocal(const SGGeod& pt) {
52 // convert from lat/lon to orthogonal
53 double delta_lat = pt.getLatitudeRad() - _origin.getLatitudeRad();
54 double delta_lon = pt.getLongitudeRad() - _origin.getLongitudeRad();
55 double y = sin(delta_lat) * SG_EQUATORIAL_RADIUS_M;
56 double x = sin(delta_lon) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
61 x = x*cos(_theta) - y*sin(_theta);
62 y = (xbar*sin(_theta)) + (y*cos(_theta));
65 return SGVec3d(x, y, pt.getElevationM());
68 SGGeod FGATCAlignedProjection::ConvertFromLocal(const SGVec3d& pt) {
70 double thi = _theta * -1.0;
71 double x = pt.x()*cos(thi) - pt.y()*sin(thi);
72 double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
74 // convert from orthogonal to lat/lon
75 double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M);
76 double delta_lon = asin(x / SG_EQUATORIAL_RADIUS_M) / _correction_factor;
78 return SGGeod::fromRadM(_origin.getLongitudeRad()+delta_lon, _origin.getLatitudeRad()+delta_lat, pt.z());