source: ntrip/trunk/GnssCenter/monitor/utils.cpp@ 7692

Last change on this file since 7692 was 5450, checked in by mervart, 11 years ago
File size: 2.6 KB
RevLine 
[5437]1
2#include <math.h>
3
4#include "utils.h"
5
6using namespace std;
[5447]7using namespace GnssCenter;
[5437]8
9// Rectangular Coordinates -> Ellipsoidal Coordinates
10////////////////////////////////////////////////////////////////////////////
[5450]11t_CST::t_irc t_utils::xyz2ell(const double* XYZ, double* Ell) {
[5437]12
13 const double bell = t_CST::aell*(1.0-1.0/t_CST::fInv) ;
14 const double e2 = (t_CST::aell*t_CST::aell-bell*bell)/(t_CST::aell*t_CST::aell) ;
15 const double e2c = (t_CST::aell*t_CST::aell-bell*bell)/(bell*bell) ;
16
17 double nn, ss, zps, hOld, phiOld, theta, sin3, cos3;
18
19 ss = sqrt(XYZ[0]*XYZ[0]+XYZ[1]*XYZ[1]) ;
20 zps = XYZ[2]/ss ;
21 theta = atan( (XYZ[2]*t_CST::aell) / (ss*bell) );
22 sin3 = sin(theta) * sin(theta) * sin(theta);
23 cos3 = cos(theta) * cos(theta) * cos(theta);
24
25 // Closed formula
26 Ell[0] = atan( (XYZ[2] + e2c * bell * sin3) / (ss - e2 * t_CST::aell * cos3) );
27 Ell[1] = atan2(XYZ[1],XYZ[0]) ;
28 nn = t_CST::aell/sqrt(1.0-e2*sin(Ell[0])*sin(Ell[0])) ;
29 Ell[2] = ss / cos(Ell[0]) - nn;
30
31 const int MAXITER = 100;
32 for (int ii = 1; ii <= MAXITER; ii++) {
33 nn = t_CST::aell/sqrt(1.0-e2*sin(Ell[0])*sin(Ell[0])) ;
34 hOld = Ell[2] ;
35 phiOld = Ell[0] ;
36 Ell[2] = ss/cos(Ell[0])-nn ;
37 Ell[0] = atan(zps/(1.0-e2*nn/(nn+Ell[2]))) ;
38 if ( fabs(phiOld-Ell[0]) <= 1.0e-11 && fabs(hOld-Ell[2]) <= 1.0e-5 ) {
[5450]39 return t_CST::success;
[5437]40 }
41 }
42
[5450]43 return t_CST::failure;
[5437]44}
45
46// Rectangular Coordinates -> North, East, Up Components
47////////////////////////////////////////////////////////////////////////////
[5450]48void t_utils::xyz2neu(const double* Ell, const double* xyz, double* neu) {
[5437]49
50 double sinPhi = sin(Ell[0]);
51 double cosPhi = cos(Ell[0]);
52 double sinLam = sin(Ell[1]);
53 double cosLam = cos(Ell[1]);
54
55 neu[0] = - sinPhi*cosLam * xyz[0]
56 - sinPhi*sinLam * xyz[1]
57 + cosPhi * xyz[2];
58
59 neu[1] = - sinLam * xyz[0]
60 + cosLam * xyz[1];
61
62 neu[2] = + cosPhi*cosLam * xyz[0]
63 + cosPhi*sinLam * xyz[1]
64 + sinPhi * xyz[2];
65}
66
67// North, East, Up Components -> Rectangular Coordinates
68////////////////////////////////////////////////////////////////////////////
[5450]69void t_utils::neu2xyz(const double* Ell, const double* neu, double* xyz) {
[5437]70
71 double sinPhi = sin(Ell[0]);
72 double cosPhi = cos(Ell[0]);
73 double sinLam = sin(Ell[1]);
74 double cosLam = cos(Ell[1]);
75
76 xyz[0] = - sinPhi*cosLam * neu[0]
77 - sinLam * neu[1]
78 + cosPhi*cosLam * neu[2];
79
80 xyz[1] = - sinPhi*sinLam * neu[0]
81 + cosLam * neu[1]
82 + cosPhi*sinLam * neu[2];
83
84 xyz[2] = + cosPhi * neu[0]
85 + sinPhi * neu[2];
86}
87
Note: See TracBrowser for help on using the repository browser.