~jtaylor/ubuntu/oneiric/flightgear/fix-749249

« back to all changes in this revision

Viewing changes to src/ATC/ATCProjection.cxx

  • Committer: Bazaar Package Importer
  • Author(s): Ove Kaaven
  • Date: 2006-05-17 17:12:09 UTC
  • mfrom: (1.1.5 upstream) (3.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060517171209-9qbwm4q1uj05vhcj
Tags: 0.9.10-2
Updated the build dependencies for xorg 7.0. Apparently the
amd64 autobuilder doesn't use Provides.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
//
17
17
// You should have received a copy of the GNU General Public License
18
18
// along with this program; if not, write to the Free Software
19
 
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
19
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
20
 
21
21
#include "ATCProjection.hxx"
22
22
#include <math.h>
23
23
#include <simgear/constants.h>
24
24
 
25
 
#include <iostream>
26
 
SG_USING_STD(cout);
27
 
 
28
 
#define DCL_PI  3.1415926535f
29
 
//#define SG_PI  ((SGfloat) M_PI)
30
 
#define DCL_DEGREES_TO_RADIANS  (DCL_PI/180.0)
31
 
#define DCL_RADIANS_TO_DEGREES  (180.0/DCL_PI)
32
 
 
33
25
FGATCProjection::FGATCProjection() {
34
 
    origin.setlat(0.0);
35
 
    origin.setlon(0.0);
36
 
    origin.setelev(0.0);
37
 
    correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
 
26
    _origin.setlat(0.0);
 
27
    _origin.setlon(0.0);
 
28
    _origin.setelev(0.0);
 
29
    _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
38
30
}
39
31
 
40
32
FGATCProjection::FGATCProjection(const Point3D& centre) {
41
 
    origin = centre;
42
 
    correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
 
33
    _origin = centre;
 
34
    _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
43
35
}
44
36
 
45
37
FGATCProjection::~FGATCProjection() {
46
38
}
47
39
 
48
40
void FGATCProjection::Init(const Point3D& centre) {
49
 
    origin = centre;
50
 
    correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
 
41
    _origin = centre;
 
42
    _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
51
43
}
52
44
 
53
45
Point3D FGATCProjection::ConvertToLocal(const Point3D& pt) {
54
 
    double delta_lat = pt.lat() - origin.lat();
55
 
    double delta_lon = pt.lon() - origin.lon();
 
46
    double delta_lat = pt.lat() - _origin.lat();
 
47
    double delta_lon = pt.lon() - _origin.lon();
56
48
 
57
 
    double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
58
 
    double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor;
 
49
    double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
 
50
    double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
59
51
 
60
52
    return(Point3D(x,y,0.0));
61
53
}
62
54
 
63
55
Point3D FGATCProjection::ConvertFromLocal(const Point3D& pt) {
64
 
        double delta_lat = asin(pt.y() / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES;
65
 
        double delta_lon = (asin(pt.x() / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES) / correction_factor;
66
 
        
67
 
    return(Point3D(origin.lon()+delta_lon, origin.lat()+delta_lat, 0.0));
 
56
    double delta_lat = asin(pt.y() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
 
57
    double delta_lon = (asin(pt.x() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
 
58
    
 
59
    return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, 0.0));
68
60
}
69
61
 
70
62
/**********************************************************************************/
71
63
 
72
64
FGATCAlignedProjection::FGATCAlignedProjection() {
73
 
    origin.setlat(0.0);
74
 
    origin.setlon(0.0);
75
 
    origin.setelev(0.0);
76
 
    correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
 
65
    _origin.setlat(0.0);
 
66
    _origin.setlon(0.0);
 
67
    _origin.setelev(0.0);
 
68
    _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
 
69
}
 
70
 
 
71
FGATCAlignedProjection::FGATCAlignedProjection(const Point3D& centre, double heading) {
 
72
    _origin = centre;
 
73
    _theta = heading * SG_DEGREES_TO_RADIANS;
 
74
    _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
77
75
}
78
76
 
79
77
FGATCAlignedProjection::~FGATCAlignedProjection() {
80
78
}
81
79
 
82
80
void FGATCAlignedProjection::Init(const Point3D& centre, double heading) {
83
 
    origin = centre;
84
 
    theta = heading * DCL_DEGREES_TO_RADIANS;
85
 
    correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
 
81
    _origin = centre;
 
82
    _theta = heading * SG_DEGREES_TO_RADIANS;
 
83
    _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
86
84
}
87
85
 
88
86
Point3D FGATCAlignedProjection::ConvertToLocal(const Point3D& pt) {
89
87
    // convert from lat/lon to orthogonal
90
 
    double delta_lat = pt.lat() - origin.lat();
91
 
    double delta_lon = pt.lon() - origin.lon();
92
 
    double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
93
 
    double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor;
 
88
    double delta_lat = pt.lat() - _origin.lat();
 
89
    double delta_lon = pt.lon() - _origin.lon();
 
90
    double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
 
91
    double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
94
92
 
95
93
    // Align
96
 
    double xbar = x;
97
 
    x = x*cos(theta) - y*sin(theta);
98
 
    y = (xbar*sin(theta)) + (y*cos(theta));
 
94
    if(_theta != 0.0) {
 
95
        double xbar = x;
 
96
        x = x*cos(_theta) - y*sin(_theta);
 
97
        y = (xbar*sin(_theta)) + (y*cos(_theta));
 
98
    }
99
99
 
100
100
    return(Point3D(x,y,pt.elev()));
101
101
}
102
102
 
103
103
Point3D FGATCAlignedProjection::ConvertFromLocal(const Point3D& pt) {
104
 
        //cout << "theta = " << theta << '\n';
105
 
        //cout << "origin = " << origin << '\n';
106
104
    // de-align
107
 
    double thi = theta * -1.0;
 
105
    double thi = _theta * -1.0;
108
106
    double x = pt.x()*cos(thi) - pt.y()*sin(thi);
109
107
    double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
110
108
 
111
109
    // convert from orthogonal to lat/lon
112
 
    double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES;
113
 
    double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES) / correction_factor;
 
110
    double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
 
111
    double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
114
112
 
115
 
    return(Point3D(origin.lon()+delta_lon, origin.lat()+delta_lat, pt.elev()));
 
113
    return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, pt.elev()));
116
114
}