25 #include "sunriseset.h"
28 static double PI = 3.14159265358979323846;
30 static double MaxLat = 89.99;
31 static double MaxLong = 179.99;
33 using namespace KHolidays;
34 using namespace SunRiseSet;
36 static double degToRad(
double degree )
38 return ( degree * PI ) / 180.00;
41 static double radToDeg(
double rad )
43 return ( rad * 180.0 ) / PI;
47 static double calcTimeJulianCent(
int jday )
49 return (
double( jday ) - 2451545.0 ) / 36525.0;
53 static double calcMeanObliquityOfEcliptic(
double t )
55 double seconds = 21.448 - t * ( 46.8150 + t * ( 0.00059 - t * 0.001813 ) );
56 double e0 = 23.0 + ( 26.0 + ( seconds / 60.0 ) ) / 60.0;
61 static double calcObliquityCorrection(
double t )
63 double e0 = calcMeanObliquityOfEcliptic( t );
64 double omega = 125.04 - 1934.136 * t;
65 double e = e0 + 0.00256 * cos( degToRad( omega ) );
70 static double calcGeomMeanLongSun(
double t )
72 double L0 = 280.46646 + t * ( 36000.76983 + 0.0003032 * t );
73 while ( L0 > 360.0 ) {
83 static double calcGeomMeanAnomalySun(
double t )
85 double M = 357.52911 + t * ( 35999.05029 - 0.0001537 * t );
90 static double calcSunEqOfCenter(
double t )
92 double m = calcGeomMeanAnomalySun( t );
93 double mrad = degToRad( m );
94 double sinm = sin( mrad );
95 double sin2m = sin( mrad + mrad );
96 double sin3m = sin( mrad + mrad + mrad );
97 double C = sinm * ( 1.914602 - t * ( 0.004817 + 0.000014 * t ) ) +
98 sin2m * ( 0.019993 - 0.000101 * t ) + sin3m * 0.000289;
103 static double calcSunTrueLong(
double t )
105 double l0 = calcGeomMeanLongSun( t );
106 double c = calcSunEqOfCenter( t );
112 static double calcSunApparentLong(
double t )
114 double o = calcSunTrueLong( t );
115 double omega = 125.04 - 1934.136 * t;
116 double lambda = o - 0.00569 - 0.00478 * sin( degToRad( omega ) );
121 static double calcSunDeclination(
double t )
123 double e = calcObliquityCorrection( t );
124 double lambda = calcSunApparentLong( t );
126 double sint = sin( degToRad( e ) ) * sin( degToRad( lambda ) );
127 double theta = radToDeg( asin( sint ) );
132 static double calcEccentricityEarthOrbit(
double t )
134 double e = 0.016708634 - t * ( 0.000042037 + 0.0000001267 * t );
140 static double calcEquationOfTime(
double t )
142 double epsilon = calcObliquityCorrection( t );
143 double l0 = calcGeomMeanLongSun( t );
144 double e = calcEccentricityEarthOrbit( t );
145 double m = calcGeomMeanAnomalySun( t );
147 double y = tan( degToRad( epsilon ) / 2.0 );
150 double sin2l0 = sin( 2.0 * degToRad( l0 ) );
151 double sinm = sin( degToRad( m ) );
152 double cos2l0 = cos( 2.0 * degToRad( l0 ) );
153 double sin4l0 = sin( 4.0 * degToRad( l0 ) );
154 double sin2m = sin( 2.0 * degToRad( m ) );
156 double Etime = y * sin2l0 - 2.0 * e * sinm + 4.0 * e *
157 y * sinm * cos2l0 - 0.5 *
158 y * y * sin4l0 - 1.25 * e * e * sin2m;
159 return radToDeg( Etime ) * 4.0;
163 static double calcHourAngleSunrise(
double latitude,
double solarDec )
165 double latRad = degToRad( latitude );
166 double sdRad = degToRad( solarDec );
167 double HAarg = ( cos( degToRad( 90.833 ) ) /
168 ( cos( latRad ) * cos( sdRad ) ) - tan( latRad ) * tan( sdRad ) );
169 double HA = acos( HAarg );
175 latitude = qMax( qMin( MaxLat, latitude ), -MaxLat );
176 longitude = qMax( qMin( MaxLong, longitude ), -MaxLong );
178 double t = calcTimeJulianCent( date.
toJulianDay() );
179 double eqTime = calcEquationOfTime( t );
180 double solarDec = calcSunDeclination( t );
181 double hourAngle = calcHourAngleSunrise( latitude, solarDec );
182 double delta = longitude + radToDeg( hourAngle );
184 timeUTC = timeUTC.
addSecs( ( 720 - ( 4.0 * delta ) - eqTime ) * 60 );
192 latitude = qMax( qMin( MaxLat, latitude ), -MaxLat );
193 longitude = qMax( qMin( MaxLong, longitude ), -MaxLong );
195 double t = calcTimeJulianCent( date.
toJulianDay() );
196 double eqTime = calcEquationOfTime( t );
197 double solarDec = calcSunDeclination( t );
198 double hourAngle = -calcHourAngleSunrise( latitude, solarDec );
199 double delta = longitude + radToDeg( hourAngle );
201 timeUTC = timeUTC.
addSecs( ( 720 - ( 4.0 * delta ) - eqTime ) * 60 );
QTime addSecs(int s) const
KHOLIDAYS_EXPORT QTime utcSunrise(const QDate &date, double latitude, double longitude)
Compute the sunrise time (UTC) for a date and Earth location.
KHOLIDAYS_EXPORT QTime utcSunset(const QDate &date, double latitude, double longitude)
Compute the sunset time (UTC) for a date and Earth location.