src

Go monorepo.
git clone git://code.dwrz.net/src
Log | Files | Refs

hourangle.go (723B)


      1 package sunrise
      2 
      3 import (
      4 	"math"
      5 )
      6 
      7 // HourAngle calculates the second of the two angles required to locate a point
      8 // on the celestial sphere in the equatorial coordinate system.
      9 func HourAngle(latitude, declination float64) float64 {
     10 	var (
     11 		latitudeRad    = latitude * Degree
     12 		declinationRad = declination * Degree
     13 		numerator      = -0.01449 - math.Sin(latitudeRad)*math.Sin(declinationRad)
     14 		denominator    = math.Cos(latitudeRad) * math.Cos(declinationRad)
     15 	)
     16 
     17 	// Check for no sunrise/sunset
     18 	if numerator/denominator > 1 {
     19 		// Sun never rises
     20 		return math.MaxFloat64
     21 	}
     22 
     23 	if numerator/denominator < -1 {
     24 		// Sun never sets
     25 		return -1 * math.MaxFloat64
     26 	}
     27 
     28 	return math.Acos(numerator/denominator) / Degree
     29 }