#include "stdafx.h"
#include <math.h>
#define PI 3.14159
/*
This program is mainly a function to convert from GPS coordinates to three-dimensional coordinates of the Earth.
*/
void Gps2ecef (double latitude, double longitude, double height, double &x, double &y, double &z)
{
Double A = 6378137;
Double b = 6356752.314245;
Double E = (a*a-b*b)/(A*A);
Double coslat = cos (latitude*pi/180);
Double Sinlat = sin (latitude*pi/180);
Double coslong = cos (longitude*pi/180);
Double Sinlong = sin (longitude*pi/180);
Double N = A/(sqrt (1-e*sinlat*sinlat));
Double NH = N + height;
X = NH * Coslat * coslong;
Y = NH * Coslat * sinlong;
Z = (b*b*n/(a*a) + height) * Sinlat;
}
int _tmain (int argc, _tchar* argv[])
{
Double latitude = 22.4331034196;
Double longitude = 113.3957986107;
Double h = 23.3;
Double XX = 0.0;
Double YY = 0.0;
Double ZZ = 0.0;
GPS2ECEF (latitude, longitude, H, XX, YY, ZZ);
return 0;
}
GPS coordinates turn ECEF Earth coordinates