Calculation of sunrise and sunset

From WickyWiki
Revision as of 18:13, 4 March 2019 by Wilbert (talk | contribs)


Source:

A script to change settings with MotionEyeOS for day and night settings:

Input example:

  • Date --> vDayOfYear
  • Date --> vLeapyear

Fractional year (radians)

 vY = 2 * PI() / (365 + vLeapYear) * (vDayOfYear - 1 )

Equation of time (minutes)

 vEqtime = 229.18 * (0.000075 + 0.001868 * COS( vY ) - 0.032077 * SIN( vY ) - 0.014615 * COS(2 *  vY ) - 0.040849 * SIN(2 *  vY )

Solar declination angle (radians).

 vDecl = 0.006918 - 0.399912 * COS(vY) + 0.070257 * SIN(vY) - 0.006758 * COS(2 * vY) + 0.000907 * SIN(2 * vY) - 0.002697 * COS(3 * vY) + 0.00148 * SIN (3 * vY)

For sunrise or sunset, the zenith is set to 90.833 degrees (the approximate correction for atmospheric refraction at sunrise and sunset, and the size of the solar disk). Hours angle (radians):

 vHa = ACOS( COS( TO_RADIANS(90.833) ) / COS(vLat) * COS(vDecl) - TAN(vLat) * TAN(vDecl) )

Sunrise UTC minutes

 vUtcMinsSunrise = 360 * 2 - 4 * (vLon + TO_DEGREES(vHa) ) - vEqtime

Noon UTC minutes

 vUtcMinsNoon = 360 * 2 - 4 * vLon - vEqtime

Sunset UTC minutes

 vUtcMinsSunset = 360 * 2 - 4 * (vLon - TO_DEGREES(vHa) ) - vEqtime

Sunset local time in fractional day. For Europe/Amsterdam --> vTimezone=+1 or +2 (DST)

 (vUtcMinsSunset / 60 + vTimezone) / 24