@@ -65,7 +65,7 @@ public String getCalculatorName() {
65
65
public double getUTCSunrise (Calendar calendar , GeoLocation geoLocation , double zenith , boolean adjustForElevation ) {
66
66
double elevation = adjustForElevation ? geoLocation .getElevation () : 0 ;
67
67
double adjustedZenith = adjustZenith (zenith , elevation );
68
- double sunrise = getSunRiseSetUTC (getJulianDay ( calendar ) , geoLocation .getLatitude (), -geoLocation .getLongitude (),
68
+ double sunrise = getSunRiseSetUTC (calendar , geoLocation .getLatitude (), -geoLocation .getLongitude (),
69
69
adjustedZenith , SolarEvent .SUNRISE );
70
70
sunrise = sunrise / 60 ;
71
71
return sunrise > 0 ? sunrise % 24 : sunrise % 24 + 24 ; // ensure that the time is >= 0 and < 24
@@ -77,7 +77,7 @@ public double getUTCSunrise(Calendar calendar, GeoLocation geoLocation, double z
77
77
public double getUTCSunset (Calendar calendar , GeoLocation geoLocation , double zenith , boolean adjustForElevation ) {
78
78
double elevation = adjustForElevation ? geoLocation .getElevation () : 0 ;
79
79
double adjustedZenith = adjustZenith (zenith , elevation );
80
- double sunset = getSunRiseSetUTC (getJulianDay ( calendar ) , geoLocation .getLatitude (), -geoLocation .getLongitude (),
80
+ double sunset = getSunRiseSetUTC (calendar , geoLocation .getLatitude (), -geoLocation .getLongitude (),
81
81
adjustedZenith , SolarEvent .SUNSET );
82
82
sunset = sunset / 60 ;
83
83
return sunset > 0 ? sunset % 24 : sunset % 24 + 24 ; // ensure that the time is >= 0 and < 24
@@ -116,19 +116,6 @@ private static double getJulianCenturiesFromJulianDay(double julianDay) {
116
116
return (julianDay - JULIAN_DAY_JAN_1_2000 ) / JULIAN_DAYS_PER_CENTURY ;
117
117
}
118
118
119
- /**
120
- * Convert centuries since <a href="https://en.wikipedia.org/wiki/Epoch_(astronomy)#J2000">J2000.0</a> to
121
- * <a href="https://en.wikipedia.org/wiki/Julian_day">Julian day</a>.
122
- *
123
- * @param julianCenturies
124
- * the number of Julian centuries since <a href=
125
- * "https://en.wikipedia.org/wiki/Epoch_(astronomy)#J2000">J2000.0</a>.
126
- * @return the Julian Day corresponding to the Julian centuries passed in
127
- */
128
- private static double getJulianDayFromJulianCenturies (double julianCenturies ) {
129
- return julianCenturies * JULIAN_DAYS_PER_CENTURY + JULIAN_DAY_JAN_1_2000 ;
130
- }
131
-
132
119
/**
133
120
* Returns the Geometric <a href="https://en.wikipedia.org/wiki/Mean_longitude">Mean Longitude</a> of the Sun.
134
121
*
@@ -143,31 +130,31 @@ private static double getSunGeometricMeanLongitude(double julianCenturies) {
143
130
}
144
131
145
132
/**
146
- * Returns the Geometric <a href="https://en.wikipedia.org/wiki/Mean_anomaly">Mean Anomaly</a> of the Sun.
133
+ * Returns the Geometric <a href="https://en.wikipedia.org/wiki/Mean_anomaly">Mean Anomaly</a> of the Sun in degrees .
147
134
*
148
135
* @param julianCenturies
149
136
* the number of Julian centuries since <a href=
150
137
* "https://en.wikipedia.org/wiki/Epoch_(astronomy)#J2000">J2000.0</a>.
151
138
* @return the Geometric Mean Anomaly of the Sun in degrees
152
139
*/
153
140
private static double getSunGeometricMeanAnomaly (double julianCenturies ) {
154
- return 357.52911 + julianCenturies * (35999.05029 - 0.0001537 * julianCenturies ); // in degrees
141
+ return 357.52911 + julianCenturies * (35999.05029 - 0.0001537 * julianCenturies );
155
142
}
156
143
157
144
/**
158
- * Return the <a href="https://en.wikipedia.org/wiki/Eccentricity_%28orbit%29">eccentricity of earth's orbit</a>.
145
+ * Return the unitless <a href="https://en.wikipedia.org/wiki/Eccentricity_%28orbit%29">eccentricity of earth's orbit</a>.
159
146
*
160
147
* @param julianCenturies
161
148
* the number of Julian centuries since <a href=
162
149
* "https://en.wikipedia.org/wiki/Epoch_(astronomy)#J2000">J2000.0</a>.
163
150
* @return the unitless eccentricity
164
151
*/
165
152
private static double getEarthOrbitEccentricity (double julianCenturies ) {
166
- return 0.016708634 - julianCenturies * (0.000042037 + 0.0000001267 * julianCenturies ); // unitless
153
+ return 0.016708634 - julianCenturies * (0.000042037 + 0.0000001267 * julianCenturies );
167
154
}
168
155
169
156
/**
170
- * Returns the <a href="https://en.wikipedia.org/wiki/Equation_of_the_center">equation of center</a> for the sun.
157
+ * Returns the <a href="https://en.wikipedia.org/wiki/Equation_of_the_center">equation of center</a> for the sun in degrees .
171
158
*
172
159
* @param julianCenturies
173
160
* the number of Julian centuries since <a href=
@@ -181,7 +168,7 @@ private static double getSunEquationOfCenter(double julianCenturies) {
181
168
double sin2m = Math .sin (mrad + mrad );
182
169
double sin3m = Math .sin (mrad + mrad + mrad );
183
170
return sinm * (1.914602 - julianCenturies * (0.004817 + 0.000014 * julianCenturies )) + sin2m
184
- * (0.019993 - 0.000101 * julianCenturies ) + sin3m * 0.000289 ; // in degrees
171
+ * (0.019993 - 0.000101 * julianCenturies ) + sin3m * 0.000289 ;
185
172
}
186
173
187
174
/**
@@ -195,7 +182,7 @@ private static double getSunEquationOfCenter(double julianCenturies) {
195
182
private static double getSunTrueLongitude (double julianCenturies ) {
196
183
double sunLongitude = getSunGeometricMeanLongitude (julianCenturies );
197
184
double center = getSunEquationOfCenter (julianCenturies );
198
- return sunLongitude + center ; // in degrees
185
+ return sunLongitude + center ;
199
186
}
200
187
201
188
// /**
@@ -209,7 +196,7 @@ private static double getSunTrueLongitude(double julianCenturies) {
209
196
// double meanAnomaly = getSunGeometricMeanAnomaly(julianCenturies);
210
197
// double equationOfCenter = getSunEquationOfCenter(julianCenturies);
211
198
//
212
- // return meanAnomaly + equationOfCenter; // in degrees
199
+ // return meanAnomaly + equationOfCenter;
213
200
// }
214
201
215
202
/**
@@ -224,7 +211,7 @@ private static double getSunApparentLongitude(double julianCenturies) {
224
211
double sunTrueLongitude = getSunTrueLongitude (julianCenturies );
225
212
double omega = 125.04 - 1934.136 * julianCenturies ;
226
213
double lambda = sunTrueLongitude - 0.00569 - 0.00478 * Math .sin (Math .toRadians (omega ));
227
- return lambda ; // in degrees
214
+ return lambda ;
228
215
}
229
216
230
217
/**
@@ -238,7 +225,7 @@ private static double getSunApparentLongitude(double julianCenturies) {
238
225
private static double getMeanObliquityOfEcliptic (double julianCenturies ) {
239
226
double seconds = 21.448 - julianCenturies
240
227
* (46.8150 + julianCenturies * (0.00059 - julianCenturies * (0.001813 )));
241
- return 23.0 + (26.0 + (seconds / 60.0 )) / 60.0 ; // in degrees
228
+ return 23.0 + (26.0 + (seconds / 60.0 )) / 60.0 ;
242
229
}
243
230
244
231
/**
@@ -253,7 +240,7 @@ private static double getMeanObliquityOfEcliptic(double julianCenturies) {
253
240
private static double getObliquityCorrection (double julianCenturies ) {
254
241
double obliquityOfEcliptic = getMeanObliquityOfEcliptic (julianCenturies );
255
242
double omega = 125.04 - 1934.136 * julianCenturies ;
256
- return obliquityOfEcliptic + 0.00256 * Math .cos (Math .toRadians (omega )); // in degrees
243
+ return obliquityOfEcliptic + 0.00256 * Math .cos (Math .toRadians (omega ));
257
244
}
258
245
259
246
/**
@@ -270,7 +257,7 @@ private static double getSunDeclination(double julianCenturies) {
270
257
double lambda = getSunApparentLongitude (julianCenturies );
271
258
double sint = Math .sin (Math .toRadians (obliquityCorrection )) * Math .sin (Math .toRadians (lambda ));
272
259
double theta = Math .toDegrees (Math .asin (sint ));
273
- return theta ; // in degrees
260
+ return theta ;
274
261
}
275
262
276
263
/**
@@ -296,7 +283,7 @@ private static double getEquationOfTime(double julianCenturies) {
296
283
double sin2m = Math .sin (2.0 * Math .toRadians (geomMeanAnomalySun ));
297
284
double equationOfTime = y * sin2l0 - 2.0 * eccentricityEarthOrbit * sinm + 4.0 * eccentricityEarthOrbit * y
298
285
* sinm * cos2l0 - 0.5 * y * y * sin4l0 - 1.25 * eccentricityEarthOrbit * eccentricityEarthOrbit * sin2m ;
299
- return Math .toDegrees (equationOfTime ) * 4.0 ; // in minutes of time
286
+ return Math .toDegrees (equationOfTime ) * 4.0 ;
300
287
}
301
288
302
289
/**
@@ -403,20 +390,19 @@ public static double getSolarAzimuth(Calendar calendar, double latitude, double
403
390
* @return the time in minutes from zero UTC
404
391
*/
405
392
public double getUTCNoon (Calendar calendar , GeoLocation geoLocation ) {
406
- double julianDay = getJulianDay (calendar );
407
- double julianCenturies = getJulianCenturiesFromJulianDay (julianDay );
408
- double noon = getSolarNoonUTC (julianCenturies , -geoLocation .getLongitude ());
393
+ double noon = getSolarNoonUTC (getJulianDay (calendar ), -geoLocation .getLongitude ());
409
394
noon = noon / 60 ;
410
395
return noon > 0 ? noon % 24 : noon % 24 + 24 ; // ensure that the time is >= 0 and < 24
411
396
}
412
397
413
398
/**
414
399
* Return the <a href="https://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
415
- * of of <a href="http://en.wikipedia.org/wiki/Noon#Solar_noon">solar noon</a> for the given day at the given location
400
+ * of <a href="http://en.wikipedia.org/wiki/Noon#Solar_noon">solar noon</a> for the given day at the given location
416
401
* on earth.
402
+ * @todo Refactor to possibly use the getSunRiseSetUTC (to be renamed) and remove the need for this method.
417
403
*
418
- * @param julianCenturies
419
- * the number of Julian centuries since <a href=
404
+ * @param julianDay
405
+ * the Julian day since <a href=
420
406
* "https://en.wikipedia.org/wiki/Epoch_(astronomy)#J2000">J2000.0</a>.
421
407
* @param longitude
422
408
* the longitude of observer in degrees
@@ -426,24 +412,26 @@ public double getUTCNoon(Calendar calendar, GeoLocation geoLocation) {
426
412
* @see com.kosherjava.zmanim.util.AstronomicalCalculator#getUTCNoon(Calendar, GeoLocation)
427
413
* @see #getUTCNoon(Calendar, GeoLocation)
428
414
*/
429
- private static double getSolarNoonUTC (double julianCenturies , double longitude ) {
430
- // Only 1 pass for approximate solar noon to calculate equation of time
431
- double tnoon = getJulianCenturiesFromJulianDay (getJulianDayFromJulianCenturies (julianCenturies ) + longitude
432
- / 360.0 );
415
+ private static double getSolarNoonUTC (double julianDay , double longitude ) {
416
+ // First pass for approximate solar noon to calculate equation of time
417
+ double tnoon = getJulianCenturiesFromJulianDay (julianDay + longitude / 360.0 );
433
418
double equationOfTime = getEquationOfTime (tnoon );
434
419
double solNoonUTC = 720 + (longitude * 4 ) - equationOfTime ; // minutes
435
- double newt = getJulianCenturiesFromJulianDay (getJulianDayFromJulianCenturies (julianCenturies ) - 0.5
436
- + solNoonUTC / 1440.0 );
420
+
421
+ // second pass
422
+ double newt = getJulianCenturiesFromJulianDay (julianDay - 0.5 + solNoonUTC / 1440.0 );
437
423
equationOfTime = getEquationOfTime (newt );
438
- return 720 + (longitude * 4 ) - equationOfTime ; // minutes
424
+ return 720 + (longitude * 4 ) - equationOfTime ;
439
425
}
440
426
441
427
/**
442
428
* Return the <a href="https://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
443
- * of sunrise or sunset for the given day at the given location on earth.
429
+ * of sunrise or sunset in minutes for the given day at the given location on earth.
430
+ * @todo support solar noon and possibly increase the number of passes in the Arctic areas.
431
+ * This would remove the need for getSolarNoonUTC.
444
432
*
445
- * @param julianDay
446
- * the Julian day
433
+ * @param calendar
434
+ * the calendar
447
435
* @param latitude
448
436
* the latitude of observer in degrees
449
437
* @param longitude
@@ -454,16 +442,16 @@ private static double getSolarNoonUTC(double julianCenturies, double longitude)
454
442
* Is the calculation for sunrise or sunset
455
443
* @return the time in minutes from zero Universal Coordinated Time (UTC)
456
444
*/
457
- private static double getSunRiseSetUTC (double julianDay , double latitude , double longitude , double zenith ,
445
+ private static double getSunRiseSetUTC (Calendar calendar , double latitude , double longitude , double zenith ,
458
446
SolarEvent solarEvent ) {
459
- double julianCenturies = getJulianCenturiesFromJulianDay ( julianDay );
447
+ double julianDay = getJulianDay ( calendar );
460
448
461
449
// Find the time of solar noon at the location, and use that declination.
462
450
// This is better than start of the Julian day
463
- double noonmin = getSolarNoonUTC (julianCenturies , longitude );
451
+ double noonmin = getSolarNoonUTC (julianDay , longitude );
464
452
double tnoon = getJulianCenturiesFromJulianDay (julianDay + noonmin / 1440.0 );
465
453
466
- // First calculates sunrise and approx length of day
454
+ // First calculates sunrise and approximate length of day
467
455
double equationOfTime = getEquationOfTime (tnoon );
468
456
double solarDeclination = getSunDeclination (tnoon );
469
457
double hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , solarEvent );
@@ -472,14 +460,14 @@ private static double getSunRiseSetUTC(double julianDay, double latitude, double
472
460
double timeUTC = 720 + timeDiff - equationOfTime ;
473
461
474
462
// Second pass includes fractional Julian Day in gamma calc
475
- double newt = getJulianCenturiesFromJulianDay (getJulianDayFromJulianCenturies (julianCenturies ) + timeUTC
476
- / 1440.0 );
463
+ double newt = getJulianCenturiesFromJulianDay (julianDay + timeUTC / 1440.0 );
477
464
equationOfTime = getEquationOfTime (newt );
465
+
478
466
solarDeclination = getSunDeclination (newt );
479
467
hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , solarEvent );
480
468
delta = longitude - Math .toDegrees (hourAngle );
481
469
timeDiff = 4 * delta ;
482
- timeUTC = 720 + timeDiff - equationOfTime ; // in minutes
470
+ timeUTC = 720 + timeDiff - equationOfTime ;
483
471
return timeUTC ;
484
472
}
485
473
}
0 commit comments