Skip to content

Instantly share code, notes, and snippets.

@jarodl
Created April 29, 2009 00:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jarodl/103500 to your computer and use it in GitHub Desktop.
Save jarodl/103500 to your computer and use it in GitHub Desktop.
def deg2ra(num)
if num < 0
deg = deg + 360
elsif num > 360
puts "input should not exceed 360!"
end
hour = (num/15).to_i()
min = ((num-15*hour)*4).to_i()
sec = (4*num-60*hour-min)*60
final = "#{hour}h#{min}m#{sec}s"
end
def deg2dec(num)
num = num.to_f()
if num < 0 then
sign = "-"
num = num*(-1)
else
sign = "+"
end
if num > 180
puts "input should not exceed 180!"
elsif num > 90
# exceeds 90, so convert to - dec
num -= 90
sign = "-"
end
hour = num.to_i()
min = (( num - num.to_i() ) * 60).to_i()
sec = ( (num-num.to_i() ) * 60 - min ) * 60
sign + "#{hour}h#{min}m#{sec}s"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment