Skip to main content
GameDev.net gamedev.net
🔒 Locked

Computing correct sun position

Started by deks Apr 29, 2004 at 8:18 AM 1 replies 550+ views
Original Post
deks
deks
Hi, I just implemented what''s in "A Practical Analytic Model for Daylight", and now I''m trying to compute the sun''s position as described in appendix 6 (page 26), but it don''t works. I''m using the following coordinates (Montreal CANADA, april 29 12:00pm): Standard time: 12.0f Julian day: 119.0f Latitude: 45.5f Longitude: 73.58333f Meridian: 75.0f All I get is a beautiful sunset instead of a sun at zenith. I revised over and over the formulas, and everything is correct according to the paper.Also, latitude, longitude and meridian are in degres for clarity, but I do the correct conversion in radians. Any ideas? Jean-Francois Dube
deks
deks
Here''s my code, if anyone wants to check.


void kfSun::Update(tFloat fTimeOfDay, tFloat fJulianDay, tFloat fLatitude, tFloat fLongitude, tFloat fStdMeridian)
{
tFloat fSolarTime = fTimeOfDay + (0.170f * sin(4.0f * dPi * (fJulianDay - 80.0f) / 373.0f) - 0.129f * sin(2.0f * dPi * (fJulianDay - 8.0f) / 355.0f)) + (12.0f * (fStdMeridian - fLongitude)) / dPi;
tFloat fSolarDeclination = (0.4093f * sin(2.0f * dPi * (fJulianDay - 81.0f) / 368.0f));
tFloat fSolarAltitude = asin(sin(kDegToRad(fLatitude)) * sin(fSolarDeclination) - cos(kDegToRad(fLatitude)) * cos(fSolarDeclination) * cos(dPi * fSolarTime / 12.0f));

tFloat fOpp = -cos(fSolarDeclination) * sin(dPi * fSolarTime / 12.0f);
tFloat fAdj = -(cos(kDegToRad(fLatitude)) * sin(fSolarDeclination) + sin(kDegToRad(fLatitude)) * cos(fSolarDeclination) * cos(dPi * fSolarTime / 12.0f));

m_fPhi = atan2(fOpp, fAdj);
m_fTheta = dPi / 2.0f - fSolarAltitude;
}


JF

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.