利用日期、经纬度求日出日落时间 C语言程序代码

利用日期、经纬度求日出日落时间 C语言程序代码,第1张

#define PI 31415926 

 #include<mathh> 

 #include<iostream> 

 using namespace std; 

 int days_of_month_1[]={31,28,31,30,31,30,31,31,30,31,30,31}; 

 int days_of_month_2[]={31,29,31,30,31,30,31,31,30,31,30,31}; 

 long double h=-0833; 

 //定义全局变量 

void input_date(int c[]){ 

     int i; 

     cout<<"Enter the date (form: 2009 03 10):"<<endl; 

     for(i=0;i<3;i++){ 

         cin>>c[i]; 

     } 

 } 

 //输入日期 

void input_glat(int c[]){ 

     int i; 

     cout<<"Enter the degree of latitude(range: 0°- 60°,form: 40 40 40 (means 40°40′40″)):"<<endl; 

     for(i=0;i<3;i++){ 

         cin>>c[i]; 

     } 

 } 

 //输入纬度 

void input_glong(int c[]){ 

     int i; 

     cout<<"Enter the degree of longitude(west is negativ,form: 40 40 40 (means 40°40′40″)):"<<endl; 

     for(i=0;i<3;i++){ 

         cin>>c[i]; 

     } 

 } 

 //输入经度 

int leap_year(int year){ 

     if(((year%400==0) || (year%100!=0) && (year%4==0))) return 1; 

     else return 0; 

 } 

 //判断是否为闰年:若为闰年,返回1;若非闰年,返回0 

 int days(int year, int month, int date){ 

     int i,a=0; 

     for(i=2000;i<year;i++){ 

         if(leap_year(i)) a=a+366; 

         else a=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; 

     return a; 

 } 

 //求从格林威治时间公元2000年1月1日到计算日天数days 

 long double t_century(int days, long double UTo){ 

     return ((long double)days+UTo/360)/36525; 

 } 

 //求格林威治时间公元2000年1月1日到计算日的世纪数t 

 long double L_sun(long double t_century){ 

     return (280460+36000770t_century); 

 } 

 //求太阳的平黄径 

long double G_sun(long double t_century){ 

     return (357528+35999050t_century); 

 } 

 //求太阳的平近点角 

long double ecliptic_longitude(long double L_sun,long double G_sun){ 

     return (L_sun+1915sin(G_sunPI/180)+002sin(2G_sunPI/180)); 

 } 

 //求黄道经度 

long double earth_tilt(long double t_century){ 

     return (234393-00130t_century); 

 } 

 //求地球倾角 

long double sun_deviation(long double earth_tilt, long double ecliptic_longitude){ 

     return (180/PIasin(sin(PI/180earth_tilt)sin(PI/180ecliptic_longitude))); 

 } 

 //求太阳偏差 

long double GHA(long double UTo, long double G_sun, long double ecliptic_longitude){ 

     return (UTo-180-1915sin(G_sunPI/180)-002sin(2G_sunPI/180)+2466sin(2ecliptic_longitudePI/180)-0053sin(4ecliptic_longitudePI/180)); 

 } 

 //求格林威治时间的太阳时间角GHA 

 long double e(long double h, long double glat, long double sun_deviation){ 

     return 180/PIacos((sin(hPI/180)-sin(glatPI/180)sin(sun_deviationPI/180))/(cos(glatPI/180)cos(sun_deviationPI/180))); 

 } 

 //求修正值e 

 long double UT_rise(long double UTo, long double GHA, long double glong, long double e){ 

     return (UTo-(GHA+glong+e)); 

 } 

 //求日出时间 

long double UT_set(long double UTo, long double GHA, long double glong, long double e){ 

     return (UTo-(GHA+glong-e)); 

 } 

 //求日落时间 

long double result_rise(long double UT, long double UTo, long double glong, long double glat, int year, int month, int date){ 

     long double d; 

     if(UT>=UTo) d=UT-UTo; 

     else d=UTo-UT; 

     if(d>=01) { 

         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); 

     } 

     return UT; 

 } 

 //判断并返回结果(日出) 

long double result_set(long double UT, long double UTo, long double glong, long double glat, int year, int month, int date){ 

     long double d; 

     if(UT>=UTo) d=UT-UTo; 

     else d=UTo-UT; 

     if(d>=01){ 

         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); 

     } 

     return UT; 

 } 

 //判断并返回结果(日落) 

int Zone(long double glong){ 

     if(glong>=0) return (int)((int)(glong/150)+1); 

     else return (int)((int)(glong/150)-1); 

 } 

 //求时区 

void output(long double rise, long double set, long double glong){ 

     if((int)(60(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<10) 

         cout<<"The time at which the sun rises is "<<(int)(rise/15+Zone(glong))<<":0"<<(int)(60(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<" \n"; 

     else cout<<"The time at which the sun rises is "<<(int)(rise/15+Zone(glong))<<":"<<(int)(60(rise/15+Zone(glong)-(int)(rise/15+Zone(glong))))<<" \n"; 

     if((int)(60(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<10) 

         cout<<"The time at which the sun sets is "<<(int)(set/15+Zone(glong))<<": "<<(int)(60(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<" \n"; 

     else cout<<"The time at which the sun sets is "<<(int)(set/15+Zone(glong))<<":"<<(int)(60(set/15+Zone(glong)-(int)(set/15+Zone(glong))))<<" \n"; 

 } 

 //打印结果 

         

int main(){ 

     long double UTo=1800; 

     int year,month,date; 

     long double glat,glong; 

     int c[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; 

     long double rise,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"); 

     return 0; 

 }

卫星轨道应为椭圆,如果你还记得椭圆的几何性质的话,这个应该不难的,反正我是没记住,然后在百度上找的椭圆的性质,应该是没有错吧,呵呵。仅供参考啊

syms m n r a b c;%a,b为椭圆的长短半径,2c为焦距值

m=439;n=2384;r=6371;

a=(m+n+2r)/2;%求长半径的值

c=a-m-r;

>> b=sqrt(a^2-c^2)%根据椭圆特性,a^2= b^2 +c^2

b =

77215e+003

回答“地球物理Matlab代码在哪找”这个问题,可以从不同角度进行解答,以下是四段回答:

第一段,从Matlab官网角度解答。Matlab官网是Matlab软件的官方网站,提供了大量的Matlab代码和工具箱,可以满足不同领域的用户需求。在Matlab官网上,可以通过搜索功能找到地球物理相关的代码和工具箱,也可以通过论坛和社区等渠道获取更多的资料和帮助。

第二段,从Github角度解答。Github是一个开源的代码托管平台,汇集了全球各个领域的程序员和开发者,提供了丰富的代码资源和工具。在Github上,可以搜索到大量的地球物理相关的Matlab代码,也可以通过关注和参与开源项目,与其他开发者进行交流和合作。

第三段,从学术网站角度解答。学术网站是各个学术领域的学者和研究人员进行学术交流和资源共享的平台。在地球物理领域的学术网站上,可以找到大量的地球物理Matlab代码和工具,比如SEG(Society of Exploration Geophysicists)和AGU(American Geophysical Union)等,这些网站提供了各种地球物理领域的论文、报告和数据等资源,也包括Matlab代码和工具。

第四段,从地球物理社区角度解答。地球物理社区是地球物理领域的专业组织和协会,汇集了各个领域的地球物理学者和研究人员,提供了丰富的学术资源和交流平台。在地球物理社区中,可以通过参加学术会议、研讨会和培训班等活动,获取更多的地球物理Matlab代码和工具,也可以与其他学者和研究人员进行交流和合作。

谷歌地图程序本身没有或者未开放api,你要的话只有网页版的谷歌地图了。。。

先去注册一个谷歌地图的许可证,然后按照谷歌网站提示做成网页的形式。

最后最简单的就是用c++ mfc的webbrowser控件加载你的htm了。。。

其实算是偷梁换柱了。。。

直接用MATLAB地图工具箱(Mapping Toolbox)的distance函数就可以了,例如(为方便举例,这里只设置了4个点,30个点同样处理):

% 已知各点的经纬度(依次为京沪津渝四地)

pts = [ 

    11646 3992;

    12148 3122;

    11720 3913;

    10654 2959

    ];

% 形成两两之间对应的矩阵(对称阵,可以只看上三角或下三角)

[LA1,LA2]=meshgrid(pts(:,2));

[LO1,LO2]=meshgrid(pts(:,1));

% 计算两两之间的距离,单位为公里

R = distance(LA1,LO1,LA2,LO2,almanac('earth','wgs84'));

这里地球模型是采用的WGS84参考椭球,也可以改用其它参考椭球,具体可参考almanac函数。

得到的结果为

>> num2str(R,'%102f')

ans =

   000   106668    10836   146016

106668      000    95995   144581

 10836    95995      000   144061

146016   144581   144061      000

根据你的题目写的

#include <iostream>

#include <string>

using namespace std;

#define  EARTH_RADIUS  6371393

#define PI 314159

int main(int argc,char argv)

{

while(1)

{

char szInput[128];

string strInput;

string strTmp;

char szTmp[128];

string::size_type Index;

float LatLongitude[3]={0}; //经纬度

float Radius;

float ArcLen; //弧长

float ChordLen; //弦长

float LonDiff; //圆心角

int i=0;

cout<<"-----------------------------------------------"<<endl;

cout<<"请输入经纬度"<<endl;

cinclear();

cinsync();

cinget(szInput,sizeof(szInput));

strInput=szInput;

while((Index=strInputfind(" ")) != string::npos)

{

strTmp=strInputsubstr(0,Index);

_snprintf(szTmp,sizeof(szTmp),"%s",strTmpc_str());

sscanf(szTmp,"%f",&(LatLongitude[i]));

strInput=strInputsubstr(Index+1);

i++;

}

_snprintf(szTmp,sizeof(szTmp),"%s",strInputc_str());

sscanf(szTmp,"%f",&(LatLongitude[i]));

if(LatLongitude[0]>90 || LatLongitude[0]<-90)

{

cout<<"输入纬度有误"<<endl;

continue;

}

if(LatLongitude[1]<-180 || LatLongitude[1]>180 || LatLongitude[2]<-180 || LatLongitude[2]>180)

{

cout<<"输入经度有误"<<endl;

continue;

}

Radius=EARTH_RADIUSsin((90-LatLongitude[0])/180PI);

if(LatLongitude[2]>LatLongitude[1])

{

LonDiff=LatLongitude[2]-LatLongitude[1];

}

else

{

LonDiff=LatLongitude[1]-LatLongitude[2];

}

if(LonDiff>180)

{

LonDiff=360-LonDiff;

}

ChordLen=Radiussin(LonDiff/2/180PI)2;

ArcLen=2RadiusPI(LonDiff/360);

cout<<"两点之间的弦长:"<<ChordLen<<"千米"<<endl;

cout<<"弦长所对应的圆心角:"<<LonDiff<<"度"<<endl;

cout<<"两点之间的劣弧长:"<<ArcLen<<"千米"<<endl;

}

return 0;

}

运行

以上就是关于利用日期、经纬度求日出日落时间 C语言程序代码全部的内容,包括:利用日期、经纬度求日出日落时间 C语言程序代码、matlab问题解答,急需谢谢、地球物理matlab代码在哪找等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zz/10122018.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存