1 #include "ATCProjection.hxx"
3 #include <simgear/constants.h>
5 #define DCL_PI 3.1415926535f
6 //#define SG_PI ((SGfloat) M_PI)
7 #define DCL_DEGREES_TO_RADIANS (DCL_PI/180.0)
8 #define DCL_RADIANS_TO_DEGREES (180.0/DCL_PI)
10 FGATCProjection::FGATCProjection() {
14 correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
17 FGATCProjection::~FGATCProjection() {
20 void FGATCProjection::Init(Point3D centre) {
22 correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
25 Point3D FGATCProjection::ConvertToLocal(Point3D pt) {
26 double delta_lat = pt.lat() - origin.lat();
27 double delta_lon = pt.lon() - origin.lon();
29 double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
30 double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor;
32 return(Point3D(x,y,0.0));
35 Point3D FGATCProjection::ConvertFromLocal(Point3D pt) {
36 return(Point3D(0,0,0));
39 /**********************************************************************************/
41 FGATCAlignedProjection::FGATCAlignedProjection() {
45 correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
48 FGATCAlignedProjection::~FGATCAlignedProjection() {
51 void FGATCAlignedProjection::Init(Point3D centre, double heading) {
53 theta = heading * DCL_DEGREES_TO_RADIANS;
54 correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS);
57 Point3D FGATCAlignedProjection::ConvertToLocal(Point3D pt) {
58 // convert from lat/lon to orthogonal
59 double delta_lat = pt.lat() - origin.lat();
60 double delta_lon = pt.lon() - origin.lon();
61 double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
62 double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor;
63 //cout << "Before alignment, x = " << x << " y = " << y << '\n';
67 x = x*cos(theta) - y*sin(theta);
68 y = (xbar*sin(theta)) + (y*cos(theta));
69 //cout << "After alignment, x = " << x << " y = " << y << '\n';
71 return(Point3D(x,y,0.0));
74 Point3D FGATCAlignedProjection::ConvertFromLocal(Point3D pt) {
75 return(Point3D(0,0,0));