当前位置:文档之家› 大地坐标与空间坐标的互相转换··

大地坐标与空间坐标的互相转换··

大地坐标向空间坐标转换和空间坐标向大地坐标转换的c程

#include<stdio.h>
#include<math.h>
void main()
{
float a=6378137.000,b=6356752.3142,E=0.006694379990,pi=3.14159265;
float B,L,N,H,X,Y,Z;
float K,t0,t1,t2,P;
int i;
float B1,B2,B3,L1,L2,L3;
printf("如果向进行大地坐标向空间坐标转换请输入1,进行空间坐标向大地坐标转换请输入0");
scanf("%d",&i);
if(i)
{
printf("请输入经度:B1,B2,B3");
scanf("%f%f%f",&B1,&B2,&B3);
B=(B1+B2/60+B3/3600)*pi/180;
printf("请输入纬度:L1,L2,L3");
scanf("%f%f%f",&L1,&L2,&L3);
L=(L1+L2/60+L3/3600)*pi/180;
printf("请输入大地高:H");
scanf("%f",&H);
N=a/sqrt(1-E*sin(B)*sin(B));
X=(N+H)*cos(B)*cos(L);
Y=(N+H)*cos(B)*sin(L);
Z=(N*(1-E)+H)*sin(B);
printf("X=%f\n",X);
printf("Y=%f\n",Y);
printf("Z=%f\n",Z);
}
else
{printf("请输入空间坐标:X,Y,Z");
scanf("%f%f%f",&X,&Y,&Z);
L=atan(Y/X)*180/pi;
L1=int(L);
L2=int((L-L1)*60);
L3=int(((L-L1)*60-L2)*60);
printf("大地经度:L1=%f,L2=%f,L3=%f\n",L1,L2,L3 ); t0=Z/sqrt(X*X+Y*Y);
t1=t0;
K=1+E;
P=E*a*a/b/sqrt(X*X+Y*Y);
t2=t0+P*t1/sqrt(K+t1*t1);
while(abs(t2-t1)>1E-100)
{t1=t2;
t2=t0+P*t1/sqrt(K+t1*t1);
}
B=atan(t1)*180/pi;
B1=int(B);
B2=int((B-B1)*60);
B3=int(((B-B1)*60-B2)*60);
printf("大地纬度:B1=%f,B2=%f,B3=%f\n",B1,B2,B3 ); N=a/sqrt(1-E*sin(B)*sin(B));
B=B*pi/180;
H=sqrt(X*X+Y*Y)/cos(B)-N; printf("大地高:H:\n");
printf("%f\n",H);}
}。

相关主题