mk_sunmoon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 73b07a2e353f23c02f3b3f81df5a8e8627b48320
4
+ data.tar.gz: e4ce92fc88c1365104e6876ed64a3d570b6962df
5
+ SHA512:
6
+ metadata.gz: dcd38b0bf57a188390faa5ead0ef487463c3ffeade680a0d751ebd7484439279497cf85b41d5f5d7d4bd5535462ec83a19f6e1865b228fe263feecf7c5371721
7
+ data.tar.gz: aeda53957dc63572db12b6602f28b0441f764fc4ffe91552262723e329353347dccffa09f1be45f174ed8dcd8e20be6c25fe145fda6084124876c445e656e12a
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.3.1
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mk_sunmoon.gemspec
4
+ gemspec
5
+
6
+ group :development do
7
+ gem "guard"
8
+ gem "guard-rspec", "~> 4.7.0"
9
+ end
10
+
data/Guardfile ADDED
@@ -0,0 +1,42 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separately)
25
+ # * 'just' rspec: 'rspec'
26
+
27
+ guard :rspec, cmd: "bundle exec rspec" do
28
+ require "guard/rspec/dsl"
29
+ dsl = Guard::RSpec::Dsl.new(self)
30
+
31
+ # Feel free to open issues for suggestions and improvements
32
+
33
+ # RSpec files
34
+ rspec = dsl.rspec
35
+ watch(rspec.spec_helper) { rspec.spec_dir }
36
+ watch(rspec.spec_support) { rspec.spec_dir }
37
+ watch(rspec.spec_files)
38
+
39
+ # Ruby files
40
+ ruby = dsl.ruby
41
+ dsl.watch_spec_files_for(ruby.lib_files)
42
+ end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Masaru Koizumi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # MkSunmoon
2
+
3
+ ## Introduction
4
+
5
+ This is the gem library which calculates rise/set/meridian_passage of Sun and Moon.(Timezone: JST)
6
+
7
+ ### Computable items
8
+
9
+ Sunrise(time, azimath), Sunset(time, azimath), Sun's meridian passage(time, altitude),
10
+ Moorise(time, azimath), Moonset(time, azimath), Moon's meridian passage(time, altitude),
11
+
12
+ ### Original Text
13
+
14
+ 「日の出・日の入りの計算―天体の出没時刻の求め方」(長沢 工 著)
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ ```ruby
21
+ gem 'mk_sunmoon'
22
+ ```
23
+
24
+ And then execute:
25
+
26
+ $ bundle
27
+
28
+ Or install it yourself as:
29
+
30
+ $ gem install mk_sunmoon
31
+
32
+ ## Usage
33
+
34
+ ``` ruby
35
+ require 'mk_sunmoon'
36
+
37
+ o = MkSunmoon.new("20160613", 35.47222222, 133.05055556, 0)
38
+ exit unless o
39
+
40
+ p o.sunrise # => ["04:51:52", 60.3625538738466]
41
+ p o.sunset # => ["19:23:59", 299.679632987787]
42
+ p o.sun_mp # => ["12:07:52", 77.75865299128155]
43
+ p o.moonrise # => ["12:48:14", 89.56165470119508]
44
+ p o.moonset # => ["00:32:24", 272.8282647107956]
45
+ p o.moon_mp # => ["18:58:52", 54.1049869601976]
46
+ ```
47
+
48
+ ## Development
49
+
50
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec mk_sunmoon` to use the gem in this directory, ignoring other installed copies of this gem.
51
+
52
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
53
+
54
+ ## Contributing
55
+
56
+ Bug reports and pull requests are welcome on GitHub at https://github.com/komasaru/mk_sunmoon.
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
62
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "mk_sunmoon"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
data/exe/mk_sunmoon ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "mk_sunmoon"
4
+
5
+ o = MkSunmoon.new(*ARGV)
6
+ exit unless o
7
+
8
+ p o.year, o.month, o.day
9
+ p o.lat, o.lon, o.alt
10
+ p o.sunrise
11
+ p o.sunset
12
+ p o.sun_mp
13
+ p o.moonrise
14
+ p o.moonset
15
+ p o.moon_mp
16
+
@@ -0,0 +1,72 @@
1
+ require "date"
2
+
3
+ module MkSunmoon
4
+ class Argument
5
+ def initialize(*args)
6
+ @date, @lat, @lon, @alt = args
7
+ end
8
+
9
+ #=========================================================================
10
+ # 引数取得
11
+ #
12
+ # * コマンドライン引数を取得して日時の妥当性チェックを行う
13
+ # コマンドライン引数無指定なら、現在日とする。
14
+ # * -90.0 < 緯度 < 90.0
15
+ # * -180.0 < 経度 < 180.0
16
+ # * 0.0 < 標高 < 10000.0
17
+ #
18
+ # @return: [year, month, day, lat, lon, alt] (when error, [])
19
+ #=========================================================================
20
+ def get_args
21
+ date = get_date; return [] unless date
22
+ lat = get_latitude; return [] unless lat
23
+ lon = get_longitude; return [] unless lon
24
+ alt = get_altitude; return [] unless alt
25
+ return [*date, lat, lon, alt]
26
+ end
27
+
28
+ private
29
+
30
+ def get_date
31
+ @date ||= Time.now.strftime("%Y%m%d")
32
+ unless @date =~ /^\d{8}$/
33
+ puts Const::MSG_ERR_1
34
+ return nil
35
+ end
36
+ year, month, day = @date[0,4].to_i, @date[4,2].to_i, @date[6,2].to_i
37
+ unless Date.valid_date?(year, month, day)
38
+ puts Const::MSG_ERR_1
39
+ return nil
40
+ end
41
+ return [year, month, day]
42
+ end
43
+
44
+ def get_latitude
45
+ @lat ||= Const::LAT_MATSUE
46
+ unless @lat.to_s =~ /^[+-]?[0-8]?\d?(\.\d*)?$/
47
+ puts Const::MSG_ERR_2
48
+ return nil
49
+ end
50
+ return @lat.to_f
51
+ end
52
+
53
+ def get_longitude
54
+ @lon ||= Const::LON_MATSUE
55
+ unless @lon.to_s =~ /^[+-]?(\d{,2}|1[0-7]\d?)(\.\d*)?$/
56
+ puts Const::MSG_ERR_3
57
+ return nil
58
+ end
59
+ return @lon.to_f
60
+ end
61
+
62
+ def get_altitude
63
+ @alt ||= 0.0
64
+ unless @alt.to_s =~ /^\d{,4}(\.\d*)?$/
65
+ puts Const::MSG_ERR_4
66
+ return nil
67
+ end
68
+ return @alt.to_f
69
+ end
70
+ end
71
+ end
72
+
@@ -0,0 +1,775 @@
1
+ module MkSunmoon
2
+ module Compute
3
+ module_function
4
+
5
+ #=========================================================================
6
+ # Gregorian Calendar -> Julian Day
7
+ #
8
+ # * フリーゲルの公式を使用する
9
+ # [ JD ] = int( 365.25 × year )
10
+ # + int( year / 400 )
11
+ # - int( year / 100 )
12
+ # + int( 30.59 ( month - 2 ) )
13
+ # + day
14
+ # + 1721088
15
+ # ※上記の int( x ) は厳密には、x を超えない最大の整数
16
+ # ( ちなみに、[ 準JD ]を求めるなら + 1721088.5 が - 678912 となる )
17
+ #
18
+ # @param: year
19
+ # @param: month
20
+ # @param: day
21
+ # @param: hour
22
+ # @param: minute
23
+ # @param: second
24
+ # @return: jd ( ユリウス日 )
25
+ #=========================================================================
26
+ def gc2jd(year, month, day, hour = 0, min = 0, sec = 0)
27
+ # 1月,2月は前年の13月,14月とする
28
+ if month < 3
29
+ year -= 1
30
+ month += 12
31
+ end
32
+ # 日付(整数)部分計算
33
+ jd = (365.25 * year).truncate
34
+ jd += (year / 400.0).truncate
35
+ jd -= (year / 100.0).truncate
36
+ jd += (30.59 * (month - 2)).truncate
37
+ jd += day
38
+ jd += 1721088.125
39
+ # 時間(小数)部分計算
40
+ t = sec / 3600.0
41
+ t += min / 60.0
42
+ t += hour
43
+ t = t / 24.0
44
+ return jd + t
45
+ end
46
+
47
+ #=========================================================================
48
+ # ΔT の計算
49
+ #
50
+ # * 1972-01-01 以降、うるう秒挿入済みの年+αまでは、以下で算出
51
+ # TT - UTC = ΔT + DUT1 = TAI + 32.184 - UTC = ΔAT + 32.184
52
+ # [うるう秒実施日一覧](http://jjy.nict.go.jp/QandA/data/leapsec.html)
53
+ #
54
+ # @param: year
55
+ # @param: month
56
+ # @param: day
57
+ # @return: dt
58
+ #=========================================================================
59
+ def compute_dt(year, month, day)
60
+ ymd = sprintf("%04d-%02d-%02d", year, month, day)
61
+ case
62
+ when year < -500
63
+ t = (year-1820) / 100.0
64
+ dt = -20 + 32 * t ** 2
65
+ when -500 <= year && year < 500
66
+ t = year / 100.0
67
+ dt = 10583.6
68
+ (-1014.41 + \
69
+ ( 33.78311 + \
70
+ ( -5.952053 + \
71
+ ( -0.1798452 + \
72
+ ( 0.022174192 + \
73
+ ( 0.0090316521) \
74
+ * t) * t) * t) * t) * t) * t
75
+ when 500 <= year && year < 1600
76
+ t = (year - 1000) / 100.0
77
+ dt = 1574.2 + \
78
+ (-556.01 + \
79
+ ( 71.23472 + \
80
+ ( 0.319781 + \
81
+ ( -0.8503463 + \
82
+ ( -0.005050998 + \
83
+ ( 0.0083572073) \
84
+ * t) * t) * t) * t) * t) * t
85
+ when 1600 <= year && year < 1700
86
+ t = year - 1600
87
+ dt = 120 + \
88
+ ( -0.9808 + \
89
+ ( -0.01532 + \
90
+ ( 1.0 / 7129.0) \
91
+ * t) * t) * t
92
+ when 1700 <= year && year < 1800
93
+ t = year - 1700
94
+ dt = 8.83 + \
95
+ ( 0.1603 + \
96
+ (-0.0059285 + \
97
+ ( 0.00013336 + \
98
+ (-1.0 / 1174000.0) \
99
+ * t) * t) * t) * t
100
+ when 1800 <= year && year < 1860
101
+ t = year - 1800
102
+ dt = 13.72 + \
103
+ (-0.332447 + \
104
+ ( 0.0068612 + \
105
+ ( 0.0041116 + \
106
+ (-0.00037436 + \
107
+ ( 0.0000121272 + \
108
+ (-0.0000001699 + \
109
+ ( 0.000000000875) \
110
+ * t) * t) * t) * t) * t) * t) * t
111
+ when 1860 <= year && year < 1900
112
+ t = year - 1860
113
+ dt = 7.62 + \
114
+ ( 0.5737 + \
115
+ (-0.251754 + \
116
+ ( 0.01680668 + \
117
+ (-0.0004473624 + \
118
+ ( 1.0 / 233174.0) \
119
+ * t) * t) * t) * t) * t
120
+ when 1900 <= year && year < 1920
121
+ t = year - 1900
122
+ dt = -2.79 + \
123
+ ( 1.494119 + \
124
+ (-0.0598939 + \
125
+ ( 0.0061966 + \
126
+ (-0.000197 ) \
127
+ * t) * t) * t) * t
128
+ when 1920 <= year && year < 1941
129
+ t = year - 1920
130
+ dt = 21.20 + \
131
+ ( 0.84493 + \
132
+ (-0.076100 + \
133
+ ( 0.0020936) \
134
+ * t) * t) * t
135
+ when 1941 <= year && year < 1961
136
+ t = year - 1950
137
+ dt = 29.07 + \
138
+ ( 0.407 + \
139
+ (-1 / 233.0 + \
140
+ ( 1 / 2547.0) \
141
+ * t) * t) * t
142
+ when 1961 <= year && year < 1986
143
+ case
144
+ when ymd < sprintf("%04d-%02d-%02d", 1972, 1, 1)
145
+ t = year - 1975
146
+ dt = 45.45 + \
147
+ ( 1.067 + \
148
+ (-1 / 260.0 + \
149
+ (-1 / 718.0) \
150
+ * t) * t) * t
151
+ when ymd < sprintf("%04d-%02d-%02d", 1972, 7, 1)
152
+ dt = 32.184 + 10
153
+ when ymd < sprintf("%04d-%02d-%02d", 1973, 1, 1)
154
+ dt = 32.184 + 11
155
+ when ymd < sprintf("%04d-%02d-%02d", 1974, 1, 1)
156
+ dt = 32.184 + 12
157
+ when ymd < sprintf("%04d-%02d-%02d", 1975, 1, 1)
158
+ dt = 32.184 + 13
159
+ when ymd < sprintf("%04d-%02d-%02d", 1976, 1, 1)
160
+ dt = 32.184 + 14
161
+ when ymd < sprintf("%04d-%02d-%02d", 1977, 1, 1)
162
+ dt = 32.184 + 15
163
+ when ymd < sprintf("%04d-%02d-%02d", 1978, 1, 1)
164
+ dt = 32.184 + 16
165
+ when ymd < sprintf("%04d-%02d-%02d", 1979, 1, 1)
166
+ dt = 32.184 + 17
167
+ when ymd < sprintf("%04d-%02d-%02d", 1980, 1, 1)
168
+ dt = 32.184 + 18
169
+ when ymd < sprintf("%04d-%02d-%02d", 1981, 7, 1)
170
+ dt = 32.184 + 19
171
+ when ymd < sprintf("%04d-%02d-%02d", 1982, 7, 1)
172
+ dt = 32.184 + 20
173
+ when ymd < sprintf("%04d-%02d-%02d", 1983, 7, 1)
174
+ dt = 32.184 + 21
175
+ when ymd < sprintf("%04d-%02d-%02d", 1985, 7, 1)
176
+ dt = 32.184 + 22
177
+ when ymd < sprintf("%04d-%02d-%02d", 1988, 1, 1)
178
+ dt = 32.184 + 23
179
+ end
180
+ when 1986 <= year && year < 2005
181
+ # t = year - 2000
182
+ #dt = 63.86 + \
183
+ # ( 0.3345 + \
184
+ # (-0.060374 + \
185
+ # ( 0.0017275 + \
186
+ # ( 0.000651814 + \
187
+ # ( 0.00002373599) \
188
+ # * t) * t) * t) * t) * t
189
+ case
190
+ when ymd < sprintf("%04d-%02d-%02d", 1988, 1, 1)
191
+ dt = 32.184 + 23
192
+ when ymd < sprintf("%04d-%02d-%02d", 1990, 1, 1)
193
+ dt = 32.184 + 24
194
+ when ymd < sprintf("%04d-%02d-%02d", 1991, 1, 1)
195
+ dt = 32.184 + 25
196
+ when ymd < sprintf("%04d-%02d-%02d", 1992, 7, 1)
197
+ dt = 32.184 + 26
198
+ when ymd < sprintf("%04d-%02d-%02d", 1993, 7, 1)
199
+ dt = 32.184 + 27
200
+ when ymd < sprintf("%04d-%02d-%02d", 1994, 7, 1)
201
+ dt = 32.184 + 28
202
+ when ymd < sprintf("%04d-%02d-%02d", 1996, 1, 1)
203
+ dt = 32.184 + 29
204
+ when ymd < sprintf("%04d-%02d-%02d", 1997, 7, 1)
205
+ dt = 32.184 + 30
206
+ when ymd < sprintf("%04d-%02d-%02d", 1999, 1, 1)
207
+ dt = 32.184 + 31
208
+ when ymd < sprintf("%04d-%02d-%02d", 2006, 1, 1)
209
+ dt = 32.184 + 32
210
+ end
211
+ when 2005 <= year && year < 2050
212
+ case
213
+ when ymd < sprintf("%04d-%02d-%02d", 2006, 1, 1)
214
+ dt = 32.184 + 32
215
+ when ymd < sprintf("%04d-%02d-%02d", 2009, 1, 1)
216
+ dt = 32.184 + 33
217
+ when ymd < sprintf("%04d-%02d-%02d", 2012, 7, 1)
218
+ dt = 32.184 + 34
219
+ when ymd < sprintf("%04d-%02d-%02d", 2015, 7, 1)
220
+ dt = 32.184 + 35
221
+ when ymd < sprintf("%04d-%02d-%02d", 2017, 7, 1) # <= 第27回うるう秒実施までの暫定措置
222
+ dt = 32.184 + 36
223
+ else
224
+ t = year - 2000
225
+ dt = 62.92 + \
226
+ ( 0.32217 + \
227
+ ( 0.005589) \
228
+ * t) * t
229
+ end
230
+ when 2050 <= year && year <= 2150
231
+ dt = -20 \
232
+ + 32 * ((year - 1820) / 100.0) ** 2
233
+ - 0.5628 * (2150 - year)
234
+ when 2150 < year
235
+ t = (year - 1820) / 100.0
236
+ dt = -20 + 32 * t ** 2
237
+ end
238
+ return dt
239
+ end
240
+
241
+ #=========================================================================
242
+ # 日の出・入・南中の計算
243
+ #
244
+ # @param: div(0: 出, 1: 入, 2: 南中)
245
+ # @return: [time_str, hour_angle]
246
+ #=========================================================================
247
+ def compute_sun(div)
248
+ time_val = compute_time_sun(div)
249
+ time_str = val2hhmmss(time_val * 24.0)
250
+ jy = (@jd + time_val + @dt / 86400.0 - 2451545.0) / 365.25
251
+ lambda = compute_lambda_sun(jy)
252
+ if div == 2
253
+ angle = compute_height_ecliptic(jy, time_val, lambda, 0.0)
254
+ else
255
+ angle = compute_angle_ecliptic(jy, time_val, lambda, 0.0)
256
+ end
257
+ return [time_str, angle]
258
+ end
259
+
260
+ #=========================================================================
261
+ # 月の出・入・南中の計算
262
+ #
263
+ # @param: div(0: 出, 1: 入, 2: 南中)
264
+ # @return: [time_str, hour_angle]
265
+ #=========================================================================
266
+ def compute_moon(div)
267
+ time_val = compute_time_moon(div)
268
+ if time_val == 0.0
269
+ time_str = "--:--:--"
270
+ angle = "---"
271
+ else
272
+ time_str = val2hhmmss(time_val * 24.0)
273
+ jy = (@jd + time_val + @dt / 86400.0 - 2451545.0) / 365.25
274
+ lambda = compute_lambda_moon(jy)
275
+ beta = compute_beta_moon(jy)
276
+ if div == 2
277
+ angle = compute_height_ecliptic(jy, time_val, lambda, beta)
278
+ else
279
+ angle = compute_angle_ecliptic(jy, time_val, lambda, beta)
280
+ end
281
+ end
282
+ return [time_str, angle]
283
+ end
284
+
285
+ #=========================================================================
286
+ # 日の出/日の入/日の南中計算計算
287
+ #
288
+ # @param: div (0: 出, 1: 入, 2: 南中)
289
+ # @return: time (0.xxxx日)
290
+ #=========================================================================
291
+ def compute_time_sun(div)
292
+ rev = 1 # 補正値初期値
293
+ t = 0.5 # 逐次計算時刻(日)初期設定
294
+
295
+ while rev.abs > Const::CONVERGE
296
+ jy = (@jd + t + @dt / 86400.0 - 2451545.0) / 365.25
297
+ lambda = compute_lambda_sun(jy)
298
+ dist = compute_dist_sun(jy)
299
+ alpha, delta = eclip2equat(jy, lambda, 0.0)
300
+ r = 0.266994 / dist
301
+ diff = 0.0024428 / dist
302
+ height = -1 * r - Const::REFRACTION - @incl + diff
303
+ time_sidereal = compute_sidereal_time(jy, t)
304
+ hour_angle_diff = compute_hour_angle_diff(
305
+ alpha, delta, time_sidereal, height, div
306
+ )
307
+ # 仮定時刻に対する補正値
308
+ rev = hour_angle_diff / 360.0
309
+ t += rev
310
+ end
311
+ return t
312
+ end
313
+
314
+ #=========================================================================
315
+ # 月の出/月の入/月の南中計算計算
316
+ #
317
+ # @param: div (0: 出, 1: 入, 2: 南中)
318
+ # @return: time (0.xxxx日)
319
+ #=========================================================================
320
+ def compute_time_moon(div)
321
+ rev = 1 # 補正値初期値
322
+ t = 0.5 # 逐次計算時刻(日)初期設定
323
+
324
+ while rev.abs > Const::CONVERGE
325
+ jy = (@jd + t + @dt / 86400.0 - 2451545.0) / 365.25
326
+ lambda = compute_lambda_moon(jy)
327
+ beta = compute_beta_moon(jy)
328
+ alpha, delta = eclip2equat(jy, lambda, beta)
329
+ unless div == 2 # 南中のときは計算しない
330
+ diff = compute_diff_moon(jy)
331
+ height = -1 * Const::REFRACTION - @incl + diff
332
+ end
333
+ time_sidereal = compute_sidereal_time(jy, t)
334
+ hour_angle_diff = compute_hour_angle_diff(
335
+ alpha, delta, time_sidereal, height, div
336
+ )
337
+ # 仮定時刻に対する補正値
338
+ rev = hour_angle_diff / 347.8
339
+ t += rev
340
+ end
341
+ # 月の出/月の入りがない場合は 0 とする
342
+ t = 0 if t < 0 || t >= 1
343
+ return t
344
+ end
345
+
346
+ #=========================================================================
347
+ # 太陽視黄経の計算
348
+ #
349
+ # @param: jy (ユリウス年(JST))
350
+ # @return: lambda
351
+ #=========================================================================
352
+ def compute_lambda_sun(jy)
353
+ rm = 0.0003 * Math.sin(Const::K * norm_angle(329.7 + 44.43 * jy))
354
+ rm += 0.0003 * Math.sin(Const::K * norm_angle(352.5 + 1079.97 * jy))
355
+ rm += 0.0004 * Math.sin(Const::K * norm_angle( 21.1 + 720.02 * jy))
356
+ rm += 0.0004 * Math.sin(Const::K * norm_angle(157.3 + 299.30 * jy))
357
+ rm += 0.0004 * Math.sin(Const::K * norm_angle(234.9 + 315.56 * jy))
358
+ rm += 0.0005 * Math.sin(Const::K * norm_angle(291.2 + 22.81 * jy))
359
+ rm += 0.0005 * Math.sin(Const::K * norm_angle(207.4 + 1.50 * jy))
360
+ rm += 0.0006 * Math.sin(Const::K * norm_angle( 29.8 + 337.18 * jy))
361
+ rm += 0.0007 * Math.sin(Const::K * norm_angle(206.8 + 30.35 * jy))
362
+ rm += 0.0007 * Math.sin(Const::K * norm_angle(153.3 + 90.38 * jy))
363
+ rm += 0.0008 * Math.sin(Const::K * norm_angle(132.5 + 659.29 * jy))
364
+ rm += 0.0013 * Math.sin(Const::K * norm_angle( 81.4 + 225.18 * jy))
365
+ rm += 0.0015 * Math.sin(Const::K * norm_angle(343.2 + 450.37 * jy))
366
+ rm += 0.0018 * Math.sin(Const::K * norm_angle(251.3 + 0.20 * jy))
367
+ rm += 0.0018 * Math.sin(Const::K * norm_angle(297.8 + 4452.67 * jy))
368
+ rm += 0.0020 * Math.sin(Const::K * norm_angle(247.1 + 329.64 * jy))
369
+ rm += 0.0048 * Math.sin(Const::K * norm_angle(234.95 + 19.341 * jy))
370
+ rm += 0.0200 * Math.sin(Const::K * norm_angle(355.05 + 719.981 * jy))
371
+ rm += (1.9146 - 0.00005 * jy) * Math.sin(Const::K * norm_angle(357.538 + 359.991 * jy))
372
+ rm += norm_angle(280.4603 + 360.00769 * jy)
373
+ return norm_angle(rm)
374
+ end
375
+
376
+ #=========================================================================
377
+ # 太陽の距離の計算
378
+ #
379
+ # @param: jy (ユリウス年(JST))
380
+ # @return: distance
381
+ #=========================================================================
382
+ def compute_dist_sun(jy)
383
+ r_sun = 0.000007 * Math.sin(Const::PI_180 * norm_angle(156.0 + 329.6 * jy))
384
+ r_sun += 0.000007 * Math.sin(Const::PI_180 * norm_angle(254.0 + 450.4 * jy))
385
+ r_sun += 0.000013 * Math.sin(Const::PI_180 * norm_angle( 27.8 + 4452.67 * jy))
386
+ r_sun += 0.000030 * Math.sin(Const::PI_180 * norm_angle( 90.0))
387
+ r_sun += 0.000091 * Math.sin(Const::PI_180 * norm_angle(265.1 + 719.98 * jy))
388
+ r_sun += (0.007256 - 0.0000002 * jy) * Math.sin(Const::PI_180 * norm_angle(267.54 + 359.991 * jy))
389
+ r_sun = 10.0 ** r_sun
390
+ return r_sun
391
+ end
392
+
393
+ #=========================================================================
394
+ # 月視黄経の計算
395
+ #
396
+ # @param: jy (ユリウス年(JST))
397
+ # @return: lambda
398
+ #=========================================================================
399
+ def compute_lambda_moon(jy)
400
+ am = 0.0006 * Math.sin(Const::PI_180 * norm_angle( 54.0 + 19.3 * jy))
401
+ am += 0.0006 * Math.sin(Const::PI_180 * norm_angle( 71.0 + 0.2 * jy))
402
+ am += 0.0020 * Math.sin(Const::PI_180 * norm_angle( 55.0 + 19.34 * jy))
403
+ am += 0.0040 * Math.sin(Const::PI_180 * norm_angle(119.5 + 1.33 * jy))
404
+ rm = 0.0003 * Math.sin(Const::PI_180 * norm_angle(280.0 + 23221.3 * jy))
405
+ rm += 0.0003 * Math.sin(Const::PI_180 * norm_angle(161.0 + 40.7 * jy))
406
+ rm += 0.0003 * Math.sin(Const::PI_180 * norm_angle(311.0 + 5492.0 * jy))
407
+ rm += 0.0003 * Math.sin(Const::PI_180 * norm_angle(147.0 + 18089.3 * jy))
408
+ rm += 0.0003 * Math.sin(Const::PI_180 * norm_angle( 66.0 + 3494.7 * jy))
409
+ rm += 0.0003 * Math.sin(Const::PI_180 * norm_angle( 83.0 + 3814.0 * jy))
410
+ rm += 0.0004 * Math.sin(Const::PI_180 * norm_angle( 20.0 + 720.0 * jy))
411
+ rm += 0.0004 * Math.sin(Const::PI_180 * norm_angle( 71.0 + 9584.7 * jy))
412
+ rm += 0.0004 * Math.sin(Const::PI_180 * norm_angle(278.0 + 120.1 * jy))
413
+ rm += 0.0004 * Math.sin(Const::PI_180 * norm_angle(313.0 + 398.7 * jy))
414
+ rm += 0.0005 * Math.sin(Const::PI_180 * norm_angle(332.0 + 5091.3 * jy))
415
+ rm += 0.0005 * Math.sin(Const::PI_180 * norm_angle(114.0 + 17450.7 * jy))
416
+ rm += 0.0005 * Math.sin(Const::PI_180 * norm_angle(181.0 + 19088.0 * jy))
417
+ rm += 0.0005 * Math.sin(Const::PI_180 * norm_angle(247.0 + 22582.7 * jy))
418
+ rm += 0.0006 * Math.sin(Const::PI_180 * norm_angle(128.0 + 1118.7 * jy))
419
+ rm += 0.0007 * Math.sin(Const::PI_180 * norm_angle(216.0 + 278.6 * jy))
420
+ rm += 0.0007 * Math.sin(Const::PI_180 * norm_angle(275.0 + 4853.3 * jy))
421
+ rm += 0.0007 * Math.sin(Const::PI_180 * norm_angle(140.0 + 4052.0 * jy))
422
+ rm += 0.0008 * Math.sin(Const::PI_180 * norm_angle(204.0 + 7906.7 * jy))
423
+ rm += 0.0008 * Math.sin(Const::PI_180 * norm_angle(188.0 + 14037.3 * jy))
424
+ rm += 0.0009 * Math.sin(Const::PI_180 * norm_angle(218.0 + 8586.0 * jy))
425
+ rm += 0.0011 * Math.sin(Const::PI_180 * norm_angle(276.5 + 19208.02 * jy))
426
+ rm += 0.0012 * Math.sin(Const::PI_180 * norm_angle(339.0 + 12678.71 * jy))
427
+ rm += 0.0016 * Math.sin(Const::PI_180 * norm_angle(242.2 + 18569.38 * jy))
428
+ rm += 0.0018 * Math.sin(Const::PI_180 * norm_angle( 4.1 + 4013.29 * jy))
429
+ rm += 0.0020 * Math.sin(Const::PI_180 * norm_angle( 55.0 + 19.34 * jy))
430
+ rm += 0.0021 * Math.sin(Const::PI_180 * norm_angle(105.6 + 3413.37 * jy))
431
+ rm += 0.0021 * Math.sin(Const::PI_180 * norm_angle(175.1 + 719.98 * jy))
432
+ rm += 0.0021 * Math.sin(Const::PI_180 * norm_angle( 87.5 + 9903.97 * jy))
433
+ rm += 0.0022 * Math.sin(Const::PI_180 * norm_angle(240.6 + 8185.36 * jy))
434
+ rm += 0.0024 * Math.sin(Const::PI_180 * norm_angle(252.8 + 9224.66 * jy))
435
+ rm += 0.0024 * Math.sin(Const::PI_180 * norm_angle(211.9 + 988.63 * jy))
436
+ rm += 0.0026 * Math.sin(Const::PI_180 * norm_angle(107.2 + 13797.39 * jy))
437
+ rm += 0.0027 * Math.sin(Const::PI_180 * norm_angle(272.5 + 9183.99 * jy))
438
+ rm += 0.0037 * Math.sin(Const::PI_180 * norm_angle(349.1 + 5410.62 * jy))
439
+ rm += 0.0039 * Math.sin(Const::PI_180 * norm_angle(111.3 + 17810.68 * jy))
440
+ rm += 0.0040 * Math.sin(Const::PI_180 * norm_angle(119.5 + 1.33 * jy))
441
+ rm += 0.0040 * Math.sin(Const::PI_180 * norm_angle(145.6 + 18449.32 * jy))
442
+ rm += 0.0040 * Math.sin(Const::PI_180 * norm_angle( 13.2 + 13317.34 * jy))
443
+ rm += 0.0048 * Math.sin(Const::PI_180 * norm_angle(235.0 + 19.34 * jy))
444
+ rm += 0.0050 * Math.sin(Const::PI_180 * norm_angle(295.4 + 4812.66 * jy))
445
+ rm += 0.0052 * Math.sin(Const::PI_180 * norm_angle(197.2 + 319.32 * jy))
446
+ rm += 0.0068 * Math.sin(Const::PI_180 * norm_angle( 53.2 + 9265.33 * jy))
447
+ rm += 0.0079 * Math.sin(Const::PI_180 * norm_angle(278.2 + 4493.34 * jy))
448
+ rm += 0.0085 * Math.sin(Const::PI_180 * norm_angle(201.5 + 8266.71 * jy))
449
+ rm += 0.0100 * Math.sin(Const::PI_180 * norm_angle( 44.89 + 14315.966 * jy))
450
+ rm += 0.0107 * Math.sin(Const::PI_180 * norm_angle(336.44 + 13038.696 * jy))
451
+ rm += 0.0110 * Math.sin(Const::PI_180 * norm_angle(231.59 + 4892.052 * jy))
452
+ rm += 0.0125 * Math.sin(Const::PI_180 * norm_angle(141.51 + 14436.029 * jy))
453
+ rm += 0.0153 * Math.sin(Const::PI_180 * norm_angle(130.84 + 758.698 * jy))
454
+ rm += 0.0305 * Math.sin(Const::PI_180 * norm_angle(312.49 + 5131.979 * jy))
455
+ rm += 0.0348 * Math.sin(Const::PI_180 * norm_angle(117.84 + 4452.671 * jy))
456
+ rm += 0.0410 * Math.sin(Const::PI_180 * norm_angle(137.43 + 4411.998 * jy))
457
+ rm += 0.0459 * Math.sin(Const::PI_180 * norm_angle(238.18 + 8545.352 * jy))
458
+ rm += 0.0533 * Math.sin(Const::PI_180 * norm_angle( 10.66 + 13677.331 * jy))
459
+ rm += 0.0572 * Math.sin(Const::PI_180 * norm_angle(103.21 + 3773.363 * jy))
460
+ rm += 0.0588 * Math.sin(Const::PI_180 * norm_angle(214.22 + 638.635 * jy))
461
+ rm += 0.1143 * Math.sin(Const::PI_180 * norm_angle( 6.546 + 9664.0404 * jy))
462
+ rm += 0.1856 * Math.sin(Const::PI_180 * norm_angle(177.525 + 359.9905 * jy))
463
+ rm += 0.2136 * Math.sin(Const::PI_180 * norm_angle(269.926 + 9543.9773 * jy))
464
+ rm += 0.6583 * Math.sin(Const::PI_180 * norm_angle(235.700 + 8905.3422 * jy))
465
+ rm += 1.2740 * Math.sin(Const::PI_180 * norm_angle(100.738 + 4133.3536 * jy))
466
+ rm += 6.2887 * Math.sin(Const::PI_180 * norm_angle(134.961 + 4771.9886 * jy + am))
467
+ rm += norm_angle(218.3161 + 4812.67881 * jy)
468
+ return rm
469
+ end
470
+
471
+ #=========================================================================
472
+ # 月視黄緯の計算
473
+ #
474
+ # @param: jy (ユリウス年(JST))
475
+ # @return: lambda
476
+ #=========================================================================
477
+ def compute_beta_moon(jy)
478
+ bm = 0.0005 * Math.sin(Const::PI_180 * norm_angle(307.0 + 19.4 * jy))
479
+ bm += 0.0026 * Math.sin(Const::PI_180 * norm_angle( 55.0 + 19.34 * jy))
480
+ bm += 0.0040 * Math.sin(Const::PI_180 * norm_angle(119.5 + 1.33 * jy))
481
+ bm += 0.0043 * Math.sin(Const::PI_180 * norm_angle(322.1 + 19.36 * jy))
482
+ bm += 0.0267 * Math.sin(Const::PI_180 * norm_angle(234.95 + 19.341 * jy))
483
+ bt = 0.0003 * Math.sin(Const::PI_180 * norm_angle(234.0 + 19268.0 * jy))
484
+ bt += 0.0003 * Math.sin(Const::PI_180 * norm_angle(146.0 + 3353.3 * jy))
485
+ bt += 0.0003 * Math.sin(Const::PI_180 * norm_angle(107.0 + 18149.4 * jy))
486
+ bt += 0.0003 * Math.sin(Const::PI_180 * norm_angle(205.0 + 22642.7 * jy))
487
+ bt += 0.0004 * Math.sin(Const::PI_180 * norm_angle(147.0 + 14097.4 * jy))
488
+ bt += 0.0004 * Math.sin(Const::PI_180 * norm_angle( 13.0 + 9325.4 * jy))
489
+ bt += 0.0004 * Math.sin(Const::PI_180 * norm_angle( 81.0 + 10242.6 * jy))
490
+ bt += 0.0004 * Math.sin(Const::PI_180 * norm_angle(238.0 + 23281.3 * jy))
491
+ bt += 0.0004 * Math.sin(Const::PI_180 * norm_angle(311.0 + 9483.9 * jy))
492
+ bt += 0.0005 * Math.sin(Const::PI_180 * norm_angle(239.0 + 4193.4 * jy))
493
+ bt += 0.0005 * Math.sin(Const::PI_180 * norm_angle(280.0 + 8485.3 * jy))
494
+ bt += 0.0006 * Math.sin(Const::PI_180 * norm_angle( 52.0 + 13617.3 * jy))
495
+ bt += 0.0006 * Math.sin(Const::PI_180 * norm_angle(224.0 + 5590.7 * jy))
496
+ bt += 0.0007 * Math.sin(Const::PI_180 * norm_angle(294.0 + 13098.7 * jy))
497
+ bt += 0.0008 * Math.sin(Const::PI_180 * norm_angle(326.0 + 9724.1 * jy))
498
+ bt += 0.0008 * Math.sin(Const::PI_180 * norm_angle( 70.0 + 17870.7 * jy))
499
+ bt += 0.0010 * Math.sin(Const::PI_180 * norm_angle( 18.0 + 12978.66 * jy))
500
+ bt += 0.0011 * Math.sin(Const::PI_180 * norm_angle(138.3 + 19147.99 * jy))
501
+ bt += 0.0012 * Math.sin(Const::PI_180 * norm_angle(148.2 + 4851.36 * jy))
502
+ bt += 0.0012 * Math.sin(Const::PI_180 * norm_angle( 38.4 + 4812.68 * jy))
503
+ bt += 0.0013 * Math.sin(Const::PI_180 * norm_angle(155.4 + 379.35 * jy))
504
+ bt += 0.0013 * Math.sin(Const::PI_180 * norm_angle( 95.8 + 4472.03 * jy))
505
+ bt += 0.0014 * Math.sin(Const::PI_180 * norm_angle(219.2 + 299.96 * jy))
506
+ bt += 0.0015 * Math.sin(Const::PI_180 * norm_angle( 45.8 + 9964.00 * jy))
507
+ bt += 0.0015 * Math.sin(Const::PI_180 * norm_angle(211.1 + 9284.69 * jy))
508
+ bt += 0.0016 * Math.sin(Const::PI_180 * norm_angle(135.7 + 420.02 * jy))
509
+ bt += 0.0017 * Math.sin(Const::PI_180 * norm_angle( 99.8 + 14496.06 * jy))
510
+ bt += 0.0018 * Math.sin(Const::PI_180 * norm_angle(270.8 + 5192.01 * jy))
511
+ bt += 0.0018 * Math.sin(Const::PI_180 * norm_angle(243.3 + 8206.68 * jy))
512
+ bt += 0.0019 * Math.sin(Const::PI_180 * norm_angle(230.7 + 9244.02 * jy))
513
+ bt += 0.0021 * Math.sin(Const::PI_180 * norm_angle(170.1 + 1058.66 * jy))
514
+ bt += 0.0022 * Math.sin(Const::PI_180 * norm_angle(331.4 + 13377.37 * jy))
515
+ bt += 0.0025 * Math.sin(Const::PI_180 * norm_angle(196.5 + 8605.38 * jy))
516
+ bt += 0.0034 * Math.sin(Const::PI_180 * norm_angle(319.9 + 4433.31 * jy))
517
+ bt += 0.0042 * Math.sin(Const::PI_180 * norm_angle(103.9 + 18509.35 * jy))
518
+ bt += 0.0043 * Math.sin(Const::PI_180 * norm_angle(307.6 + 5470.66 * jy))
519
+ bt += 0.0082 * Math.sin(Const::PI_180 * norm_angle(144.9 + 3713.33 * jy))
520
+ bt += 0.0088 * Math.sin(Const::PI_180 * norm_angle(176.7 + 4711.96 * jy))
521
+ bt += 0.0093 * Math.sin(Const::PI_180 * norm_angle(277.4 + 8845.31 * jy))
522
+ bt += 0.0172 * Math.sin(Const::PI_180 * norm_angle( 3.18 + 14375.997 * jy))
523
+ bt += 0.0326 * Math.sin(Const::PI_180 * norm_angle(328.96 + 13737.362 * jy))
524
+ bt += 0.0463 * Math.sin(Const::PI_180 * norm_angle(172.55 + 698.667 * jy))
525
+ bt += 0.0554 * Math.sin(Const::PI_180 * norm_angle(194.01 + 8965.374 * jy))
526
+ bt += 0.1732 * Math.sin(Const::PI_180 * norm_angle(142.427 + 4073.3220 * jy))
527
+ bt += 0.2777 * Math.sin(Const::PI_180 * norm_angle(138.311 + 60.0316 * jy))
528
+ bt += 0.2806 * Math.sin(Const::PI_180 * norm_angle(228.235 + 9604.0088 * jy))
529
+ bt += 5.1282 * Math.sin(Const::PI_180 * norm_angle( 93.273 + 4832.0202 * jy + bm))
530
+ return bt
531
+ end
532
+
533
+ #=========================================================================
534
+ # 月の視差の計算
535
+ #
536
+ # @param: jy (ユリウス年)
537
+ # @return: t (出入時刻(0.xxxx日))
538
+ #=========================================================================
539
+ def compute_diff_moon(jy)
540
+ t = 0.0003 * Math.sin(Const::PI_180 * norm_angle(227.0 + 4412.0 * jy))
541
+ t += 0.0004 * Math.sin(Const::PI_180 * norm_angle(194.0 + 3773.4 * jy))
542
+ t += 0.0005 * Math.sin(Const::PI_180 * norm_angle(329.0 + 8545.4 * jy))
543
+ t += 0.0009 * Math.sin(Const::PI_180 * norm_angle(100.0 + 13677.3 * jy))
544
+ t += 0.0028 * Math.sin(Const::PI_180 * norm_angle( 0.0 + 9543.98 * jy))
545
+ t += 0.0078 * Math.sin(Const::PI_180 * norm_angle(325.7 + 8905.34 * jy))
546
+ t += 0.0095 * Math.sin(Const::PI_180 * norm_angle(190.7 + 4133.35 * jy))
547
+ t += 0.0518 * Math.sin(Const::PI_180 * norm_angle(224.98 + 4771.989 * jy))
548
+ t += 0.9507 * Math.sin(Const::PI_180 * norm_angle(90.0))
549
+ return t
550
+ end
551
+
552
+ #=========================================================================
553
+ # 角度の正規化
554
+ #
555
+ # @param: angle
556
+ # @return: angle
557
+ #=========================================================================
558
+ def norm_angle(angle)
559
+ if angle < 0
560
+ angle1 = angle * (-1)
561
+ angle2 = (angle1 / 360.0).truncate
562
+ angle1 -= 360 * angle2
563
+ angle1 = 360 - angle1
564
+ else
565
+ angle1 = (angle / 360.0).truncate
566
+ angle1 = angle - 360.0 * angle1
567
+ end
568
+ return angle1
569
+ end
570
+
571
+ #=========================================================================
572
+ # 黄道座標 -> 赤道座標変換
573
+ #
574
+ # @param: jy (ユリウス年(JST))
575
+ # @param: lambda (黄経)
576
+ # @param: beta (黄緯)
577
+ # @return: [alpha(R.A.), delta(Decl.)]
578
+ #=========================================================================
579
+ def eclip2equat(jy, lambda, beta)
580
+ eps = (23.439291 - 0.000130042 * jy) * Const::PI_180
581
+ lambda *= Const::PI_180
582
+ beta *= Const::PI_180
583
+ a = Math.cos(beta) * Math.cos(lambda)
584
+ b = -1 * Math.sin(beta) * Math.sin(eps)
585
+ b += Math.cos(beta) * Math.sin(lambda) * Math.cos(eps)
586
+ c = Math.sin(beta) * Math.cos(eps)
587
+ c += Math.cos(beta) * Math.sin(lambda) * Math.sin(eps)
588
+ alpha = b / a
589
+ alpha = Math.atan(alpha) / Const::PI_180
590
+ alpha += 180 if a < 0
591
+ delta = Math.asin(c) / Const::PI_180
592
+ return [alpha, delta]
593
+ end
594
+
595
+ #=========================================================================
596
+ # 恒星時Θ(度)の計算
597
+ #
598
+ # @param: jy (ユリウス年(JST))
599
+ # @param: t (時刻(0.xxxx日))
600
+ # @param: longitude
601
+ # @return: sidereal time
602
+ #=========================================================================
603
+ def compute_sidereal_time(jy, t)
604
+ val = 325.4606 + \
605
+ (360.007700536 + \
606
+ ( 0.00000003879) \
607
+ * jy) * jy \
608
+ + 360.0 * t + @lon
609
+ return norm_angle(val)
610
+ end
611
+
612
+ #=========================================================================
613
+ # 出入点(k)の時角(tk)と天体の時角(t)との差(dt=tk-t)を計算する
614
+ #
615
+ # @param: alpha(R.A.) (赤経)
616
+ # @param: delta(Decl.) (赤緯)
617
+ # @param: time_sidereal(恒星時Θ(度))
618
+ # @param: height (出没高度(度))
619
+ # @param: kbn (0: 出, 1: 入, 2: 南中)
620
+ # @return: hour angle difference (時角の差 dt)
621
+ #=========================================================================
622
+ def compute_hour_angle_diff(alpha, delta, time_sidereal, height, kbn)
623
+ # 南中の場合は天体の時角を返す
624
+ if kbn == 2
625
+ tk = 0
626
+ else
627
+ tk = Math.sin(Const::PI_180 * height)
628
+ tk -= Math.sin(Const::PI_180 * delta) * Math.sin(Const::PI_180 * @lat)
629
+ tk /= Math.cos(Const::PI_180 * delta) * Math.cos(Const::PI_180 * @lat)
630
+ # 出没点の時角
631
+ tk = Math.acos(tk) / Const::PI_180
632
+ # tkは出のときマイナス、入のときプラス
633
+ tk = -tk if kbn == 0 && tk > 0
634
+ tk = -tk if kbn == 1 && tk < 0
635
+ end
636
+ # 天体の時角
637
+ t = time_sidereal - alpha
638
+ dt = tk - t
639
+ # dtの絶対値を180°以下に調整
640
+ if dt > 180
641
+ while dt > 180; dt -= 360; end
642
+ end
643
+ if dt < -180
644
+ while dt < -180; dt += 360; end
645
+ end
646
+ return dt
647
+ end
648
+
649
+ #=========================================================================
650
+ # 時刻:数値->時刻:時分変換 (xx.xxxx -> hh:mm:ss)
651
+ #
652
+ # @param: time value (時刻, xx.xxxx日)
653
+ # @return: time string (時刻, hh:mm:ss)
654
+ #=========================================================================
655
+ def val2hhmmss(val)
656
+ val_h = val.truncate # 整数部(時)
657
+ val_2 = val - val_h # 小数部
658
+ val_m = (val_2 * 60).truncate # (分)計算
659
+ val_3 = val_2 - (val_m / 60.0) # (秒)計算
660
+ val_s = (val_3 * 60 * 60).round
661
+ return sprintf("%02d:%02d:%02d", val_h, val_m, val_s)
662
+ end
663
+
664
+ #=========================================================================
665
+ # 時刻(t)における黄経、黄緯(λ(jy),β(jy))の天体の方位角(ang)計算
666
+ #
667
+ # @param: lambda (天体の黄経(λ(T)(度)))
668
+ # @param: beta (天体の黄緯(β(T)(度)))
669
+ # @param: jy (ユリウス年)
670
+ # @param: t (時刻(0.xxxx日))
671
+ # @return: angle (角度(xx.x度))
672
+ #=========================================================================
673
+ def compute_angle_ecliptic(jy, t, lambda, beta)
674
+ res = eclip2equat(jy, lambda, beta)
675
+ return compute_angle_equator(jy, t, *res)
676
+ end
677
+
678
+ #=========================================================================
679
+ # 時刻(t)における赤経、赤緯(α(jy),δ(jy))(度)の天体の方位角(ang)計算
680
+ #
681
+ # @param: jy (ユリウス年)
682
+ # @param: t (時刻 (0.xxxx日))
683
+ # @param: alpha (天体の赤経(α(jy)(度)))
684
+ # @param: delta (天体の赤緯(δ(jy)(度)))
685
+ # @return: angle (角度(xx.x度))
686
+ #=========================================================================
687
+ def compute_angle_equator(jy, t, alpha, delta)
688
+ time_sidereal = compute_sidereal_time(jy, t)
689
+ hour_angle = time_sidereal - alpha
690
+ a_0 = -1.0 * Math.cos(Const::PI_180 * delta) \
691
+ * Math.sin(Const::PI_180 * hour_angle)
692
+ a_1 = Math.sin(Const::PI_180 * delta) \
693
+ * Math.cos(Const::PI_180 * @lat) \
694
+ - Math.cos(Const::PI_180 * delta) \
695
+ * Math.sin(Const::PI_180 * @lat) \
696
+ * Math.cos(Const::PI_180 * hour_angle)
697
+ angle = Math.atan(a_0 / a_1) / Const::PI_180
698
+ angle += 360.0 if a_1 > 0.0 && angle < 0.0
699
+ angle += 180.0 if a_1 < 0.0
700
+ return angle
701
+ end
702
+
703
+ #=========================================================================
704
+ # 時刻(t)における黄経、黄緯(λ(jy),β(jy))の天体の高度(height)計算
705
+ #
706
+ # @param: jy (ユリウス年)
707
+ # @param: t (時刻(0.xxxx日))
708
+ # @param: lambda (天体の黄経(λ(T)(度)))
709
+ # @param: beta (天体の黄緯(β(T)(度)))
710
+ # @return: height (高度(xx.x度))
711
+ #=========================================================================
712
+ def compute_height_ecliptic(jy, t, lambda, beta)
713
+ res = eclip2equat(jy, lambda, beta)
714
+ return compute_height_equator(jy, t, *res)
715
+ end
716
+
717
+ #=========================================================================
718
+ # 時刻(t)における赤経、赤緯(α(jy),δ(jy))(度)の天体の高度(height)計算
719
+ #
720
+ # @param: jy (ユリウス年)
721
+ # @param: t (時刻 (0.xxxx日))
722
+ # @param: alpha (天体の赤経α(jy)(度))
723
+ # @param: delta (天体の赤緯δ(jy)(度))
724
+ # @return: height (高度(xx.x度))
725
+ #=========================================================================
726
+ def compute_height_equator(jy, t, alpha, delta)
727
+ time_sidereal = compute_sidereal_time(jy, t)
728
+ sidereal = time_sidereal - alpha
729
+ height = Math.sin(Const::PI_180 * delta) \
730
+ * Math.sin(Const::PI_180 * @lat) \
731
+ + Math.cos(Const::PI_180 * delta) \
732
+ * Math.cos(Const::PI_180 * @lat) \
733
+ * Math.cos(Const::PI_180 * sidereal)
734
+ height = Math.asin(height) / Const::PI_180
735
+
736
+ # 大気差補正
737
+ # [ 以下の内、3-2の計算式を採用 ]
738
+ # # 1. 日月出没計算 by「菊池さん」による計算式
739
+ # # [ http://kikuchisan.net/ ]
740
+ # h = 0.0167 / Math.tan( Const::PI_180 * ( height + 8.6 / ( height + 4.4 ) ) )
741
+
742
+ # # 2. 中川用語集による計算式 ( 5度 - 85度用 )
743
+ # # [ http://www.es.ris.ac.jp/~nakagawa/term_collection/yogoshu/ll/ni.htm ]
744
+ # h = 58.1 / Math.tan( height )
745
+ # h -= 0.07 / Math.tan( height ) ** 3
746
+ # h += 0.000086 / Math.tan( height ) ** 5
747
+ # h *= 1 / 3600.0
748
+
749
+ # # 3-1. フランスの天文学者ラドー(R.Radau)の平均大気差と1秒程度の差で大気差を求めることが可能
750
+ # # ( 標準的大気(気温10゚C,気圧1013.25hPa)の場合 )
751
+ # # ( 視高度30゚以上 )
752
+ # h = ( 58.294 / 3600.0 ) * Math.tan( Const::PI_180 * ( 90.0 - height ) )
753
+ # h -= ( 0.0668 / 3600.0 ) * Math.tan( Const::PI_180 * ( 90.0 - height ) ) ** 3
754
+
755
+ # 3-2. フランスの天文学者ラドー(R.Radau)の平均大気差と1秒程度の差で大気差を求めることが可能
756
+ # ( 標準的大気(気温10゚C,気圧1013.25hPa)の場合 )
757
+ # ( 視高度 4゚以上 )
758
+ a = Math.tan(Const::PI_180 * (90.0 - height))
759
+ h = (58.76 + \
760
+ (-0.406 + \
761
+ (- 0.0192) \
762
+ * a) * a) * a * 1 / 3600.0
763
+
764
+ # # 3-3. さらに、上記の大気差(3-1,3-2)を気温、気圧を考慮する
765
+ # # ( しかし、気温・気圧を考慮してもさほど変わりはない )
766
+ # pres = 1013.25 # <= 変更
767
+ # temp = 30.0 # <= 変更
768
+ # h *= pres / 1013.25
769
+ # h *= 283.25 / ( 273.15 + temp )
770
+
771
+ return height + h
772
+ end
773
+ end
774
+ end
775
+
@@ -0,0 +1,20 @@
1
+ module MkSunmoon
2
+ module Const
3
+ USAGE = "[USAGE] MkSunmoon.new([date[, latitude[, longitude[, altitude]]]])"
4
+ MSG_ERR_1 = "[ERROR] Invalid date! (Should be YYYYMMDD format)"
5
+ MSG_ERR_2 = "[ERROR] Invalide latitude! (Should be -90.0 < latitude < 90.0)"
6
+ MSG_ERR_3 = "[ERROR] Invalide longitude! (Should be -180.0 < longitude < 180.0)"
7
+ MSG_ERR_4 = "[ERROR] Invalide altitude! (Should be 0.0 < altitude < 10000)"
8
+ LAT_MATSUE = 35.47222222
9
+ LON_MATSUE = 133.05055556
10
+ PI = 3.141592653589793238462
11
+ PI_180 = 0.017453292519943295
12
+ K = 0.017453292519943295
13
+ OFFSET_JST = 0.375
14
+ DIGIT = 2
15
+ CONVERGE = 0.00005
16
+ REFRACTION = 0.585556
17
+ INCLINATION = 0.0353333
18
+ end
19
+ end
20
+
@@ -0,0 +1,60 @@
1
+ require 'mk_sunmoon/compute'
2
+
3
+ module MkSunmoon
4
+ class Sunmoon
5
+ attr_reader :year, :month, :day, :lat, :lon, :alt
6
+
7
+ include MkSunmoon::Compute
8
+
9
+ def initialize(args)
10
+ @year, @month, @day, @lat, @lon, @alt = args
11
+ @jd = gc2jd(year, month, day)
12
+ @jd_jst = @jd + Const::OFFSET_JST
13
+ @dt = compute_dt(year, month, day)
14
+ @incl = Const::INCLINATION * Math.sqrt(@alt)
15
+ end
16
+
17
+ #=========================================================================
18
+ # 日の出(SUNRISE)
19
+ #=========================================================================
20
+ def sunrise
21
+ return compute_sun(0)
22
+ end
23
+
24
+ #=========================================================================
25
+ # 日の入(SUNSET)
26
+ #=========================================================================
27
+ def sunset
28
+ return compute_sun(1)
29
+ end
30
+
31
+ #=========================================================================
32
+ # 日の南中(SUN MERIDIAN PASSAGE)
33
+ #=========================================================================
34
+ def sun_mp
35
+ return compute_sun(2)
36
+ end
37
+
38
+ #=========================================================================
39
+ # 月の出(MOONRISE)
40
+ #=========================================================================
41
+ def moonrise
42
+ return compute_moon(0)
43
+ end
44
+
45
+ #=========================================================================
46
+ # 月の入(MOONSET)
47
+ #=========================================================================
48
+ def moonset
49
+ return compute_moon(1)
50
+ end
51
+
52
+ #=========================================================================
53
+ # 月の南中(MOON MERIDIAN PASSAGE)
54
+ #=========================================================================
55
+ def moon_mp
56
+ return compute_moon(2)
57
+ end
58
+ end
59
+ end
60
+
@@ -0,0 +1,3 @@
1
+ module MkSunmoon
2
+ VERSION = "0.1.0"
3
+ end
data/lib/mk_sunmoon.rb ADDED
@@ -0,0 +1,12 @@
1
+ require "mk_sunmoon/version"
2
+ require "mk_sunmoon/argument"
3
+ require "mk_sunmoon/const"
4
+ require "mk_sunmoon/sunmoon"
5
+
6
+ module MkSunmoon
7
+ def self.new(*args)
8
+ res = MkSunmoon::Argument.new(*args).get_args
9
+ return if res == []
10
+ return MkSunmoon::Sunmoon.new(res)
11
+ end
12
+ end
@@ -0,0 +1,33 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'mk_sunmoon/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "mk_sunmoon"
8
+ spec.version = MkSunmoon::VERSION
9
+ spec.authors = ["mk-mode.com"]
10
+ spec.email = ["masaru@mk-mode.com"]
11
+
12
+ spec.summary = %q{Sunrise, Sunset, Moonrise, Moonset library.}
13
+ spec.description = %q{MkSunmoon is a library of Sunrise, Sunset, Moonrise, Moonset.}
14
+ spec.homepage = "https://github.com/komasaru/mk_sunmoon"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
18
+ # delete this section to allow pushing this gem to any host.
19
+ #if spec.respond_to?(:metadata)
20
+ # spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
21
+ #else
22
+ # raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
23
+ #end
24
+
25
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ spec.bindir = "exe"
27
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
+ spec.require_paths = ["lib"]
29
+
30
+ spec.add_development_dependency "bundler", "~> 1.11"
31
+ spec.add_development_dependency "rake", "~> 10.0"
32
+ spec.add_development_dependency "rspec", "~> 3.0"
33
+ end
metadata ADDED
@@ -0,0 +1,105 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mk_sunmoon
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - mk-mode.com
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-06-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: MkSunmoon is a library of Sunrise, Sunset, Moonrise, Moonset.
56
+ email:
57
+ - masaru@mk-mode.com
58
+ executables:
59
+ - mk_sunmoon
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - ".gitignore"
64
+ - ".rspec"
65
+ - ".travis.yml"
66
+ - Gemfile
67
+ - Guardfile
68
+ - LICENSE.txt
69
+ - README.md
70
+ - Rakefile
71
+ - bin/console
72
+ - bin/setup
73
+ - exe/mk_sunmoon
74
+ - lib/mk_sunmoon.rb
75
+ - lib/mk_sunmoon/argument.rb
76
+ - lib/mk_sunmoon/compute.rb
77
+ - lib/mk_sunmoon/const.rb
78
+ - lib/mk_sunmoon/sunmoon.rb
79
+ - lib/mk_sunmoon/version.rb
80
+ - mk_sunmoon.gemspec
81
+ homepage: https://github.com/komasaru/mk_sunmoon
82
+ licenses:
83
+ - MIT
84
+ metadata: {}
85
+ post_install_message:
86
+ rdoc_options: []
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ required_rubygems_version: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ requirements: []
100
+ rubyforge_project:
101
+ rubygems_version: 2.6.4
102
+ signing_key:
103
+ specification_version: 4
104
+ summary: Sunrise, Sunset, Moonrise, Moonset library.
105
+ test_files: []