Class SunTimesCalculator

    • Field Detail

      • DEG_PER_HOUR

        private static final double DEG_PER_HOUR
        The number of degrees of longitude that corresponds to one hour time difference.
        See Also:
        Constant Field Values
    • Method Detail

      • sinDeg

        private static double sinDeg​(double deg)
        Parameters:
        deg - the degrees
        Returns:
        sin of the angle in degrees
      • acosDeg

        private static double acosDeg​(double x)
        Parameters:
        x - angle
        Returns:
        acos of the angle in degrees
      • asinDeg

        private static double asinDeg​(double x)
        Parameters:
        x - angle
        Returns:
        asin of the angle in degrees
      • tanDeg

        private static double tanDeg​(double deg)
        Parameters:
        deg - degrees
        Returns:
        tan of the angle in degrees
      • cosDeg

        private static double cosDeg​(double deg)
        Calculate cosine of the angle in degrees
        Parameters:
        deg - degrees
        Returns:
        cosine of the angle in degrees
      • getHoursFromMeridian

        private static double getHoursFromMeridian​(double longitude)
        Get time difference between location's longitude and the Meridian, in hours.
        Parameters:
        longitude - the longitude
        Returns:
        time difference between the location's longitude and the Meridian, in hours. West of Meridian has a negative time difference
      • getApproxTimeDays

        private static double getApproxTimeDays​(int dayOfYear,
                                                double hoursFromMeridian,
                                                boolean isSunrise)
        Calculate the approximate time of sunset or sunrise in days since midnight Jan 1st, assuming 6am and 6pm events. We need this figure to derive the Sun's mean anomaly.
        Parameters:
        dayOfYear - the day of year
        hoursFromMeridian - hours from the meridian
        isSunrise - true for sunrise and false for sunset
        Returns:
        the approximate time of sunset or sunrise in days since midnight Jan 1st, assuming 6am and 6pm events. We need this figure to derive the Sun's mean anomaly.
      • getMeanAnomaly

        private static double getMeanAnomaly​(int dayOfYear,
                                             double longitude,
                                             boolean isSunrise)
        Calculate the Sun's mean anomaly in degrees, at sunrise or sunset, given the longitude in degrees
        Parameters:
        dayOfYear - the day of the year
        longitude - longitude
        isSunrise - true for sunrise and false for sunset
        Returns:
        the Sun's mean anomaly in degrees
      • getSunTrueLongitude

        private static double getSunTrueLongitude​(double sunMeanAnomaly)
        Parameters:
        sunMeanAnomaly - the Sun's mean anomaly in degrees
        Returns:
        the Sun's true longitude in degrees. The result is an angle >= 0 and <= 360.
      • getSunRightAscensionHours

        private static double getSunRightAscensionHours​(double sunTrueLongitude)
        Calculates the Sun's right ascension in hours.
        Parameters:
        sunTrueLongitude - the Sun's true longitude in degrees > 0 and < 360.
        Returns:
        the Sun's right ascension in hours in angles > 0 and < 360.
      • getCosLocalHourAngle

        private static double getCosLocalHourAngle​(double sunTrueLongitude,
                                                   double latitude,
                                                   double zenith)
        Calculate the cosine of the Sun's local hour angle
        Parameters:
        sunTrueLongitude - the sun's true longitude
        latitude - the latitude
        zenith - the zenith
        Returns:
        the cosine of the Sun's local hour angle
      • getLocalMeanTime

        private static double getLocalMeanTime​(double localHour,
                                               double sunRightAscensionHours,
                                               double approxTimeDays)
        Calculate local mean time of rising or setting. By 'local' is meant the exact time at the location, assuming that there were no time zone. That is, the time difference between the location and the Meridian depended entirely on the longitude. We can't do anything with this time directly; we must convert it to UTC and then to a local time.
        Parameters:
        localHour - the local hour
        sunRightAscensionHours - the sun's right ascention in hours
        approxTimeDays - approximate time days
        Returns:
        the fractional number of hours since midnight as a double
      • getTimeUTC

        private static double getTimeUTC​(Calendar calendar,
                                         GeoLocation geoLocation,
                                         double zenith,
                                         boolean isSunrise)
        Get sunrise or sunset time in UTC, according to flag. This time is returned as a double and is not adjusted for time-zone.
        Parameters:
        calendar - the Calendar object to extract the day of year for calculation
        geoLocation - the GeoLocation object that contains the latitude and longitude
        zenith - Sun's zenith, in degrees
        isSunrise - True for sunrise and false for sunset.
        Returns:
        the time as a double. If an error was encountered in the calculation (expected behavior for some locations such as near the poles, Double.NaN will be returned.