- #1
AWoods
- 7
- 0
Hi there, I hope this is the right place for this question and furthermore doesn't appear rude that my first post is a question! If so, I do apologise, I haven't been able to find an appropriate place to ask this.
I'm working on calculating the position of the sun at a given day of the year for a given location. I have all the calculations laid out correctly I believe, but my elevation and azimuth are coming back incorrect.
I think this is due to me not using radians/degrees correctly, but honestly, I've dived right into the deep end given that I haven't studied maths and physics in maybe 5 years.
Just to clarify given the guidelines I just read, this isn't homework, it's a personal project I'm working on for simulating a dynamic time of day system for games, if that still classifies, sorry and feel free to remove my thread.
Any help you could give, or even just a nudge in the right direction would be fantastic, I'll post my current calculations below:
These are taken directly from my code, I'll try to simplify it where possible in the hopes that it's simple enough to read. I can provide further clarification if needed.
Given inputs are: current time decimalTimeHourMin(format: hour.minute), date, GMTOffset (in hours), latitude and longitude.
Acos and Asin signify Arccos and Arcsine inverse functions.
localStandardTimeMeridian = 15 * GMTOffset;
fractionalYear = (360 / 365) * ( (date.DayOfYear - 1) - 81);
*** This is where is starts to get harder to read admittedly, the Deg2Rad bits equate to (PI * 2) / 360 ***
equationOfTime = (9.87f * Sin( (2 * fractionalYear) * Deg2Rad) ) - (7.53f * Cos(fractionalYear * Deg2Rad) ) - (1.5f * Sin(fractionalYear * Deg2Rad) );
timeCorrection = 4*(longitude - localStandardTimeMeridian) + equationOfTime;
localSolarTime = decimalTimeHourMin + (timeCorrection / 60);
hourAngle = 15 * (localSolarTime - 12);
declination = 23.45f * Sin(fractionalYear * Deg2Rad);
*** These are the 2 calculations that do not work out, all other calculations above are correct to an acceptable degree of accuracy ***
elevation = Asin( (Sin(declination) * Sin(lattitude) ) + (Cos(declination) * Cos(lattitude) * Cos(hourAngle) ) );
azimuth = Acos( (Sin(declination) * Sin(lattitude) ) - (Cos(declination) * Cos(lattitude) * Cos(hourAngle) ) / Cos(elevation) );
I'm fairly positive that I need to handle some of these factors as radians, though I cannot work out where.
Have I done something terribly wrong?
I also have an Excel Spreadsheet with appropriate formulas in, which does the same thing, I can post a link to that if it would be helpful.
Thanks for reading
I'm working on calculating the position of the sun at a given day of the year for a given location. I have all the calculations laid out correctly I believe, but my elevation and azimuth are coming back incorrect.
I think this is due to me not using radians/degrees correctly, but honestly, I've dived right into the deep end given that I haven't studied maths and physics in maybe 5 years.
Just to clarify given the guidelines I just read, this isn't homework, it's a personal project I'm working on for simulating a dynamic time of day system for games, if that still classifies, sorry and feel free to remove my thread.
Any help you could give, or even just a nudge in the right direction would be fantastic, I'll post my current calculations below:
These are taken directly from my code, I'll try to simplify it where possible in the hopes that it's simple enough to read. I can provide further clarification if needed.
Given inputs are: current time decimalTimeHourMin(format: hour.minute), date, GMTOffset (in hours), latitude and longitude.
Acos and Asin signify Arccos and Arcsine inverse functions.
localStandardTimeMeridian = 15 * GMTOffset;
fractionalYear = (360 / 365) * ( (date.DayOfYear - 1) - 81);
*** This is where is starts to get harder to read admittedly, the Deg2Rad bits equate to (PI * 2) / 360 ***
equationOfTime = (9.87f * Sin( (2 * fractionalYear) * Deg2Rad) ) - (7.53f * Cos(fractionalYear * Deg2Rad) ) - (1.5f * Sin(fractionalYear * Deg2Rad) );
timeCorrection = 4*(longitude - localStandardTimeMeridian) + equationOfTime;
localSolarTime = decimalTimeHourMin + (timeCorrection / 60);
hourAngle = 15 * (localSolarTime - 12);
declination = 23.45f * Sin(fractionalYear * Deg2Rad);
*** These are the 2 calculations that do not work out, all other calculations above are correct to an acceptable degree of accuracy ***
elevation = Asin( (Sin(declination) * Sin(lattitude) ) + (Cos(declination) * Cos(lattitude) * Cos(hourAngle) ) );
azimuth = Acos( (Sin(declination) * Sin(lattitude) ) - (Cos(declination) * Cos(lattitude) * Cos(hourAngle) ) / Cos(elevation) );
I'm fairly positive that I need to handle some of these factors as radians, though I cannot work out where.
Have I done something terribly wrong?
I also have an Excel Spreadsheet with appropriate formulas in, which does the same thing, I can post a link to that if it would be helpful.
Thanks for reading