日出日落时间计算
- 格式:doc
- 大小:21.00 KB
- 文档页数:1
基于go语言的日出日落时间计算方法Calculating sunrise and sunset times can be a useful feature for various applications, such as weather forecasting, photography, and outdoor activities. In Go programming language, there are libraries available that can help in calculating these times based on the user's location and date. One popular library is "/NOAA-EDL/Solar" which provides functions to compute the solar position, sunrise, and sunset times.在go语言中计算日出和日落时间可以是各种应用程序的有用功能,比如天气预报、摄影和户外活动。
有一些可用的库可以帮助计算这些时间,基于用户的位置和日期。
一个流行的库是"/NOAA-EDL/Solar",它提供了计算太阳位置、日出和日落时间的函数。
To calculate the sunrise and sunset times, we need to take into account factors such as the user's geographical coordinates, the date, and the elevation of the location. The Solar library in Go provides functions to input these parameters and calculate accurate sunrise and sunset times. By using these functions, developers can integrate sunrise and sunset calculations into their applications easily.要计算日出和日落时间,我们需要考虑用户的地理坐标、日期和地点的海拔等因素。
日出日落时间计算程序(C语言)//日出日落时间计算C语言程序#define PI 3.1415926#include<math.h>#include<iostream>using namespace std;intdays_of_month_1[]={31,28,31,30,31,30,31,3 1,30,31,30,31};intdays_of_month_2[]={31,29,31,30,31,30,31,3 1,30,31,30,31};long double h=-0.833;//定义全局变量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;若非闰年,返回0int 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日到计算日天数dayslong double t_century(int days, long double UTo){return ((long double)days+UTo/360)/36525;}//求格林威治时间公元2000年1月1日到计算日的世纪数tlong double L_sun(long double t_century){return(280.460+36000.770*t_century);}//求太阳的平黄径long double G_sun(long double t_century){return(357.528+35999.050*t_century);}//求太阳的平近点角long double ecliptic_longitude(long double L_sun,long double G_sun){return(L_sun+1.915*sin(G_sun*PI/180)+0.02*sin(2 *G_sun*PI/180));}//求黄道经度long double earth_tilt(long double t_century){return (23.4393-0.0130*t_century);}//求地球倾角long double sun_deviation(long double earth_tilt, long double ecliptic_longitude){return(180/PI*asin(sin(PI/180*earth_tilt)*sin(P I/180*ecliptic_longitude)));}//求太阳偏差long double GHA(long double UTo, long double G_sun, long double ecliptic_longitude){return(UTo-180-1.915*sin(G_sun*PI/180)-0.02*sin (2*G_sun*PI/180)+2.466*sin(2*ecliptic_lon gitude*PI/180)-0.053*sin(4*ecliptic_longi tude*PI/180));}//求格林威治时间的太阳时间角GHAlong double e(long double h, long double glat, long double sun_deviation){return180/PI*acos((sin(h*PI/180)-sin(glat*PI/180)*sin(sun_deviation*PI/180))/(cos(glat*P I/180)*cos(sun_deviation*PI/180)));}//求修正值elong 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>=0.1) {UTo=UT;UT=UT_rise(UTo,GHA(UTo,G_sun(t_century(da ys(year,month,date),UTo)),ecliptic_longit ude(L_sun(t_century(days(year,month,date) ,UTo)),G_sun(t_century(days(year,month,da te),UTo)))),glong,e(h,glat,sun_deviation( earth_tilt(t_century(days(year,month,date ),UTo)),ecliptic_longitude(L_sun(t_centur y(days(year,month,date),UTo)),G_sun(t_cen tury(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>=0.1){UTo=UT;UT=UT_set(UTo,GHA(UTo,G_sun(t_century(day s(year,month,date),UTo)),ecliptic_longitu de(L_sun(t_century(days(year,month,date), UTo)),G_sun(t_century(days(year,month,dat e),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_cent ury(days(year,month,date),UTo))))));result_set(UT,UTo,glong,glat,year,month,d ate);}return UT;}//判断并返回结果(日落)int Zone(long double glong){if(glong>=0) return (int)((int)(glong/15.0)+1);else return (int)((int)(glong/15.0)-1);}//求时区void output(long double rise, long double set, long double glong){if((int)(60*(rise/15+Zone(glong)-(int)(ri se/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+Z one(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+Zo ne(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=180.0; 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_su n(t_century(days(year,month,date),UTo)),e cliptic_longitude(L_sun(t_century(days(ye ar,month,date),UTo)),G_sun(t_century(days (year,month,date),UTo)))),glong,e(h,glat, sun_deviation(earth_tilt(t_century(days(y ear,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)),ecli ptic_longitude(L_sun(t_century(days(year, month,date),UTo)),G_sun(t_century(days(ye ar,month,date),UTo)))),glong,e(h,glat,sun _deviation(earth_tilt(t_century(days(year ,month,date),UTo)),ecliptic_longitude(L_s un(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;}。
日落时间计算公式
日落时间的计算公式:12-白昼时间的一半=日出时间或者12+白昼时间的一半=日落时间。
日落,指太阳徐徐降下至西方的地平线下的过程,亦即是夕阳时分,而确实的定义为日面完全没入地平线下的时间。
日出,指太阳初升出地平线或最初看到的太阳的出现。
一般是指太阳由东方的地平线徐徐升起的时间,而确实的定义为日面刚从地平线出现的一刹那,而非整个日面离开地平线。
日出日落时间的两个公式:
1、日出时间=12-(昼长时间除以2)。
2、昼长时间=在平面地图上所跨的昼弧经度乘以2÷15°。
日出日落时间的计算以及中国常见的日出日落时间以地球中心为原点O,赤道所在平面为XY平面,东经120度指向西经60度为Y轴正方向.球心指向北极为Z轴正方向.有了Y轴与Z轴就可定X轴的方向(从东经30度指向西经150度)球面方程:X^2 + Y^2 + Z^2 = 1 (设地球直径为1)日出日落时刻圈方程:Y^2 + Z'^2 = 1 (Z'以Z轴作坐标变换,见下面) Z'=Z*sin(β+90) (β为太阳光直射点纬度)求纬度α度时日出时刻.先解出纬度为α度时的X,Y坐标.X=sinα*sin(β+90)*cos(β+90)/(cosβ*cosβ)Y=-SQRT(1-X^2-sinα*sinα) (SQRT为平方根)有了XY坐标,求反正切,得出一个角度值(由于在XY平面内,0度在X轴正向,实际的东经120度在Y轴负方向上,即270度角.所以要换算一下,才能得出经度差)实算一下:代入杭州的纬度为30.15度,夏至日时,太阳直射点纬度为23.4333度.算出X=-0.21835,Y=-0.83578,反正切得出-104.64度.计算时假设杭州在Y轴负方向上(即270度或-90度).两者之间相差14.64度,换成时间就是58.56分钟.(计算出的14.64度的含义是指,夏至日那天,当赤道上(北纬0度)东经120度的地方看到日出时,北纬30.15度,东经(120-14.64)度的地方也正好看到日出.)(换句话说:当赤道上东经120度的地方看到日出时,北纬30.15度东经120度的地方日出已经过去58.56分钟了.由于赤道上是昼夜等分的(假设太阳是个点光源),即日出时刻一定在6:00.那么同一经度的北纬30.15度地方,日出时间是5:01:26左右.杭州东经120度10分.比120度还早了40秒钟.所以日出时间为5:00:46)查寿星万年历,杭州在夏至日的日出时间为4:58:07,日落时间19:04:07.实测数据2009年5月1日 星期五 所有时间为北京时间 (任意地点日月升落时刻查询)省会城市北 京116.46E 39.92N(-14分9秒)日出:05时15分(-1分15秒/日)日落:19时09分(+1分0秒/日)长 春125.35E 43.88N(+21分23秒)日出:04时31分(-1分25秒/日)日落:18时41分(+1分11秒/日)长 沙113E 28.21N(-28分0秒)日出:05时48分(-49秒/日)日落:19时03分(+35秒/日)成 都104.06E 30.67N (-1时3分45秒)日出:06时20分(-53秒/日)日落:19时42分(+39秒/日)重 庆106.54E 29.59N (-53分50秒)日出:06时12分(-51秒/日)日落:19时31分(+38秒/日)福 州119.3E 26.08N (-2分48秒)日出:05时26分(-46秒/日)日落:18时34分(+31秒/日)贵 阳106.71E 26.57N (-53分9秒)日出:06时15分(-46秒/日)日落:19时26分(+32秒/日)广 州113.23E 23.16N (-27分4秒)日出:05时54分(-40秒/日)日落:18时55分(+27秒/日)哈尔滨126.63E 45.75N (+26分31秒)日出:04时21分(-1分30秒/日)日落:18时40分(+1分17秒/日)海 口110.35E 20.02N (-38分36秒)日出:06时09分(-35秒/日)日落:19时02分(+22秒/日)杭 州120.19E 30.26N (+45秒)日出:05时17分(-53秒/日)日落:18时37分(+39秒/日)合 肥117.27E 31.86N (-10分55秒)日出:05时26分(-56秒/日)日落:18时51分(+42秒/日)呼和浩特111.65E 40.82N (-33分23秒)日出:05时33分(-1分16秒/日)日落:19时30分(+1分2秒/日)济 南117E 36.65N (-12分0秒)日出:05时19分(-1分7秒/日)日落:19时00分(+53秒/日)昆 明102.73E 25.04N (-1时9分4秒)日出:06时33分(-44秒/日)日落:19时39分(+29秒/日)拉 萨91.11E 29.97N (-1时55分33秒)日出:07时13分(-53秒/日)日落:20时33分(+38秒/日)兰 州103.73E 36.03N (-1时5分4秒)日出:06时13分(-1分4秒/日)日落:19时52分(+50秒/日)南 昌115.89E 28.68N (-16分26秒)日出:05时36分(-50秒/日)日落:18时52分(+36秒/日)南 京118.78E 32.04N (-4分52秒)日出:05时19分(-57秒/日)日落:18时45分(+43秒/日)南 宁108.33E 22.84N (-46分40秒)日出:06时14分(-39秒/日)日落:19时14分(+26秒/日)澳 门113.33E 22.13N (-26分40秒)日出:05时55分(-38秒/日)日落:18时53分(+25秒/日)上 海121.48E 31.22N (+5分55秒)日出:05时10分(-55秒/日)日落:18时33分(+41秒/日)沈 阳123.38E 41.8N (+13分31秒)日出:04时43分(-1分20秒/日)日落:18时44分(+1分5秒/日)石家庄114.48E 38.03N(-22分4秒)日出:05时27分(-1分10秒/日)日落:19时13分(+56秒/日)台 北121.5E 25.05N (+6分0秒)日出:05时19分(-44秒/日)日落:18时24分(+29秒/日)太 原112.53E 37.87N (-29分52秒)日出:05时35分(-1分9秒/日)日落:19时20分(+55秒/日)天 津117.2E 39.13N (-11分11秒)日出:05时14分(-1分13秒/日)日落:19时04分(+58秒/日)武 汉114.31E 30.52N (-22分45秒)日出:05时40分(-53秒/日)日落:19时01分(+40秒/日)乌鲁木齐87.68E 43.77N (-2时9分16秒)日出:07时02分(-1分25秒/日)日落:21时12分(+1分11秒/日)西 安108.95E 34.27N (-44分11秒)日出:05时55分(-1分0秒/日)日落:19时28分(+47秒/日)西 宁101.74E 36.56N (-1时13分2秒)日出:06时20分(-1分6秒/日)日落:20时01分(+51秒/日)香 港114.1E 22.2N (-23分36秒)日出:05时52分(-38秒/日)日落:18时50分(+25秒/日)银 川106.27E 38.47N (-54分55秒)日出:05时58分(-1分9秒/日)日落:19时47分(+56秒/日)郑 州113.65E 34.76N (-25分23秒)日出:05时36分(-1分2秒/日)日落:19时10分(+48秒/日)珠 海113.52E 22.3N (-25分55秒)日出:05时54分(-38秒/日)日落:18时52分(+25秒/日)深 圳114.07E 22.62N (-23分43秒)日出:05时52分(-39秒/日)日落:18时50分(+26秒/日)。
日出日落时间的计算以及中国常见的日出日落时间以地球中心为原点O,赤道所在平面为XY平面,东经120度指向西经60度为Y轴正方向.球心指向北极为Z 轴正方向.有了Y轴与Z轴就可定X轴的方向(从东经30度指向西经150度)球面方程:X^2 + Y^2 + Z^2 = 1 (设地球直径为1)日出日落时刻圈方程:Y^2 + Z'^2 = 1 (Z'以Z轴作坐标变换,见下面)Z'=Z*sin(β+90) (β为太阳光直射点纬度)求纬度α度时日出时刻.先解出纬度为α度时的X,Y坐标.X=sinα*sin(β+90)*cos(β+90)/(cosβ*cosβ)Y=-SQRT(1-X^2-sinα*sinα) (SQRT为平方根)有了XY坐标,求反正切,得出一个角度值(由于在XY平面内,0度在X轴正向,实际的东经120度在Y轴负方向上,即270度角.所以要换算一下,才能得出经度差)实算一下:代入杭州的纬度为30.15度,夏至日时,太阳直射点纬度为23.4333度.算出X=-0.21835,Y=-0.83578,反正切得出-104.64度.计算时假设杭州在Y轴负方向上(即270度或-90度).两者之间相差14.64度,换成时间就是58.56分钟.(计算出的14.64度的含义是指,夏至日那天,当赤道上(北纬0度)东经120度的地方看到日出时,北纬30.15度,东经(120-14.64)度的地方也正好看到日出.)(换句话说:当赤道上东经120度的地方看到日出时,北纬30.15度东经120度的地方日出已经过去58.56分钟了.由于赤道上是昼夜等分的(假设太阳是个点光源),即日出时刻一定在6:00.那么同一经度的北纬30.15度地方,日出时间是5:01:26左右.杭州东经120度10分.比120度还早了40秒钟.所以日出时间为5:00:46)查寿星万年历,杭州在夏至日的日出时间为4:58:07,日落时间19:04:07.实测数据2009年5月1日星期五所有时间为北京时间 (任意地点日月升落时刻查询)省会城市北京116.46E 39.92N (-14分9秒)日出:05时15分(-1分15秒/日) 日落:19时09分(+1分0秒/日) 长春125.35E 43.88N (+21分23秒)日出:04时31分(-1分25秒/日) 日落:18时41分(+1分11秒/日) 长沙113E 28.21N(-28分0秒)日出:05时48分(-49秒/日)日落:19时03分(+35秒/日)成都104.06E 30.67N (-1时3分45秒) 日出:06时20分(-53秒/日)日落:19时42分(+39秒/日)重庆106.54E 29.59N (-53分50秒)日出:06时12分(-51秒/日)日落:19时31分(+38秒/日)福州119.3E 26.08N (-2分48秒)日出:05时26分(-46秒/日)日落:18时34分(+31秒/日)贵阳106.71E 26.57N (-53分9秒)日出:06时15分(-46秒/日)日落:19时26分(+32秒/日)广州113.23E 23.16N (-27分4秒)日出:05时54分(-40秒/日)日落:18时55分(+27秒/日)哈尔滨126.63E 45.75N (+26分31秒) 日出:04时21分(-1分30秒/日) 日落:18时40分(+1分17秒/日) 海口110.35E 20.02N (-38分36秒) 日出:06时09分(-35秒/日)日落:19时02分(+22秒/日)杭州120.19E 30.26N (+45秒)日出:05时17分(-53秒/日)日落:18时37分(+39秒/日)合肥117.27E 31.86N (-10分55秒) 日出:05时26分(-56秒/日)日落:18时51分(+42秒/日)呼和浩特111.65E 40.82N (-33分23秒)日出:05时33分(-1分16秒/日) 日落:19时30分(+1分2秒/日)济南117E 36.65N(-12分0秒)日出:05时19分(-1分7秒/日)日落:19时00分(+53秒/日)昆明102.73E 25.04N (-1时9分4秒) 日出:06时33分(-44秒/日)日落:19时39分(+29秒/日)拉萨91.11E 29.97N (-1时55分33秒) 日出:07时13分(-53秒/日)日落:20时33分(+38秒/日)兰州103.73E 36.03N (-1时5分4秒) 日出:06时13分(-1分4秒/日)日落:19时52分(+50秒/日)南昌115.89E 28.68N (-16分26秒)日出:05时36分(-50秒/日)日落:18时52分(+36秒/日)南京118.78E 32.04N(-4分52秒)日出:05时19分(-57秒/日)日落:18时45分(+43秒/日)南宁108.33E 22.84N (-46分40秒) 日出:06时14分(-39秒/日)日落:19时14分(+26秒/日)澳门113.33E 22.13N (-26分40秒) 日出:05时55分(-38秒/日)日落:18时53分(+25秒/日)上海121.48E 31.22N (+5分55秒)日出:05时10分(-55秒/日)日落:18时33分(+41秒/日)沈阳123.38E 41.8N (+13分31秒) 日出:04时43分(-1分20秒/日) 日落:18时44分(+1分5秒/日) 石家庄114.48E 38.03N (-22分4秒)日出:05时27分(-1分10秒/日) 日落:19时13分(+56秒/日)台北121.5E 25.05N (+6分0秒)日出:05时19分(-44秒/日)日落:18时24分(+29秒/日)太原112.53E 37.87N (-29分52秒)日出:05时35分(-1分9秒/日) 日落:19时20分(+55秒/日)天津117.2E 39.13N (-11分11秒)日出:05时14分(-1分13秒/日) 日落:19时04分(+58秒/日)武汉114.31E 30.52N (-22分45秒)日出:05时40分(-53秒/日)日落:19时01分(+40秒/日)乌鲁木齐87.68E 43.77N (-2时9分16秒) 日出:07时02分(-1分25秒/日) 日落:21时12分(+1分11秒/日) 西安108.95E 34.27N (-44分11秒)日出:05时55分(-1分0秒/日) 日落:19时28分(+47秒/日)西宁101.74E 36.56N (-1时13分2秒) 日出:06时20分(-1分6秒/日) 日落:20时01分(+51秒/日)香港114.1E 22.2N (-23分36秒) 日出:05时52分(-38秒/日)日落:18时50分(+25秒/日)银川106.27E 38.47N (-54分55秒) 日出:05时58分(-1分9秒/日) 日落:19时47分(+56秒/日)郑州113.65E 34.76N (-25分23秒) 日出:05时36分(-1分2秒/日) 日落:19时10分(+48秒/日)珠海113.52E 22.3N (-25分55秒) 日出:05时54分(-38秒/日)日落:18时52分(+25秒/日)深圳114.07E 22.62N (-23分43秒) 日出:05时52分(-39秒/日)日落:18时50分(+26秒/日)。
日出时刻=(24-昼长)/2 日出时刻=12-昼长/2
日落时刻=24-日出时刻日落时刻=12+昼长/2
日出日落的时刻计算:夏半年时,6点前日出,18点后日落;冬半年时,6点后日出,18点前日落。
春秋二分,6点日出,18点日落。
日出日落的时间问题是和昼夜长短相关的,日落时间-日出时间=昼长。
所以白昼越长的地方,日出越早日落越晚,白昼越短的地方,日出越晚日落越早。
扩展资料:
日出日落的方位:除极昼、极夜外,当太阳直射在北半球时,各地日出东北,日落西北。
当太阳直射点在南南半球是,各地日出东南,日落西南。
春秋二分,东升西落。
例如:当太阳直射南半球时,全球(极昼极夜区除外)日出东南、日落西南,北半球越往北日出日落方位越偏南,昼长越短,到极夜区就日出日落正南方向,时间是正午12点。
南半球越往南日出日落方位越偏南,白昼越长,到极昼区就日出日落正南方向,时间是子夜0点。
当太阳直射北半球时,全球(极昼极夜区除外)日出东北、日落西北,北半球越往北日出日落方位越偏北,昼长越长,到极昼区就日出日落正北方向,时间是子夜0点。
南半球越往南日出日落方位越偏北,白昼越短,到极夜区就日出日落正北方向,时间是正午12。
各主要季节间日出、日落时间大体换算方法根据农历二、八月昼夜平(这仅是粗略的说法。
实际上不同纬度,昼夜时间不完全均等)这一基本时间,可将我们这一带主要季节之间日出、日落的大体时间用各时期的换算公式予以粗略测定。
现以中国科学院南京紫金山天文台计算的济南地区的日出、日落时间为基础予以说明。
济南地区在“春分”时日出6:15,日落18:24,在此粗略各取6点钟。
1、“春分”──“夏至”期间日出、日落时间的大体测定y=6±n·1 '20 "(式中6为六点钟,n为这一期间的某一“日序”,y为某一日序时当日的日落、日出时间。
日落时间为“+”,日出时间为“-”。
0≤n≤92)。
例:①当n=0,即代表3月21日“春分”这一天。
式中y=6±0,表示这一天为太阳六点钟出,下午六点钟落下。
②当n=(最大值)92时,即到“夏至”这一天时,y=6±92×1 '20 "为6±122 '即6±2:02 '≈(8:02 ',3:58 '),即“夏至”日时,日出为早上4点钟,日落为晚上8点钟。
③试问4月14日几点钟日出、日落?根据上述公式n=24(24为“春分”后3月份内有10天加上4月份1~14日的14天两数之和),代入公式后,y=6±24×1 '20 "=6±32 ',即4月14日这一天日出为5点28 ',日落为下午6点32 '。
同理,可求得这一期间任意一天的日出、日落的时间。
2、“夏至”──“秋分”期间日出、日落时间的大体(实际情况是“夏至”时,济南4:53日出,19:34 '日落)测定y1=3:58 '+n·1 '20 ",y2=8:02 '-n·1 '20 "(0≤n≤94)当n=0时,即夏至日时,y1=3:58 '(日出),y2=8:02 '(日落),n=(最大值)94时,y1=3:58 '+2:05 '≈6,y2=8:02 '-2:05≈6,即至秋分时,日出、日落均在早、晚6点钟。
根据经纬度计算⽇出、⽇落、中天、天亮、天⿊和昼长时间Jean Meeus的《天⽂算法》(Astronomical Algorithms,2nd Edition)第⼆版中第7章第60页内有详细介绍计算儒略⽇的⽅法:设Y为给定年份,M为⽉份,D为该⽉⽇期(带⼩数,把时:分:秒折算成⽇的形式)。
运算符INT表⽰为取所给数的整数部分,也即⼩数点前的部分。
1.若M > 2,Y和M不变。
若 M =1或2,以Y–1代Y,以M+12代M。
换句话说,如果⽇期在1⽉或2⽉,则被看作是在前⼀年的13⽉或14⽉。
2.对格⾥⾼利历(即1582年10⽉15⽇以后),有A = INT(Y/100),B = 2 - A + INT(A/4).另外,对于儒略历(即1582年10⽉15⽇之前),取B=0。
3.所求的儒略⽇即为:计算的代码:import java.io.IOException;import java.util.Date;import java.util.HashMap;import java.util.Map;import java.util.Properties;public class DayTime {private static Properties propt;private static double RAD = 180.0 * 3600 / Math.PI;private static double midDayTime;private static double dawnTime;private static String codeStr = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";static {propt = new Properties();try {propt.load(DayTime.class.getClassLoader().getResourceAsStream("jwd.properties"));} catch (IOException e) {e.printStackTrace();}}@SuppressWarnings("deprecation")public static Map<DayTimeType, String> dailytime(String area) {Date date = new Date();return dailytime(area, date.getYear(), date.getMonth(), date.getDay(), 0, 0, 0,8.0);}public static Map<DayTimeType, String> dailytime(String area, int year, int month, int day, int hour, int min, int sec,double tz) {Map<DayTimeType, String> map = new HashMap<DayTimeType, String>();String jwd = decodeJWD(area);System.out.println(jwd);Double wd = (Double.parseDouble(jwd.substring(0, 2)) + Double.parseDouble(jwd.substring(2, 4)) / 60) / 180 * Math.PI;Double jd = -(Double.parseDouble(jwd.substring(4, 7)) + Double.parseDouble(jwd.substring(7)) / 60) / 180 * Math.PI;double richu = timeToDouble(year, month, day, hour, min, sec) - 2451544.5;for (int i = 0; i < 10; i++)richu = sunRiseTime(richu, jd, wd, tz / 24);// 逐步逼近法算10次// ⽇出map.put(DayTimeType.SUNRISE, doubleToStr(richu));// ⽇落map.put(DayTimeType.SUNSET, doubleToStr(midDayTime + midDayTime - richu));// 中天map.put(DayTimeType.MIDTIME, doubleToStr(midDayTime));// 天亮map.put(DayTimeType.DAWNTIME, doubleToStr(dawnTime));// 天⿊map.put(DayTimeType.NIGHTTIME, doubleToStr(midDayTime + midDayTime - dawnTime));// 昼长map.put(DayTimeType.DAYTIME, doubleToStr((midDayTime - dawnTime) * 2 - 0.5));return map;}// 加密public static String decodeJWD(String encode) {StringBuilder jwd = new StringBuilder();for (int i = 0; i < 4; i++)if (2 == i)jwd.append(String.format("%03d", codeStr.indexOf(encode.charAt(i)) + 73));elsejwd.append(String.format("%02d", codeStr.indexOf(encode.charAt(i))));return jwd.toString();}// 解密public static String encodeJWD(Integer decode) {StringBuilder jwd = new StringBuilder();int i = 230811316;int ge = i % 100;int shi = i % 100000 - ge;int bai = i % 10000000 - shi;int qian = i % 1000000000 - bai;shi = shi / 100 - 73;qian = qian / 10000000;jwd.append(codeStr.charAt(qian)).append(codeStr.charAt(bai)).append(codeStr.charAt(shi)).append(codeStr.charAt(ge));return jwd.toString();}/**** @param date* 儒略⽇平午* @param lo* 地理经度* @param la* 地理纬度* @param tz* 时区* @return太阳升起时间*/public static Double sunRiseTime(double date, double lo, double la, double tz) {date = date - tz;// 太阳黄经以及它的正余弦值double t = date / 36525;double j = sunHJ(t);// 太阳黄经以及它的正余弦值double sinJ = Math.sin(j);double cosJ = Math.cos(j);// 其中2*PI*(0.7790572732640 + 1.00273781191135448*jd)恒星时(⼦午圈位置)double gst = 2 * Math.PI * (0.779057273264 + 1.00273781191135 * date) + (0.014506 + 4612.15739966 * t + 1.39667721 * t * t) / RAD;double E = (84381.406 - 46.836769 * t) / RAD; // 黄⾚交⾓double a = Math.atan2(sinJ * Math.cos(E), cosJ);// '太阳⾚经double D = Math.asin(Math.sin(E) * sinJ); // 太阳⾚纬double cosH0 = (Math.sin(-50 * 60 / RAD) - Math.sin(la) * Math.sin(D)) / (Math.cos(la) * Math.cos(D)); // ⽇出的时⾓计算,地平线下50分double cosH1 = (Math.sin(-6 * 3600 / RAD) - Math.sin(la) * Math.sin(D)) / (Math.cos(la) * Math.cos(D)); // 天亮的时⾓计算,地平线下6度,若为航海请改为地平线下12度// 严格应当区分极昼极夜,本程序不算if (cosH0 >= 1 || cosH0 <= -1)return -0.5;// 极昼double H0 = -Math.acos(cosH0); // 升点时⾓(⽇出)若去掉负号就是降点时⾓,也可以利⽤中天和升点计算double H1 = -Math.acos(cosH1);double H = gst - lo - a; // 太阳时⾓midDayTime = date - degree(H) / Math.PI / 2 + tz; // 中天时间dawnTime = date - degree(H - H1) / Math.PI / 2 + tz;// 天亮时间return date - degree(H - H0) / Math.PI / 2 + tz; // ⽇出时间,函数返回值}/*** 保证⾓度∈(-π,π)** @param ag* @return ag*/public static Double degree(double ag) {ag = mod(ag, 2 * Math.PI);return ag <= -Math.PI ? ag + 2 * Math.PI : ag > Math.PI ? ag - 2 * Math.PI : ag;}public static Double mod(double num1, double num2) {num2 = Math.abs(num2);// 只是取决于Num1的符号return num1 >= 0 ? num1 - ((int) (num1 / num2)) * num2 : ((int) (Math.abs(num1) / num2)) * num2 - Math.abs(num1);}/*** @param t* 儒略世纪数* @return太阳黄经*/public static Double sunHJ(double t) {t = t + (32.0 * (t + 1.8) * (t + 1.8) - 20) / 86400.0 / 36525.0;// 儒略世纪年数,⼒学时double j = 48950621.66 + 6283319653.318 * t + 53 * t * t - 994 + 334166 * Math.cos(4.669257 + 628.307585 * t) + 3489 * Math.cos(4.6261 + 1256.61517 * t) + 2060.6 * Math.cos(2.67823 + 628.307585 * t) * t;return j / 10000000;}/*** 儒略⽇的计算** @param y* 年* @param M* ⽉* @param d* ⽇* @param h* ⼩时* @param m* 分* @param s* 秒* @return int*/public static int timeToDouble(int y, int M, int d, int h, int m, int s) {double time = 0;if (M <= 2) {M += 12;y -= 1;}if (y * 372 + M * 31 + d >= 588829) {time = (int) (y / 100);time = 2 - time + (int) (time / 4);}time += (int) Math.round(365.25 * (y + 4716) + 0.01) + (int) (30.60001 * (M + 1)) + d + (h * 3600 + m * 60 + s) / (24 * 3600) - 1524.5;return (int) Math.round(time);}public static String doubleToStr(double time) {double t = time + 0.5;t = (t - (int) t) * 24;t = (t - h) * 60;int m = (int) t;t = (t - m) * 60;int s = (int) t;return h + ":" + m + ":" + s;}public static void main(String[] args) {// System.out.println(decodeJWD("N3dS肇庆"));// String jwd = decodeJWD("N3dS肇庆");// Double wd = (Double.parseDouble(jwd.substring(0, 2)) +// Double.parseDouble(jwd.substring(2, 4)) / 60) / 180 * Math.PI;// Double jd = -(Double.parseDouble(jwd.substring(4, 7)) +// Double.parseDouble(jwd.substring(7)) / 60) / 180 * Math.PI;// double richu = timeToDouble(2012, 6, 25, 0, 0, 0) - 2451544.5;// System.out.println(richu + " " + timeToDouble(2012, 6, 25, 0, 0, 0));// richu = sunRiseTime(richu, jd, wd, 8.0 / 24);// System.out.println(richu);// richu = sunRiseTime(richu, jd, wd, 8.0 / 24);// 逐步逼近法算两次// System.out.println(doubleToStr(richu));String t = "03";System.out.println(Integer.parseInt(t));System.out.println(propt.getProperty("HI"));String[] strs = propt.getProperty("HI").split(" ");for (int i = 1; i < strs.length; i++) {System.out.println(strs[i] + " ⽇出 " + dailytime(strs[i]).get(DayTimeType.SUNRISE)); System.out.println(strs[i] + " ⽇落" + dailytime(strs[i]).get(DayTimeType.SUNSET));System.out.println(strs[i] + " 中天" + dailytime(strs[i]).get(DayTimeType.MIDTIME)); System.out.println(strs[i] + " 天亮" + dailytime(strs[i]).get(DayTimeType.DAWNTIME)); System.out.println(strs[i] + " 天⿊" + dailytime(strs[i]).get(DayTimeType.NIGHTTIME)); System.out.println(strs[i] + " 昼长" + dailytime(strs[i]).get(DayTimeType.DAYTIME)); }System.out.println(encodeJWD(230811316));}}枚举类型:public enum DayTimeType {SUNRISE, SUNSET, MIDTIME, DAWNTIME, NIGHTTIME, DAYTIME}中国各个地区经纬度数据:。
c++日出日落计算公式详细C++是一种高级编程语言,常用于开发各种类型的应用程序。
C++提供了丰富的库和函数,使得编写复杂的计算公式变得更加简单和高效。
在计算日出日落时间方面,可以利用一些基本的天文学公式来进行计算。
日出和日落的计算是基于地球的自转和公转运动的。
地球绕太阳公转的轨道是一个椭圆轨道,而地球自转的轴倾斜23.5度。
这些因素都会影响日出和日落时间的计算。
以下是一个基本的日出日落计算公式的例子:```cpp#include <iostream>#include <cmath>int main() {int year = 2022; // 设置年份int month = 1; // 设置月份int day = 1; // 设置日期// 计算一年中的第几天int N = 275 * month / 9 - ((month + 9) / 12) * (1 + (year - 4 * (year / 4 + 1)) / 3) + day - 30;// 计算地球与太阳之间的平均太阳时角double M = 0.9856 * N - 3.289;// 计算太阳的真太阳时角double L = fmod(M + 1.916 * sin(M_PI * M / 180) + 0.020 * sin(2 * M_PI * M / 180) + 282.634, 360);// 计算太阳的赤纬角double declination = 23.45 * sin(M_PI * (N + 284) / 365);// 计算地球的时差double eqTime = 4 * ((L - 0.06571 * N - 19.44) / 60);// 计算日出时间double sunrise = 12 - (eqTime + 4 * atan(tan(M_PI * declination / 180)) / 15);// 计算日落时间double sunset = 12 - (eqTime - 4 * atan(tan(M_PI * declination / 180)) / 15);std::cout << "日出时间:" << sunrise << "小时" << std::endl; std::cout << "日落时间:" << sunset << "小时" << std::endl;return 0;}```上述代码给出了一个简单的日出日落时间计算的例子。
个人收集整理-ZQ
1 / 1 首先,我们根据当前地日期确定太阳在黄道中地位置.我们知道,太阳大约在月日或月日直射赤道,而其运动周期是天.
所以现在太阳在黄道中地位置是
[注]
黄道平面与赤道平面地夹角被称为黄赤夹角,大约为度.根据立体几何地知识,太阳当前直射地纬度满足
根据这个式子,就可以用计算器地反三角函数求得.
接下来,需要计算地是目前你所在纬度地昼长.由于黄道、赤道和你所在地纬圈均不同在一个平面,所以在纬圈上,太阳照射地部分并不等于纬圈地一半.这里令θ为其超出地角度,则有下式其中为你当前地纬度.解出θ后,可以求得昼长等于
等等,这里我们忽略了两点:. 阳光在大气中地折射会使得我们能见到地平线下方约′射来地光线.. 太阳不是点光源,它是一个约′圆盘.考虑这两点,θ还有一个修正量[注]在这个基础上,重新计算昼长.到这里,最难地问题已经解决了,还需要把当地时间,根据经度换算到北京时间.
也就是当地正午(太阳最高时)地北京时间为
那么日出时间和日落时间
由于忽略了地球公转地椭圆轨道(近似为圆),忽略了地球表面地起伏(近似为球)等因素,以上地计算过程和实际值具有一定误差.注:为了方便,也可以夏至(或秋分,冬至)作为起算点.不过需要对应地加上. 注:这是一个近似地做法,其依据是太阳日出地过程并不长,可以把弧段近似看作线段.但这一点只能在中低纬度地区得到保证.对精确解法有兴趣地同学,可以试着动手算一算.。