korba 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/lib/korba/constant.rb +3 -1
- data/lib/korba/kep.rb +3 -0
- data/lib/korba/orbit_utils.rb +18 -0
- data/lib/korba/tle.rb +52 -16
- data/lib/korba/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc5cb24ea2424abd3408fb27d0bd8c414b60e02fc3923116f4b4a3f278be049c
|
4
|
+
data.tar.gz: 6a67a53fa7eda0a04d51bf34732a5fd82b5d97a57963e17acd28fbd64715fbf1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e3d5ee6cf6802c4c47b04986a7ae9ebf1bc279bb76d9f8e83bebc4bdabe0521be616c662a0358195b373e22a4974c1bca2e316225e4fa79e0fd63c01e35b6920
|
7
|
+
data.tar.gz: c9e5748953f5d1ad950ca294c7ecf82d099f83ebbe31753453e57930dcc9aaf4ff26ffad97677efb577ad13ba429d287917ff6a47a2dad280a5d2962b5a8d8a6
|
data/CHANGELOG.md
CHANGED
data/lib/korba/constant.rb
CHANGED
data/lib/korba/kep.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require_relative "orbit_utils"
|
2
3
|
|
3
4
|
module Korba
|
4
5
|
class Kep
|
6
|
+
include Korba::OrbitUtils
|
7
|
+
|
5
8
|
attr_reader :object_name, :epoch, :semi_major_axis, :eccentricity, :inclination, :ra_of_asc_node, :arg_of_pericenter, :mean_anomaly
|
6
9
|
|
7
10
|
def initialize(object_name:, epoch:, semi_major_axis:, eccentricity:, inclination:, ra_of_asc_node:, arg_of_pericenter:, mean_anomaly:)
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Korba
|
4
|
+
module OrbitUtils
|
5
|
+
def semi_major_axis
|
6
|
+
# a = (μ / n^2)^(1/3) m
|
7
|
+
(Korba::Constant::GME / (mean_motion * 2 * Math::PI / 86400.0) ** 2.0) ** (1.0 / 3.0)
|
8
|
+
end
|
9
|
+
|
10
|
+
def height_at_perigee
|
11
|
+
semi_major_axis * (1 - eccentricity) - Korba::Constant::EARTH_RADIUS
|
12
|
+
end
|
13
|
+
|
14
|
+
def height_at_apogee
|
15
|
+
semi_major_axis * (1 + eccentricity) - Korba::Constant::EARTH_RADIUS
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
data/lib/korba/tle.rb
CHANGED
@@ -1,24 +1,19 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
+
require_relative "orbit_utils"
|
3
|
+
|
2
4
|
module Korba
|
3
5
|
class Tle
|
4
|
-
|
6
|
+
include Korba::OrbitUtils
|
5
7
|
|
6
|
-
|
7
|
-
@tle_json = tle_json
|
8
|
-
@object_name = tle_json[:OBJECT_NAME]
|
9
|
-
@object_id = tle_json[:OBJECT_ID]
|
10
|
-
@epoch = tle_json[:EPOCH]
|
11
|
-
@mean_motion = tle_json[:MEAN_MOTION]
|
12
|
-
@eccentricity = tle_json[:ECCENTRICITY]
|
13
|
-
@inclination = tle_json[:INCLINATION]
|
14
|
-
@ra_of_asc_node = tle_json[:RA_OF_ASC_NODE]
|
15
|
-
@arg_of_pericenter = tle_json[:ARG_OF_PERICENTER]
|
16
|
-
@mean_anomaly = tle_json[:MEAN_ANOMALY]
|
17
|
-
end
|
8
|
+
attr_reader :tle_json, :object_name, :object_id, :epoch, :mean_motion, :eccentricity, :inclination, :ra_of_asc_node, :arg_of_pericenter, :mean_anomaly
|
18
9
|
|
19
|
-
def
|
20
|
-
|
21
|
-
|
10
|
+
def initialize(tle, type: :string)
|
11
|
+
case type
|
12
|
+
when :string
|
13
|
+
initialize_from_string(tle)
|
14
|
+
when :json
|
15
|
+
initialize_from_json(tle)
|
16
|
+
end
|
22
17
|
end
|
23
18
|
|
24
19
|
def to_kep
|
@@ -31,5 +26,46 @@ module Korba
|
|
31
26
|
arg_of_pericenter:,
|
32
27
|
mean_anomaly:)
|
33
28
|
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def initialize_from_string(tle_string)
|
33
|
+
lines = tle_string.split(/\R/)
|
34
|
+
@object_name = lines.shift if lines.size > 2
|
35
|
+
parse_line1(lines[0].split(" "))
|
36
|
+
parse_line2(lines[1].split(" "))
|
37
|
+
end
|
38
|
+
|
39
|
+
def parse_line1(line1_strings)
|
40
|
+
# TODO: object_id
|
41
|
+
# For now, only supports years after 2000
|
42
|
+
epoch_year = line1_strings[3][0..1].to_i + 2000
|
43
|
+
epoch_day_of_year = line1_strings[3][2..].to_f
|
44
|
+
# Subtract 1 from epoch_day_of_year because January 1st is considered day 1
|
45
|
+
epoch_time = Time.new(epoch_year, 1, 1, 0, 0, 0, "+00:00") + (epoch_day_of_year - 1) * 24 * 60 * 60
|
46
|
+
@epoch = epoch_time.strftime("%Y-%m-%dT%H:%M:%S.%6N")
|
47
|
+
end
|
48
|
+
|
49
|
+
def parse_line2(line2_strings)
|
50
|
+
@inclination = line2_strings[2].to_f
|
51
|
+
@ra_of_asc_node = line2_strings[3].to_f
|
52
|
+
@eccentricity = "0.#{line2_strings[4]}".to_f
|
53
|
+
@arg_of_pericenter = line2_strings[5].to_f
|
54
|
+
@mean_anomaly = line2_strings[6].to_f
|
55
|
+
@mean_motion = line2_strings[7].to_f
|
56
|
+
end
|
57
|
+
|
58
|
+
def initialize_from_json(tle_json)
|
59
|
+
@tle_json = tle_json
|
60
|
+
@object_name = tle_json[:OBJECT_NAME]
|
61
|
+
@object_id = tle_json[:OBJECT_ID]
|
62
|
+
@epoch = tle_json[:EPOCH]
|
63
|
+
@mean_motion = tle_json[:MEAN_MOTION]
|
64
|
+
@eccentricity = tle_json[:ECCENTRICITY]
|
65
|
+
@inclination = tle_json[:INCLINATION]
|
66
|
+
@ra_of_asc_node = tle_json[:RA_OF_ASC_NODE]
|
67
|
+
@arg_of_pericenter = tle_json[:ARG_OF_PERICENTER]
|
68
|
+
@mean_anomaly = tle_json[:MEAN_ANOMALY]
|
69
|
+
end
|
34
70
|
end
|
35
71
|
end
|
data/lib/korba/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: korba
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- kk0000-kk
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-12-
|
11
|
+
date: 2024-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Orbital elements calculation library
|
14
14
|
email:
|
@@ -24,6 +24,7 @@ files:
|
|
24
24
|
- lib/korba.rb
|
25
25
|
- lib/korba/constant.rb
|
26
26
|
- lib/korba/kep.rb
|
27
|
+
- lib/korba/orbit_utils.rb
|
27
28
|
- lib/korba/tle.rb
|
28
29
|
- lib/korba/version.rb
|
29
30
|
- sig/korba.rbs
|