Question by
OpenMindStudios · Nov 25, 2017 at 12:39 AM ·
c#sun
Trying to get the sun in the right place
I'm working on a time cycle script, and I want to add in seasons, so I figure that if I can use the same calculations to know the suns position then I should be able to have the light appear as if it's coming from where the sun should be.
https://astronomy.stackexchange.com/questions/1855/how-to-get-the-longitude-latitude-from-solar-zenith-azimuth is the source of my mathmatics, and I have done some extra research just to confirm, but this looked like the best set of examples so I converted in to code with my little skill in calculus this is what I got:
private void CalculateSunLocation () {
localStandardTimeMeridian = 15 * localTimeZone;
calculationB = (360f / 365f) * (currentDay - 81);
equationOfTime = (9.87f * Mathf.Sin (2 * calculationB)) - (7.53f * Mathf.Cos (calculationB)) - (1.5f * Mathf.Sin (calculationB));
timeCorrectionFactor = 4 * (locationsLongitude - localStandardTimeMeridian) + equationOfTime;
localSolarTime = clockTime + (timeCorrectionFactor / 60);
hourAngle = 15 * (localSolarTime - 12);
declinationAngle = 23.45f * Mathf.Sin (calculationB);
elevationAngle = Mathf.Asin ((Mathf.Sin (declinationAngle) * Mathf.Sin (locationsLatitude)) + (Mathf.Cos (declinationAngle) * Mathf.Cos (locationsLatitude) * Mathf.Cos (hourAngle)));
azimuthAngle = Mathf.Acos (((Mathf.Sin (declinationAngle) * Mathf.Sin (locationsLatitude))+(Mathf.Cos (declinationAngle) * Mathf.Cos (locationsLatitude) * Mathf.Cos (hourAngle)))/360);
SetSunPosition ();
}
private void SetSunPosition () {
sol.transform.eulerAngles = new Vector3 ((elevationAngle*(180/Mathf.PI)), (azimuthAngle*(180/Mathf.PI)), sol.transform.rotation.z);
}
but I am way off, I just cant figure out why. Anyone able to help?
Comment
Your answer