Last active
April 19, 2018 06:28
-
-
Save komasaru/ffa7220cda43e1ba0f143b00b0ba49e6 to your computer and use it in GitHub Desktop.
Ruby script to convert celestial coordinates.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/local/bin/ruby | |
# coding: utf-8 | |
#--------------------------------------------------------------------------------- | |
#= 赤道・黄道座標変換 | |
# | |
# date name version | |
# 2016.08.29 mk-mode.com 1.00 新規作成 | |
# | |
# Copyright(C) 2016 mk-mode.com All Rights Reserved. | |
#--------------------------------------------------------------------------------- | |
#++ | |
require "mk_coord" | |
class CoordConversion | |
# 黄道傾斜角(単位: rad) | |
# (Math::PI は MkCoord::Const::PI と置き換えてもよい) | |
EPS = 23.43929 * Math::PI / 180.0 | |
# 元の赤道直交座標 | |
POS = [ | |
0.99443659220700997281, | |
-0.03816291768957833647, | |
-0.01655177670960058384 | |
] # <= ある日の地球重心から見た太陽重心の位置(単位: AU) | |
def exec | |
puts "元の赤道直交座標:\n #{POS}" | |
rect_ec = MkCoord.rect_eq2ec(POS, EPS) | |
puts "黄道直交座標に変換:\n #{rect_ec}" | |
rect_eq = MkCoord.rect_ec2eq(rect_ec, EPS) | |
puts "赤道直交座標に戻す:\n #{rect_eq}" | |
*pol_eq, r = MkCoord.rect2pol(rect_eq) | |
puts "赤道極座標に変換:\n #{pol_eq[0, 2]} (R = #{r})" | |
pol_ec = MkCoord.pol_eq2ec(pol_eq[0, 2], EPS) | |
puts "黄道極座標に変換:\n #{pol_ec[0, 2]}" | |
pol_eq = MkCoord.pol_ec2eq(pol_ec, EPS) | |
puts "赤道極座標に戻す:\n #{pol_eq[0, 2]}" | |
rect_eq = MkCoord.pol2rect(pol_eq[0, 2], r) | |
puts "赤道直交座標に戻す:\n #{rect_eq}" | |
rescue => e | |
puts "[#{e.class}] #{e.message}" | |
e.backtrace.each { |tr| $stderr.puts "\t#{tr}" } | |
exit 1 | |
end | |
end | |
CoordConversion.new.exec if __FILE__ == $0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment