/************************************************************************/
/* 计算太阳某个地方某个时刻太阳位置的程序
*/
/* 2008 年 9 月 3 日
/* 安志军
*/
/************************************************************************/
//输入当地时间,当地经纬度(转化为弧度),输出太阳高度(弧度),方向(弧度)
void SunPosition(int year,int month,int day,int hour,int minute,int second,float localLat,float locatLon,float& height,float&
direction)
{
*/
float theta,t,N=0.0f,NO;//N 为积日 theta 为赤纬角
int monthDay[12]={31,28,31,30,31,30,31,31,30,31,30,31};
for (int count=0;count=3) )
N++;
NO=79.6764+0.2422*(year-1985)-int((year-1985)/4);
t=N-NO;
theta=2*3.1415926*t/365.2422;
float 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.1415926f/180.0f;
float Et;//时差
Et=0.0028-1.9857*sin(theta)+9.9059*sin(2*theta)-7.0924*cos(theta)-0.6882*cos(2*theta);
float timeAngle;//时角
timeAngle=(float(hour-12)+float(minute-(120.0f*3.14159f/180.0f-locatLon)*4*180/3.1415926+Et)/60+float(second)/36
00)*15.0f*3.1415926/180.0f;
height=sin(localLat)*sin(lat)+cos(localLat)*cos(lat)*cos(timeAngle);
height=asin(height);
direction=(sin(height)*sin(localLat)-sin(lat))/(cos(height)*cos(localLat));
direction=acos(direction);
if (timeAngle<0)
direction*=-1.0f;
}
void CpositionShowDlg::OnTimer(UINT nIDEvent)
{
// TODO: Add your message handler code here and/or call default
int year,month,day,hour,minute,second;
float height,direction;
SYSTEMTIME time;
GetLocalTime(&time);
year=time.wYear;
month=time.wMonth;
day=time.wDay;
hour=time.wHour;
minute=time.wMinute;
second=time.wSecond;
SunPosition(year,month,day,hour,minute,second,39.9f*3.14159/180,116.3833*3.14159/180,height,direction);
//将高度和经度转化为度分秒的结构
height=height*180/3.1415926f;
direction=direction*180/3.1415926f;
m_HeightDegree=int(height);
m_HeightMinute=int((height-int(height))*60);
m_DirectionDegree=int(direction);
m_DirectionMinute=int((direction-int(direction))*60);
UpdateData(false);
CDialog::OnTimer(nIDEvent);
}
void CpositionShowDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
CMenu menu,*pSubmenu;
menu.LoadMenu(IDR_MENU1);
pSubmenu = menu.GetSubMenu(0);
pSubmenu = menu.GetSubMenu(0);
SetForegroundWindow();
pSubmenu->TrackPopupMenu(TPM_LEFTALIGN,point.x,point.y,this,0);
CDialog::OnRButtonDown(nFlags, point);
}