c语言经纬度
#definePI3.1415926
#include<math.h>
#include<iostream>
usingnamespacestd;
intdays_of_month_1[]={31,28,31,30,31,30,31,31,30,31,30,31};
intdays_of_month_2[]={31,29,31,30,31,30,31,31,30,31,30,31};
longdoubleh=-0.833;
//定义全局变量
voidinput_date(intc[]){
inti;
cout<<"Enterthedate(form:20090310):"<<endl;
for(i=0;i<3;i++){
cin>>c[i];
}
}
//输入日期
voidinput_glat(intc[]){
inti;
cout<<"Enterthedegreeoflatitude(range:0°-60°,form:404040(means40°40′40″)):"<<endl;
for(i=0;i<3;i++){
cin>>c[i];
}
}
//输入纬度
voidinput_glong(intc[]){
inti;
cout<<"Enterthedegreeoflongitude(westisnegativ,form:404040(means40°40′40″)):"<<endl;
for(i=0;i<3;i++){
cin>>c[i];
}
}
//输入经度
intleap_year(intyear){
if(((year%400==0)||(year%100!=0)&&(year%4==0)))return1;
elsereturn0;
}
//判断是否为闰年:若为闰年,返回1;若非闰年,返回0
intdays(intyear,intmonth,intdate){
inti,a=0;
for(i=2000;i<year;i++){
if(leap_year(i))a=a+366;
elsea=a+365;
}
if(leap_year(year)){
for(i=0;i<month-1;i++){
a=a+days_of_month_2[i];
}
}
else{
for(i=0;i<month-1;i++){
a=a+days_of_month_1[i];
}
}
a=a+date;
returna;
}
//求从格林威治时间公元2000年1月1日到计算日天数days
longdoublet_century(intdays,longdoubleUTo){
return((longdouble)days+UTo/360)/36525;
}
//求格林威治时间公元2000年1月1日到计算日的世纪数t
longdoubleL_sun(longdoublet_century){
return(280.460+36000.770*t_century);
}
//求太阳的平黄径
longdoubleG_sun(longdoublet_century){
return(357.528+35999.050*t_century);
}
//求太阳的平近点角
longdoubleecliptic_longitude(longdoubleL_sun,longdoubleG_sun){
return(L_sun+1.915*sin(G_sun*PI/180)+0.02*sin(2*G_sun*PI/180));
}
//求黄道经度
longdoubleearth_tilt(longdoublet_century){
return(23.4393-0.0130*t_century);
}
//求地球倾角
longdoublesun_deviation(longdoubleearth_tilt,longdoubleecliptic_longitude){
return(180/PI*asin(sin(PI/180*earth_tilt)*sin(PI/180*ecliptic_longitude)));
}
//求太阳偏差
longdoubleGHA(longdoubleUTo,longdoubleG_sun,longdoubleecliptic_longitude){
return(UTo-180-1.915*sin(G_sun*PI/180)-0.02*sin(2*G_sun*PI/180)+2.466*sin(2*ecliptic_longitude*PI/180)-0.053*sin(4*ecliptic_longitude*PI/180));
}
//求格林威治时间的太阳时间角GHA
longdoublee(longdoubleh,longdoubleglat,longdoublesun_deviation){
return180/PI*acos((sin(h*PI/180)-sin(glat*PI/180)*sin(sun_deviation*PI/180))/(cos(glat*PI/180)*cos(sun_deviation*PI/180)));
}
//求修正值e
longdoubleUT_rise(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){
return(UTo-(GHA+glong+e));
}
//求日出时间
longdoubleUT_set(longdoubleUTo,longdoubleGHA,longdoubleglong,longdoublee){
return(UTo-(GHA+glong-e));
}
//求日落时间
longdoubleresult_rise(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){
longdoubled;
if(UT>=UTo)d=UT-UTo;
elsed=UTo-UT;
if(d>=0.1){
UTo=UT;
UT=UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));
result_rise(UT,UTo,glong,glat,year,month,date);
}
returnUT;
}
//判断并返回结果(日出)
longdoubleresult_set(longdoubleUT,longdoubleUTo,longdoubleglong,longdoubleglat,intyear,intmonth,intdate){
longdoubled;
if(UT>=UTo)d=UT-UTo;
elsed=UTo-UT;
if(d>=0.1){
UTo=UT;
UT=UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo))))));
result_set(UT,UTo,glong,glat,year,month,date);
}
returnUT;
}
//判断并返回结果(日落)
intZone(longdoubleglong){
if(glong>=0)return(int)((int)(glong/15.0)+1);
elsereturn(int)((int)(glong/15.0)-1);
}
//求时区
voidoutput(longdoublerise,longdoubleset,longdoubleglong){
if((int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<10)
cout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":0"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";
elsecout<<"Thetimeatwhichthesunrisesis"<<(int)(rise/15+Zone(glong))<<":"<<(int)(60*(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<". ";
if((int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<10)
cout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";
elsecout<<"Thetimeatwhichthesunsetsis"<<(int)(set/15+Zone(glong))<<":"<<(int)(60*(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<". ";
}
//打印结果intmain(){
longdoubleUTo=180.0;
intyear,month,date;
longdoubleglat,glong;
intc[3];
input_date(c);
year=c[0];
month=c[1];
date=c[2];
input_glat(c);
glat=c[0]+c[1]/60+c[2]/3600;
input_glong(c);
glong=c[0]+c[1]/60+c[2]/3600;
longdoublerise,set;
rise=result_rise(UT_rise(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);
set=result_set(UT_set(UTo,GHA(UTo,G_sun(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))),glong,e(h,glat,sun_deviation(earth_tilt(t_century(days(year,month,date),UTo)),ecliptic_longitude(L_sun(t_century(days(year,month,date),UTo)),G_sun(t_century(days(year,month,date),UTo)))))),UTo,glong,glat,year,month,date);
output(rise,set,glong);
system("pause");
return0;
}
『贰』 C语言知道经纬度求两地距离的题目,求高手指点哪里错了,对了再加分
最后的计算s的公式有问题,因为反余弦函数y=arccosx中,y的取值范围只能是-π/2 ≤ y ≤ π/2,而地球上两点间的夹角明显在0到180°之间,所以这个地方你还应该加上角度判断语句,另外你的R的单位是km,最后的结果页应该是km。
『叁』 求c点的经纬度,求讲解
70°s,45°E
『肆』 请问点C的经纬度是多少
北纬22.5度,西经30度
『伍』 C语言中怎么表示经纬度呢
提供一思路,仅参考:
参照坐标系点的表示法
a(x,y)
『陆』 C() D() 经纬度
c:165w,40N
d:150E,60N
『柒』 C语言实现经纬度的转换
办法很多,三维字符数组,指针字符数组都可以,分别保存字符串到数组元素,最后以%s输出即可。
我来写个最简单的
#include "stdafx.h"
#include "stdlib.h"
#include "string.h"
void explain_NS(char * str)
{
char tmp_ca[30] = "";
if(str[0] == 'N')
strcpy(tmp_ca,"北纬");
else
strcpy(tmp_ca,"南纬");
char *p = tmp_ca;
while(*p) p++;
strncpy(p, str+1, 2);
p += 2;
*p = 176;
p ++;
strncpy(p,str+3,2);
p += 2;
*p = 39;
p++;
strncpy(p, str+6,5);
p += 5;
*p = 34;
printf("%s\n",tmp_ca);
}
void explain_EW(char * str)
{
char tmp_ca[30] = "";
if(str[0] == 'E')
strcpy(tmp_ca,"东经");
else
strcpy(tmp_ca,"西经");
char *p = tmp_ca;
while(*p) p++;
strncpy(p, str+1, 3);
p += 3;
*p = 176;
p ++;
strncpy(p,str+4,2);
p += 2;
*p = 39;
p++;
strncpy(p, str+7,5);
p += 5;
*p = 34;
printf("%s\n",tmp_ca);
}
int _tmain(int argc, _TCHAR* argv[])
{
char ca[30] = "N3018.93661";
char cb[30] = "E12022.88281";
explain_NS(ca);
explain_EW(cb);
system("pause");
return 0;
}
『捌』 c语言中计算gps坐标转经纬度
就是纯计算公式,一个公式就可以解决。具体逻辑如下。
一般从GPS得到的数据是经纬度。经纬度有多种表示方法。
1.) ddd.ddddd, 度 . 度的十进制小数部分(5位)例如:31.12035º
2.) ddd.mm.mmm,度 . 分 . 分的十进制小数部分(3位)例如 31º10.335′
3.) ddd.mm.ss, 度 . 分 . 秒 例如 31º12’42″
地球上任何一个固定的点都可以用确定的经纬度表示出来。
关于经纬度坐标转换的方法
一、十进制转换成经纬度
把经纬度转换成十进制的方法很简单
如下就可以了
Decimal Degrees = Degrees + minutes/60 + seconds/3600
例:57°55’56.6″ =57+55/60+56.6/3600=57.9323888888888
114°65’24.6″=114+65/60+24.6/3600=结果自己算!
如把经纬度 (longitude,latitude) (205.395583333332,57.9323888888888)
转换据成坐标(Degrees,minutes,seconds)(205°23’44.1″,57°55’56.6″)。
步骤如下:
1, 直接读取”度”:205
2,(205.395583333332-205)*60=23.734999999920 得到”分”:23
3,(23.734999999920-23)*60=44.099999995200 得到”秒”:44.1
采用同样的方法可以得到纬度坐标:57°55’56.6″
『玖』 GPS模块获取的数据转换成经纬度(度分秒的格式),C语言
3559.10468,N,12009.46619,E
N/S(北纬或南纬):北纬35 度59.10468 分;
E/W(东经或西经):东经120 度9.46619 分;
纬度(格式ddmm.mmmm:即dd 度,mm.mmmm 分);
经度(格式dddmm.mmmm:即ddd 度,mm.mmmm 分);
list和字符串操作就不写了吧。