@@ -65,10 +65,9 @@ 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 = getSunriseUTC (getJulianDay (calendar ), geoLocation .getLatitude (), -geoLocation .getLongitude (),
69
- adjustedZenith );
68
+ double sunrise = getSunRiseSetUTC (getJulianDay (calendar ), geoLocation .getLatitude (), -geoLocation .getLongitude (),
69
+ adjustedZenith , SolarEvent . SUNRISE );
70
70
sunrise = sunrise / 60 ;
71
-
72
71
return sunrise > 0 ? sunrise % 24 : sunrise % 24 + 24 ; // ensure that the time is >= 0 and < 24
73
72
}
74
73
@@ -78,8 +77,8 @@ public double getUTCSunrise(Calendar calendar, GeoLocation geoLocation, double z
78
77
public double getUTCSunset (Calendar calendar , GeoLocation geoLocation , double zenith , boolean adjustForElevation ) {
79
78
double elevation = adjustForElevation ? geoLocation .getElevation () : 0 ;
80
79
double adjustedZenith = adjustZenith (zenith , elevation );
81
- double sunset = getSunsetUTC (getJulianDay (calendar ), geoLocation .getLatitude (), -geoLocation .getLongitude (),
82
- adjustedZenith );
80
+ double sunset = getSunRiseSetUTC (getJulianDay (calendar ), geoLocation .getLatitude (), -geoLocation .getLongitude (),
81
+ adjustedZenith , SolarEvent . SUNSET );
83
82
sunset = sunset / 60 ;
84
83
return sunset > 0 ? sunset % 24 : sunset % 24 + 24 ; // ensure that the time is >= 0 and < 24
85
84
}
@@ -386,48 +385,6 @@ public static double getSolarAzimuth(Calendar calendar, double latitude, double
386
385
387
386
}
388
387
389
- /**
390
- * Return the <a href="https://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
391
- * of sunrise for the given day at the given location on earth.
392
- *
393
- * @param julianDay
394
- * the Julian day
395
- * @param latitude
396
- * the latitude of observer in degrees
397
- * @param longitude
398
- * the longitude of observer in degrees
399
- * @param zenith
400
- * the zenith
401
- * @return the time in minutes from zero UTC
402
- */
403
- private static double getSunriseUTC (double julianDay , double latitude , double longitude , double zenith ) {
404
- double julianCenturies = getJulianCenturiesFromJulianDay (julianDay );
405
-
406
- // Find the time of solar noon at the location, and use that declination. This is better than start of the
407
- // Julian day
408
- double noonmin = getSolarNoonUTC (julianCenturies , longitude );
409
- double tnoon = getJulianCenturiesFromJulianDay (julianDay + noonmin / 1440.0 );
410
-
411
- // First pass to approximate sunrise (using solar noon)
412
- double equationOfTime = getEquationOfTime (tnoon );
413
- double solarDeclination = getSunDeclination (tnoon );
414
- double hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , SolarEvent .SUNRISE );
415
- double delta = longitude - Math .toDegrees (hourAngle );
416
- double timeDiff = 4 * delta ; // in minutes of time
417
- double timeUTC = 720 + timeDiff - equationOfTime ; // in minutes
418
-
419
- // Second pass includes fractional Julian Day in gamma calc
420
- double newt = getJulianCenturiesFromJulianDay (getJulianDayFromJulianCenturies (julianCenturies ) + timeUTC
421
- / 1440.0 );
422
- equationOfTime = getEquationOfTime (newt );
423
- solarDeclination = getSunDeclination (newt );
424
- hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , SolarEvent .SUNRISE );
425
- delta = longitude - Math .toDegrees (hourAngle );
426
- timeDiff = 4 * delta ;
427
- timeUTC = 720 + timeDiff - equationOfTime ; // in minutes
428
- return timeUTC ;
429
- }
430
-
431
388
/**
432
389
* Return the <a href="https://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
433
390
* of <a href="https://en.wikipedia.org/wiki/Noon#Solar_noon">solar noon</a> for the given day at the given location
@@ -470,7 +427,7 @@ public double getUTCNoon(Calendar calendar, GeoLocation geoLocation) {
470
427
* @see #getUTCNoon(Calendar, GeoLocation)
471
428
*/
472
429
private static double getSolarNoonUTC (double julianCenturies , double longitude ) {
473
- // First pass uses approximate solar noon to calculate equation of time
430
+ // Only 1 pass for approximate solar noon to calculate equation of time
474
431
double tnoon = getJulianCenturiesFromJulianDay (getJulianDayFromJulianCenturies (julianCenturies ) + longitude
475
432
/ 360.0 );
476
433
double equationOfTime = getEquationOfTime (tnoon );
@@ -480,10 +437,10 @@ private static double getSolarNoonUTC(double julianCenturies, double longitude)
480
437
equationOfTime = getEquationOfTime (newt );
481
438
return 720 + (longitude * 4 ) - equationOfTime ; // minutes
482
439
}
483
-
440
+
484
441
/**
485
442
* Return the <a href="https://en.wikipedia.org/wiki/Universal_Coordinated_Time">Universal Coordinated Time</a> (UTC)
486
- * of sunset for the given day at the given location on earth.
443
+ * of sunrise or sunset for the given day at the given location on earth.
487
444
*
488
445
* @param julianDay
489
446
* the Julian day
@@ -493,20 +450,23 @@ private static double getSolarNoonUTC(double julianCenturies, double longitude)
493
450
* longitude of observer in degrees
494
451
* @param zenith
495
452
* zenith
453
+ * @param solarEvent
454
+ * Is the calculation for sunrise or sunset
496
455
* @return the time in minutes from zero Universal Coordinated Time (UTC)
497
456
*/
498
- private static double getSunsetUTC (double julianDay , double latitude , double longitude , double zenith ) {
457
+ private static double getSunRiseSetUTC (double julianDay , double latitude , double longitude , double zenith ,
458
+ SolarEvent solarEvent ) {
499
459
double julianCenturies = getJulianCenturiesFromJulianDay (julianDay );
500
460
501
- // Find the time of solar noon at the location, and use that declination. This is better than start of the
502
- // Julian day
461
+ // Find the time of solar noon at the location, and use that declination.
462
+ // This is better than start of the Julian day
503
463
double noonmin = getSolarNoonUTC (julianCenturies , longitude );
504
464
double tnoon = getJulianCenturiesFromJulianDay (julianDay + noonmin / 1440.0 );
505
465
506
466
// First calculates sunrise and approx length of day
507
467
double equationOfTime = getEquationOfTime (tnoon );
508
468
double solarDeclination = getSunDeclination (tnoon );
509
- double hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , SolarEvent . SUNSET );
469
+ double hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , solarEvent );
510
470
double delta = longitude - Math .toDegrees (hourAngle );
511
471
double timeDiff = 4 * delta ;
512
472
double timeUTC = 720 + timeDiff - equationOfTime ;
@@ -516,7 +476,7 @@ private static double getSunsetUTC(double julianDay, double latitude, double lon
516
476
/ 1440.0 );
517
477
equationOfTime = getEquationOfTime (newt );
518
478
solarDeclination = getSunDeclination (newt );
519
- hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , SolarEvent . SUNSET );
479
+ hourAngle = getSunHourAngle (latitude , solarDeclination , zenith , solarEvent );
520
480
delta = longitude - Math .toDegrees (hourAngle );
521
481
timeDiff = 4 * delta ;
522
482
timeUTC = 720 + timeDiff - equationOfTime ; // in minutes
0 commit comments