ceeK / Solar

A Swift micro library for generating Sunrise and Sunset times.
MIT License
568 stars 82 forks source link

Is it possible to get the times for a given sun position on a given date ? #30

Open MBenoli opened 7 years ago

MBenoli commented 7 years ago

Dear Chris,

Here is an example of what I mean: Knowing the latitude, longitude of a location (Let's say: 40.730610, -73.935242 for New York) and knowing the sun angle (for example for the sunset the sun angle is defined as making an angle of -0.833 below the horizon) can I get the time of the sunset for a given date (for example: 6:22 AM on the 12th of July) ?

Of course, here I gave an example for the sunset but I want to get times for different sun angles.

So the call to the function would be like: getTimeForGivenSunAngle(date,lat,long,sunAngle) that will return something like: "In New York, on the 12th of July the Sun will make an angle of -0.833 degrees at 6:22 AM"

Best regards,

Michael

maurymarkowitz commented 6 years ago

I realize this is out of the blue, but I wrote such a function in Swift a while back. See https://stackoverflow.com/questions/41656453/suns-position-in-swift. ceeK, if you see this, feel free to add this code to your library, that will save me having to reinvent the wheel.

isVoid commented 5 years ago

+1 request for this function.

Surely one can enumerate every single second from this point on for a fixed time range and store them in a linear list. However for a function which requires frequent calls, the memory and computing overhead is unnecessarily large. Is it possible to have a closed form solution/approximation to the sun positions?