Module: SunCalc::Helpers
- Included in:
- SunCalc
- Defined in:
- lib/sun_calc/helpers.rb
Overview
:nodoc:
Instance Method Summary collapse
- #altitude(h, phi, dec) ⇒ Object
- #approx_transit(ht, lw, n) ⇒ Object
- #astro_refraction(h) ⇒ Object
- #azimuth(h, phi, dec) ⇒ Object
- #declination(l, b) ⇒ Object
- #ecliptic_longitude(m) ⇒ Object
- #from_julian(j) ⇒ Object
- #get_set_j(h0, lw, phi, dec, n, m, l) ⇒ Object
- #hour_angle(h0, phi, dec) ⇒ Object
- #hours_later(date, h) ⇒ Object
- #julian_cycle(d, lw) ⇒ Object
- #moon_coords(d) ⇒ Object
- #right_ascension(l, b) ⇒ Object
- #sidereal_time(d, lw) ⇒ Object
- #solar_mean_anomaly(d) ⇒ Object
- #solar_transit_j(ds, m, l) ⇒ Object
- #sun_coords(d) ⇒ Object
- #to_days(date) ⇒ Object
- #to_julian(date) ⇒ Object
Instance Method Details
#altitude(h, phi, dec) ⇒ Object
36 37 38 39 |
# File 'lib/sun_calc/helpers.rb', line 36 def altitude(h, phi, dec) Math.asin(Math.sin(phi) * Math.sin(dec) + Math.cos(phi) * Math.cos(dec) * Math.cos(h)) end |
#approx_transit(ht, lw, n) ⇒ Object
77 78 79 |
# File 'lib/sun_calc/helpers.rb', line 77 def approx_transit(ht, lw, n) J0 + (ht + lw) / (2 * Math::PI) + n end |
#astro_refraction(h) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/sun_calc/helpers.rb', line 45 def astro_refraction(h) # The following formula works for positive altitudes only. h = 0 if h < 0 # Based on forumla 16.4 of "Astronomical Algorithms" 2nd edition by Jean # Meeus (Willmann-Bell, Richmond) 1998. 0.0002967 / Math.tan(h + 0.00312536 / (h + 0.08901179)) end |
#azimuth(h, phi, dec) ⇒ Object
31 32 33 34 |
# File 'lib/sun_calc/helpers.rb', line 31 def azimuth(h, phi, dec) Math.atan2(Math.sin(h), Math.cos(h) * Math.sin(phi) - Math.tan(dec) * Math.cos(phi)) end |
#declination(l, b) ⇒ Object
26 27 28 29 |
# File 'lib/sun_calc/helpers.rb', line 26 def declination(l, b) Math.asin(Math.sin(b) * Math.cos(OBLIQUITY_OF_THE_EARTH) + Math.cos(b) * Math.sin(OBLIQUITY_OF_THE_EARTH) * Math.sin(l)) end |
#ecliptic_longitude(m) ⇒ Object
57 58 59 60 61 62 63 64 |
# File 'lib/sun_calc/helpers.rb', line 57 def ecliptic_longitude(m) # Equation of center. c = ONE_RADIAN * (1.9148 * Math.sin(m) + 0.02 * Math.sin(2 * m) + 0.0003 * Math.sin(3 * m)) # Perihelion of Earth. p = ONE_RADIAN * 102.9372 m + c + p + Math::PI end |
#from_julian(j) ⇒ Object
10 11 12 |
# File 'lib/sun_calc/helpers.rb', line 10 def from_julian(j) Time.at((j + 0.5 - J1970) * ONE_DAY_IN_SECONDS).utc end |
#get_set_j(h0, lw, phi, dec, n, m, l) ⇒ Object
92 93 94 95 96 |
# File 'lib/sun_calc/helpers.rb', line 92 def get_set_j(h0, lw, phi, dec, n, m, l) w = hour_angle(h0, phi, dec) a = approx_transit(w, lw, n) solar_transit_j(a, m, l) end |
#hour_angle(h0, phi, dec) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/sun_calc/helpers.rb', line 85 def hour_angle(h0, phi, dec) Math.acos( (Math.sin(h0) - Math.sin(phi) * Math.sin(dec)) / (Math.cos(phi) * Math.cos(dec)) ) end |
#hours_later(date, h) ⇒ Object
111 112 113 |
# File 'lib/sun_calc/helpers.rb', line 111 def hours_later(date, h) Time.at(date.to_f + h * ONE_DAY_IN_SECONDS / 24).utc end |
#julian_cycle(d, lw) ⇒ Object
73 74 75 |
# File 'lib/sun_calc/helpers.rb', line 73 def julian_cycle(d, lw) (d - J0 - lw / (2 * Math::PI)).round end |
#moon_coords(d) ⇒ Object
98 99 100 101 102 103 104 105 106 107 108 109 |
# File 'lib/sun_calc/helpers.rb', line 98 def moon_coords(d) # Geocentric ecliptic coordinates of the moon l = ONE_RADIAN * (218.316 + 13.176396 * d) # ecliptic longitude m = ONE_RADIAN * (134.963 + 13.064993 * d) # mean anomaly f = ONE_RADIAN * (93.272 + 13.229350 * d) # mean distance l += ONE_RADIAN * 6.289 * Math.sin(m) # longitude b = ONE_RADIAN * 5.128 * Math.sin(f) # latitude dt = 385_001 - 20_905 * Math.cos(m) # distance to the moon in km { ra: right_ascension(l, b), dec: declination(l, b), dist: dt } end |
#right_ascension(l, b) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/sun_calc/helpers.rb', line 18 def right_ascension(l, b) Math.atan2( Math.sin(l) * Math.cos(OBLIQUITY_OF_THE_EARTH) - Math.tan(b) * Math.sin(OBLIQUITY_OF_THE_EARTH), Math.cos(l) ) end |
#sidereal_time(d, lw) ⇒ Object
41 42 43 |
# File 'lib/sun_calc/helpers.rb', line 41 def sidereal_time(d, lw) ONE_RADIAN * (280.16 + 360.9856235 * d) - lw end |
#solar_mean_anomaly(d) ⇒ Object
53 54 55 |
# File 'lib/sun_calc/helpers.rb', line 53 def solar_mean_anomaly(d) ONE_RADIAN * (357.5291 + 0.98560028 * d) end |
#solar_transit_j(ds, m, l) ⇒ Object
81 82 83 |
# File 'lib/sun_calc/helpers.rb', line 81 def solar_transit_j(ds, m, l) J2000 + ds + 0.0053 * Math.sin(m) - 0.0069 * Math.sin(2 * l) end |
#sun_coords(d) ⇒ Object
66 67 68 69 70 71 |
# File 'lib/sun_calc/helpers.rb', line 66 def sun_coords(d) m = solar_mean_anomaly(d) l = ecliptic_longitude(m) { dec: declination(l, 0), ra: right_ascension(l, 0) } end |
#to_days(date) ⇒ Object
14 15 16 |
# File 'lib/sun_calc/helpers.rb', line 14 def to_days(date) to_julian(date) - J2000 end |
#to_julian(date) ⇒ Object
6 7 8 |
# File 'lib/sun_calc/helpers.rb', line 6 def to_julian(date) date.to_f / ONE_DAY_IN_SECONDS - 0.5 + J1970 end |