korba 0.1.0 → 0.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9653687d464e692461e7f9d1a02bf22c969b9cbd410be77270f2774f04efde50
4
- data.tar.gz: d5d043ecefc767e6ba7c158158065cfc42fc3bcda73b47e6f79315c478733b4a
3
+ metadata.gz: 5b7470c62a2e8df7ed79ca869272a846fad21bed8794ee2b25deff5448cbfb85
4
+ data.tar.gz: ee043f86462fe065c95245706174aae8945347d91aba211d3fc7f988975c25a3
5
5
  SHA512:
6
- metadata.gz: 64c57ea852bd747be82d9c0d42a963c1990167d92316447b6ccf338be2fc8e4c9775fb2155f1372939a1aa5d5a2c554a9e4abb213367e13afd51df5bd51b22a2
7
- data.tar.gz: 90e986f11ccfa6f197df247339d39e1c928c788e36c0796027a571e09718c83ac75c4f210104ba5b209bc28c3eb183a021cb00e7c2caf08439082a1468dca97b
6
+ metadata.gz: '0529630074005be970a0cc52aaa583e357cd856daafbcda8d0db1e074a8f5bbd0ab810edc25e721c6fd5b5b6ba2b97bf398e472d4a0ed77b03a465d40ec4d75d'
7
+ data.tar.gz: ffda7bb7e72c728ba5e7ef4199d5c00cc8b5102c19fb9af9976c95d7b64158e6f4514d3ea289c32225460bfc91481344b98caab4c34016567af0d7d978a8de23
data/CHANGELOG.md CHANGED
@@ -1,4 +1,11 @@
1
- ## [Unreleased]
1
+ ## [0.3.0] - 2024-12-09
2
+
3
+ - Enable instance creation without arguments
4
+
5
+ ## [0.2.0] - 2024-12-08
6
+
7
+ - Enable to create tle object from string
8
+ - Enable to calculate height
2
9
 
3
10
  ## [0.1.0] - 2024-11-30
4
11
 
data/README.md CHANGED
@@ -1,28 +1,55 @@
1
- # Korba
1
+ [![Gem Version](https://badge.fury.io/rb/korba.svg)](https://rubygems.org/gems/korba)
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
3
+ # Korba
4
4
 
5
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/korba`. To experiment with that code, run `bin/console` for an interactive prompt.
5
+ An orbital analytics library for ruby.
6
6
 
7
7
  ## Installation
8
8
 
9
- TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
-
11
9
  Install the gem and add to the application's Gemfile by executing:
12
10
 
13
11
  ```bash
14
- bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
12
+ bundle add korba
15
13
  ```
16
14
 
17
15
  If bundler is not being used to manage dependencies, install the gem by executing:
18
16
 
19
17
  ```bash
20
- gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+ gem install korba
21
19
  ```
22
20
 
23
21
  ## Usage
24
22
 
25
- TODO: Write usage instructions here
23
+ ### Create Orbital Elements From TLE(Two Line Elements)
24
+
25
+ ```ruby
26
+ orbit = Korba::Tle.new(<<~TLE)
27
+ ISS (ZARYA)
28
+ 1 25544U 98067A 24342.85930654 .00018474 00000+0 32681-3 0 9991
29
+ 2 25544 51.6381 174.9565 0006817 314.0303 175.4461 15.50337242485488
30
+ TLE
31
+
32
+ orbit.semi_major_axis
33
+ # => 6793877.649839985
34
+
35
+ orbit.height_at_perigee
36
+ # => 411109.2634460889
37
+
38
+ orbit.height_at_apogee
39
+ # => 420372.03623388056
40
+
41
+ orbit.to_kep
42
+ # =>
43
+ # #<Korba::Kep:xxxxxxxxxxxxxxxx
44
+ # @arg_of_pericenter=314.0303,
45
+ # @eccentricity=0.0006817,
46
+ # @epoch="2024-12-07T20:37:24.085055",
47
+ # @inclination=51.6381,
48
+ # @mean_anomaly=175.4461,
49
+ # @object_name="ISS (ZARYA)",
50
+ # @ra_of_asc_node=174.9565,
51
+ # @semi_major_axis=6793877.649839985>
52
+ ```
26
53
 
27
54
  ## Development
28
55
 
@@ -32,4 +59,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
59
 
33
60
  ## Contributing
34
61
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/korba.
62
+ Bug reports and pull requests are welcome on GitHub at https://github.com/kk0000-kk/korba.
@@ -2,7 +2,9 @@
2
2
 
3
3
  module Korba
4
4
  class Constant
5
- # 3.986004418(8)×10^14 m3/s2
5
+ # geocentric gravitational constant in m3/s2
6
6
  GME = 3.9860044188e14
7
+ # nominal equatorial Earth radius in m
8
+ EARTH_RADIUS = 6378137
7
9
  end
8
10
  end
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,21 @@
1
1
  # frozen_string_literal: true
2
+ require_relative "orbit_utils"
3
+
2
4
  module Korba
3
5
  class Tle
6
+ include Korba::OrbitUtils
7
+
4
8
  attr_reader :tle_json, :object_name, :object_id, :epoch, :mean_motion, :eccentricity, :inclination, :ra_of_asc_node, :arg_of_pericenter, :mean_anomaly
5
9
 
6
- def initialize(tle_json)
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
10
+ def initialize(tle = nil, type: :string)
11
+ return if tle.nil?
18
12
 
19
- def semi_major_axis
20
- # a = (μ / n^2)^(1/3) m
21
- (Korba::Constant::GME / (mean_motion * 2 * Math::PI / 86400.0) ** 2.0) ** (1.0 / 3.0)
13
+ case type
14
+ when :string
15
+ initialize_from_string(tle)
16
+ when :json
17
+ initialize_from_json(tle)
18
+ end
22
19
  end
23
20
 
24
21
  def to_kep
@@ -31,5 +28,46 @@ module Korba
31
28
  arg_of_pericenter:,
32
29
  mean_anomaly:)
33
30
  end
31
+
32
+ private
33
+
34
+ def initialize_from_string(tle_string)
35
+ lines = tle_string.split(/\R/)
36
+ @object_name = lines.shift if lines.size > 2
37
+ parse_line1(lines[0].split(" "))
38
+ parse_line2(lines[1].split(" "))
39
+ end
40
+
41
+ def parse_line1(line1_strings)
42
+ # TODO: object_id
43
+ # For now, only supports years after 2000
44
+ epoch_year = line1_strings[3][0..1].to_i + 2000
45
+ epoch_day_of_year = line1_strings[3][2..].to_f
46
+ # Subtract 1 from epoch_day_of_year because January 1st is considered day 1
47
+ epoch_time = Time.new(epoch_year, 1, 1, 0, 0, 0, "+00:00") + (epoch_day_of_year - 1) * 24 * 60 * 60
48
+ @epoch = epoch_time.strftime("%Y-%m-%dT%H:%M:%S.%6N")
49
+ end
50
+
51
+ def parse_line2(line2_strings)
52
+ @inclination = line2_strings[2].to_f
53
+ @ra_of_asc_node = line2_strings[3].to_f
54
+ @eccentricity = "0.#{line2_strings[4]}".to_f
55
+ @arg_of_pericenter = line2_strings[5].to_f
56
+ @mean_anomaly = line2_strings[6].to_f
57
+ @mean_motion = line2_strings[7].to_f
58
+ end
59
+
60
+ def initialize_from_json(tle_json)
61
+ @tle_json = tle_json
62
+ @object_name = tle_json[:OBJECT_NAME]
63
+ @object_id = tle_json[:OBJECT_ID]
64
+ @epoch = tle_json[:EPOCH]
65
+ @mean_motion = tle_json[:MEAN_MOTION]
66
+ @eccentricity = tle_json[:ECCENTRICITY]
67
+ @inclination = tle_json[:INCLINATION]
68
+ @ra_of_asc_node = tle_json[:RA_OF_ASC_NODE]
69
+ @arg_of_pericenter = tle_json[:ARG_OF_PERICENTER]
70
+ @mean_anomaly = tle_json[:MEAN_ANOMALY]
71
+ end
34
72
  end
35
73
  end
data/lib/korba/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Korba
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.0"
5
5
  end
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.1.0
4
+ version: 0.3.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-07 00:00:00.000000000 Z
11
+ date: 2024-12-09 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