[c++] 计算太阳高度角

/*
输入参数:                            
Longitude - 经度(单位"度")
Latitude  - 纬度(单位"度")
Year      - 年
Month     - 月
Day       - 日
Hour      - 时
Minute    - 分
Second    - 秒

输出参数:
Height    - 太阳高度角   (单位"弧度")
Direction - 太阳方位角   (单位"弧度")
*/
void SunPositionNR(double Longitude, double Latitude, int year, int month, int day, int hour, int minute, int second, double& height, double& direction)
{
	double A = year/4;   
	double B = A-floor(A);   
	double C = 32.8;   
	if(month <= 2)   
		C = 30.6;   
	if(B==0 && month>2)   
		C = 31.8;   
	double G = floor(30.6*month-C+0.5)+day;   
	double L = Longitude/15.0;                    //经度修正    
	double H = hour-8 + minute/60.0;              //时刻修正    
	double N = G+(H-L)/24.0;                      //计算积日 
	double theta, NO;     //theta为日角
	NO = 79.6764 + 0.2422*(year-1985) - floor((year-1985)/4.0);
	theta = 2*PI*(N-NO)/365.2422;

	double lat;//赤纬角
	lat = 0.3723+23.2567*sin(theta)+0.1149*sin(2*theta)-0.1712*sin(3*theta)-0.758*cos(theta)+0.3656*cos(2*theta)+0.0201*cos(3*theta);
	lat = lat*3.14159265358979/180.0;

	double Et;//时差(以分钟为单位)
	Et = 0.0028-1.9857*sin(theta)+9.9059*sin(2*theta)-7.0924*cos(theta)-0.6882*cos(2*theta);

	double timeAngle;//时角
	timeAngle = ( (hour-12) + (minute - (120.0-Longitude) * 4.0 + Et)/60.0 ) * 15.0;
	timeAngle = timeAngle * 3.14159265358979 / 180.0;

	// 将纬度由角度转换为弧度
	Latitude = Latitude * 3.14159265358979 / 180.0;

	// 太阳高度角
	height = sin(Latitude)*sin(lat)+cos(Latitude)*cos(lat)*cos(timeAngle);
	height = asin(height);

	// 太阳方位角
	direction = (sin(height)*sin(Latitude)-sin(lat))/(cos(height)*cos(Latitude));
	direction = acos(direction);

	if (timeAngle<0)  //(以正南方向为0度,顺时针为正)
		direction *= -1.0;
}

以武汉某一天为例:

[c++] 计算太阳高度角

将日出时间代入得到:height = -0.015, 算是非常准确的了。

 

原文链接: https://www.cnblogs.com/P3nguin/p/8288511.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    [c++] 计算太阳高度角

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/267756

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月14日 下午6:47
下一篇 2023年2月14日 下午6:50

相关推荐