Simple sunset/sunrise algorithm
This commit is contained in:
35
include/sun.h
Normal file
35
include/sun.h
Normal file
@ -0,0 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/time.h>
|
||||
#include <time.h>
|
||||
|
||||
// See http://edwilliams.org/sunrise_sunset_algorithm.htm
|
||||
#define ZENITH_OFFICIAL 90.83
|
||||
#define ZENITH_CIVIL 96.0
|
||||
#define ZENITH_NAUTICAL 102.0
|
||||
#define ZENITH_ASTRONOMICAL 108.0
|
||||
|
||||
/* Given the latlong, returns the seconds in the day, in UTC, that the sun rises
|
||||
* on a given year-month-day, or 0 if it never rises.
|
||||
*/
|
||||
uint32_t calcSunRise(int year, int month, int day, float latitude, float longitude);
|
||||
|
||||
/* Given the latlong, returns the seconds in the day, in UTC, that the sun sets
|
||||
* on a given year-month-day, or 0 if it never sets.
|
||||
*/
|
||||
uint32_t calcSunSet(int year, int month, int day, float latitude, float longitude);
|
||||
|
||||
/* Given a month and hemisphere, a sunrise and sunset (output from
|
||||
* calcSun{Rise,Set}()), returns the amount of seconds of the day where
|
||||
* daylight is observed.
|
||||
*
|
||||
* Is reasonably aware of polar regions (ie permanent day/night). Exception is the
|
||||
* first full day/night, which are truncated to 86400 respectively 0 seconds. This is
|
||||
* only a concern for any latitude > 66.6 or latitude < -66.6.
|
||||
*/
|
||||
uint32_t calcDaylight(int month, float latitude, uint32_t rise, uint32_t set);
|
Reference in New Issue
Block a user