1
0
Fork 0

General tidy up - add an extra ctor method, remove surplus defined constants, remove cout and iostream

This commit is contained in:
daveluff 2005-11-29 19:58:37 +00:00
parent 9c28ed0257
commit 49b6bef6bb
2 changed files with 48 additions and 49 deletions

View file

@ -22,95 +22,93 @@
#include <math.h> #include <math.h>
#include <simgear/constants.h> #include <simgear/constants.h>
#include <iostream>
SG_USING_STD(cout);
#define DCL_PI 3.1415926535f
//#define SG_PI ((SGfloat) M_PI)
#define DCL_DEGREES_TO_RADIANS (DCL_PI/180.0)
#define DCL_RADIANS_TO_DEGREES (180.0/DCL_PI)
FGATCProjection::FGATCProjection() { FGATCProjection::FGATCProjection() {
origin.setlat(0.0); _origin.setlat(0.0);
origin.setlon(0.0); _origin.setlon(0.0);
origin.setelev(0.0); _origin.setelev(0.0);
correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS); _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
} }
FGATCProjection::FGATCProjection(const Point3D& centre) { FGATCProjection::FGATCProjection(const Point3D& centre) {
origin = centre; _origin = centre;
correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS); _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
} }
FGATCProjection::~FGATCProjection() { FGATCProjection::~FGATCProjection() {
} }
void FGATCProjection::Init(const Point3D& centre) { void FGATCProjection::Init(const Point3D& centre) {
origin = centre; _origin = centre;
correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS); _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
} }
Point3D FGATCProjection::ConvertToLocal(const Point3D& pt) { Point3D FGATCProjection::ConvertToLocal(const Point3D& pt) {
double delta_lat = pt.lat() - origin.lat(); double delta_lat = pt.lat() - _origin.lat();
double delta_lon = pt.lon() - origin.lon(); double delta_lon = pt.lon() - _origin.lon();
double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M; double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor; double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
return(Point3D(x,y,0.0)); return(Point3D(x,y,0.0));
} }
Point3D FGATCProjection::ConvertFromLocal(const Point3D& pt) { Point3D FGATCProjection::ConvertFromLocal(const Point3D& pt) {
double delta_lat = asin(pt.y() / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES; double delta_lat = asin(pt.y() / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
double delta_lon = (asin(pt.x() / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES) / correction_factor; 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)); return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, 0.0));
} }
/**********************************************************************************/ /**********************************************************************************/
FGATCAlignedProjection::FGATCAlignedProjection() { FGATCAlignedProjection::FGATCAlignedProjection() {
origin.setlat(0.0); _origin.setlat(0.0);
origin.setlon(0.0); _origin.setlon(0.0);
origin.setelev(0.0); _origin.setelev(0.0);
correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS); _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);
} }
FGATCAlignedProjection::~FGATCAlignedProjection() { FGATCAlignedProjection::~FGATCAlignedProjection() {
} }
void FGATCAlignedProjection::Init(const Point3D& centre, double heading) { void FGATCAlignedProjection::Init(const Point3D& centre, double heading) {
origin = centre; _origin = centre;
theta = heading * DCL_DEGREES_TO_RADIANS; _theta = heading * SG_DEGREES_TO_RADIANS;
correction_factor = cos(origin.lat() * DCL_DEGREES_TO_RADIANS); _correction_factor = cos(_origin.lat() * SG_DEGREES_TO_RADIANS);
} }
Point3D FGATCAlignedProjection::ConvertToLocal(const Point3D& pt) { Point3D FGATCAlignedProjection::ConvertToLocal(const Point3D& pt) {
// convert from lat/lon to orthogonal // convert from lat/lon to orthogonal
double delta_lat = pt.lat() - origin.lat(); double delta_lat = pt.lat() - _origin.lat();
double delta_lon = pt.lon() - origin.lon(); double delta_lon = pt.lon() - _origin.lon();
double y = sin(delta_lat * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M; double y = sin(delta_lat * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M;
double x = sin(delta_lon * DCL_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * correction_factor; double x = sin(delta_lon * SG_DEGREES_TO_RADIANS) * SG_EQUATORIAL_RADIUS_M * _correction_factor;
// Align // Align
double xbar = x; if(_theta != 0.0) {
x = x*cos(theta) - y*sin(theta); double xbar = x;
y = (xbar*sin(theta)) + (y*cos(theta)); x = x*cos(_theta) - y*sin(_theta);
y = (xbar*sin(_theta)) + (y*cos(_theta));
}
return(Point3D(x,y,pt.elev())); return(Point3D(x,y,pt.elev()));
} }
Point3D FGATCAlignedProjection::ConvertFromLocal(const Point3D& pt) { Point3D FGATCAlignedProjection::ConvertFromLocal(const Point3D& pt) {
//cout << "theta = " << theta << '\n';
//cout << "origin = " << origin << '\n';
// de-align // de-align
double thi = theta * -1.0; double thi = _theta * -1.0;
double x = pt.x()*cos(thi) - pt.y()*sin(thi); double x = pt.x()*cos(thi) - pt.y()*sin(thi);
double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi)); double y = (pt.x()*sin(thi)) + (pt.y()*cos(thi));
// convert from orthogonal to lat/lon // convert from orthogonal to lat/lon
double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES; double delta_lat = asin(y / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES;
double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * DCL_RADIANS_TO_DEGREES) / correction_factor; double delta_lon = (asin(x / SG_EQUATORIAL_RADIUS_M) * SG_RADIANS_TO_DEGREES) / _correction_factor;
return(Point3D(origin.lon()+delta_lon, origin.lat()+delta_lat, pt.elev())); return(Point3D(_origin.lon()+delta_lon, _origin.lat()+delta_lat, pt.elev()));
} }

View file

@ -40,8 +40,8 @@ public:
Point3D ConvertFromLocal(const Point3D& pt); Point3D ConvertFromLocal(const Point3D& pt);
private: private:
Point3D origin; // lat/lon of local area origin Point3D _origin; // lat/lon of local area origin
double correction_factor; // Reduction in surface distance per degree of longitude due to latitude. Saves having to do a cos() every call. double _correction_factor; // Reduction in surface distance per degree of longitude due to latitude. Saves having to do a cos() every call.
}; };
@ -52,6 +52,7 @@ class FGATCAlignedProjection {
public: public:
FGATCAlignedProjection(); FGATCAlignedProjection();
FGATCAlignedProjection(const Point3D& centre, double heading);
~FGATCAlignedProjection(); ~FGATCAlignedProjection();
void Init(const Point3D& centre, double heading); void Init(const Point3D& centre, double heading);
@ -63,9 +64,9 @@ public:
Point3D ConvertFromLocal(const Point3D& pt); Point3D ConvertFromLocal(const Point3D& pt);
private: private:
Point3D origin; // lat/lon of local area origin (the threshold) Point3D _origin; // lat/lon of local area origin (the threshold)
double theta; // the rotation angle for alignment in radians double _theta; // the rotation angle for alignment in radians
double correction_factor; // Reduction in surface distance per degree of longitude due to latitude. Saves having to do a cos() every call. double _correction_factor; // Reduction in surface distance per degree of longitude due to latitude. Saves having to do a cos() every call.
}; };