#include "stdio.h"
#include "math.h"
#define PI 3.141592653589793
double AngleToRadian( double alfa)
{
double alfa1,alfa2;
double HS;
alfa = alfa + 0.00000000000001;
alfa1=floor(alfa)+floor((alfa-floor(alfa))*100)/60;
alfa2=(alfa*100-floor(alfa*100.0))/36;
alfa1 += alfa2;
HS = alfa1/180*PI;
return HS;
}
void GSZS ( double a, double b, double l, double B, double *x, double *y){
double e,e1,t,u2;
double m0,m2,m4,m6,m8,a0,a2,a4,a6,a8,X;
double n0,n2,n4,n6,n8,sin2B,sin4B,sin6B,sin8B,N;
e = (sqrt(a*a-b*b))/a; //第一偏心率
e= 0.081819;
e1 =(sqrt(a*a-b*b))/b;
t = tan(B);
u2 = e1*e1*cos(B)*cos(B);
m0 = a*(1-e*e);
m2 = 3.0*e*e*m0/2.0;
m4 = 5.0*e*e*m2/4.0;
m6 = 7.0*e*e*m4/6.0;
m8 = 9.0*e*e*m6/8.0;
a0 = m0+m2/2.0+3.0/8.0*m4 + 5.0/16.0*m6 + 35.0/128.0*m8;
a2 = m2/2.0 + m4/2.0 + 15.0*m6/32.0 + 7.0*m8/16.0;
a4 = m4/8.0 + 3.0*m6/16.0 + 7.0*m8/32.0;
a6 = m6/32.0+m8/16.0;
a8 = m8/128.0;
X = a0*B - a2*sin(2*B)/2.0 + a4*sin(4*B)/4.0- a6*sin(6*B)/6.0+ a8*sin(8*B)/8.0;
n0 =a;
n2 = 1.0*e*e*n0/2.0;
n4 = 3.0*e*e*n2/4.0;
n6 = 5.0*e*e*n4/6.0;
n8 = 7.0*e*e*n6/8.0;
sin2B = pow(sin(B),2);
sin4B = pow(sin(B),4);
sin6B = pow(sin(B),6);
sin8B = pow(sin(B),8);
N = n0 + n2*sin2B + n4*sin4B + n6*sin6B+n8*sin8B;
*x = X+N/2.0*t*cos(B)*cos(B)*l*l+N*t*(5-t*t+9*u2+4*pow(u2,2))*pow(cos(B),4)*pow(l,4)/24.0 + N*t*(61-58*t*t+pow(t,4))*pow(cos(B),6)*pow(l,6)/720.0;
*y = N*cos(B)*l +N/6.0*(l-t*t+u2)*pow(cos(B),3)*pow(l,3)+ N/120.0*(5-18*t*t+pow(t,4)+14*u2 - 58*u2*t*t)*pow(cos(B),5)*pow(l,5);
}
int main(){
double B,L;
double a,b;
double n;
double L0;
double B1,L1,l;
double x,y;
double *pointer_x,*pointer_y;
pointer_x = &x;
pointer_y = &y;
B=40;
L=117;
a=6378140.0000000000;
b=6356755.2882;
n = round((L+3)/6);
L0=n*6-3; //获取当地中央子午线经度
B1 = AngleToRadian(B);
L0 = AngleToRadian(L0);
L1 = AngleToRadian(L);
l = L1-L0;
printf(" L0 = %f \n",L0);
GSZS(a,b,l,B1,pointer_x,pointer_y);
printf("x = %lf \n y = %lf \n",x,(y+500000 + n*1000000));
return 1;
}