Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def pos(degree = 0, minute = 0, second = 0, negate = false)
- if negate
- (-1 * pos(degree, minute, second))
- else
- (Float(degree) + (Float(minute) / 60) + (Float(second) / 60 / 60))
- end
- end
- day = 6
- month = 2
- year = 2011
- rad_factor = 180 / Math::PI # => 57.2957795130823
- def sin_d(theta)
- Math.sin(theta * Math::PI / 180)
- end
- def cos_d(theta)
- Math.cos(theta * Math::PI / 180)
- end
- def tan_d(theta)
- Math.tan(theta * Math::PI / 180)
- end
- def acos_d(theta)
- 180 / Math::PI * Math.acos(theta)
- end
- def asin_d(theta)
- 180 / Math::PI * Math.asin(theta)
- end
- def atan_d(theta)
- 180 / Math::PI * Math.atan(theta)
- end
- longitude = pos(2, 9, 48, true) # => -2.16333333333333
- lattitude = pos(51, 1, 31) # => 51.0252777777778
- day_of_year = ((275 * month / 9).floor) - ((((month + 9) / 12).floor) * (1 + (year - 4 * (year / 4).floor + 2).floor / 3)) + day - 30 # => 33
- day_of_year # => 33
- lng_hour = longitude / 15 # => -0.144222222222222
- # rising
- t = day_of_year + ((6 - lng_hour) / 24) # => 33.2560092592593
- # setting
- t = day_of_year + ((18 - lng_hour) / 24)
- m = (0.9856 * t) - 3.289 # => 29.9809227259259
- l = m + (1.916 * sin_d(m)) + (0.02 * sin_d(2 * m)) + 282.634 # => 313.589684033694
- l = (l < 0) ? l + 360 : (l > 360 ? l - 360 : l) # => 313.589684033694
- ra = atan_d(0.91764 * tan_d(l)) # => -43.9488322973256
- ra = (ra < 0) ? ra + 360 : (ra > 360 ? ra - 360 : ra) # => 316.051167702674
- l_quadrant = (l / 90).floor * 90 # => 270
- ra_quadrant = (ra / 90).floor * 90 # => 270
- ra = ra + (l_quadrant - ra_quadrant) # => 316.051167702674
- ra = ra / 15 # => 21.070077846845
- sin_dec = 0.39782 * sin_d(l) # => -0.288139440300342
- cos_dec = cos_d(asin_d(sin_dec)) # => 0.95758846220253
- cos_h = (cos_d(pos(90, 50, 0)) - (sin_dec * sin_d(lattitude))) / (cos_dec * cos_d(lattitude)) # => 0.34777011168273
- # rising
- h = 360 - acos_d(cos_h) # => 290.350985694917
- # setting
- h = acos_d(cos_h)
- h = h / 15 # => 4.64326762033886
- big_t = h + ra - (0.06571 * t) - 6.622 # => 16.8732380987579
- ut = big_t - lng_hour # => 17.0174603209801
- ut = (ut < 0) ? ut + 24 : (ut > 24 ? ut - 24 : ut) # => 17.0174603209801
- hour = ut.floor # => 17
- minute = ((ut - hour) * 60).round # => 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement