Advertisement
andyherbert

Untitled

Jul 4th, 2020
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.21 KB | None | 0 0
  1. def pos(degree = 0, minute = 0, second = 0, negate = false)
  2.   if negate
  3.     (-1 * pos(degree, minute, second))
  4.   else
  5.     (Float(degree) + (Float(minute) / 60) + (Float(second) / 60 / 60))
  6.   end
  7. end
  8.  
  9. day = 6
  10. month = 2
  11. year = 2011
  12.  
  13. rad_factor = 180 / Math::PI # => 57.2957795130823
  14.  
  15. def sin_d(theta)
  16.   Math.sin(theta * Math::PI / 180)
  17. end
  18.  
  19. def cos_d(theta)
  20.   Math.cos(theta * Math::PI / 180)
  21. end
  22.  
  23. def tan_d(theta)
  24.   Math.tan(theta * Math::PI / 180)
  25. end
  26.  
  27. def acos_d(theta)
  28.   180 / Math::PI * Math.acos(theta)
  29. end
  30.  
  31. def asin_d(theta)
  32.   180 / Math::PI * Math.asin(theta)
  33. end
  34.  
  35. def atan_d(theta)
  36.   180 / Math::PI * Math.atan(theta)
  37. end
  38.  
  39. longitude = pos(2, 9, 48, true) # => -2.16333333333333
  40. lattitude = pos(51, 1, 31) # => 51.0252777777778
  41.  
  42. day_of_year = ((275 * month / 9).floor) - ((((month + 9) / 12).floor) * (1 + (year - 4 * (year / 4).floor + 2).floor / 3)) + day - 30 # => 33
  43.  
  44. day_of_year # => 33
  45.  
  46. lng_hour = longitude / 15 # => -0.144222222222222
  47.  
  48. # rising
  49. t = day_of_year + ((6 - lng_hour) / 24) # => 33.2560092592593
  50.  
  51. # setting
  52. t = day_of_year + ((18 - lng_hour) / 24)
  53.  
  54. m = (0.9856 * t) - 3.289 # => 29.9809227259259
  55.  
  56. l = m + (1.916 * sin_d(m)) + (0.02 * sin_d(2 * m)) + 282.634 # => 313.589684033694
  57. l = (l < 0) ? l + 360 : (l > 360 ? l - 360 : l) # => 313.589684033694
  58.  
  59. ra = atan_d(0.91764 * tan_d(l)) # => -43.9488322973256
  60.  
  61. ra = (ra < 0) ? ra + 360 : (ra > 360 ? ra - 360 : ra) # => 316.051167702674
  62.  
  63. l_quadrant = (l / 90).floor * 90 # => 270
  64. ra_quadrant = (ra / 90).floor * 90 # => 270
  65.  
  66. ra = ra + (l_quadrant - ra_quadrant) # => 316.051167702674
  67.  
  68. ra = ra / 15 # => 21.070077846845
  69.  
  70. sin_dec = 0.39782 * sin_d(l) # => -0.288139440300342
  71. cos_dec = cos_d(asin_d(sin_dec)) # => 0.95758846220253
  72.  
  73. cos_h = (cos_d(pos(90, 50, 0)) - (sin_dec * sin_d(lattitude))) / (cos_dec * cos_d(lattitude)) # => 0.34777011168273
  74.  
  75. # rising
  76. h = 360 - acos_d(cos_h) # => 290.350985694917
  77.  
  78. # setting
  79. h = acos_d(cos_h)
  80.  
  81. h = h / 15 # => 4.64326762033886
  82.  
  83. big_t = h + ra - (0.06571 * t) - 6.622 # => 16.8732380987579
  84.  
  85. ut = big_t - lng_hour # => 17.0174603209801
  86. ut = (ut < 0) ? ut + 24 : (ut > 24 ? ut - 24 : ut) # => 17.0174603209801
  87.  
  88. hour = ut.floor # => 17
  89. minute = ((ut - hour) * 60).round # => 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement