#include "stdafx.h"
#include <math.h>
#define PI 3.14159
/*
该程序主要是实现从GPS坐标转换为地球的三维坐标的函数
*/
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;
}