Class: Korba::Orbit

Inherits:
Object
  • Object
show all
Includes:
Converter
Defined in:
lib/korba/orbit.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Converter

#cartesian_to_keplerian, #keplerian_to_cartesian, #tle_to_cartesian, #tle_to_keplerian

Constructor Details

#initialize(keplerian: nil, cartesian: nil, tle: nil, epoch: nil, name: nil) ⇒ Orbit

Returns a new instance of Orbit.



23
24
25
26
27
28
29
# File 'lib/korba/orbit.rb', line 23

def initialize(keplerian: nil, cartesian: nil, tle: nil, epoch: nil, name: nil)
  @keplerian = keplerian
  @cartesian = cartesian
  @tle = tle
  @epoch = epoch
  @name = name
end

Instance Attribute Details

#epochObject (readonly)

Returns the value of attribute epoch.



6
7
8
# File 'lib/korba/orbit.rb', line 6

def epoch
  @epoch
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/korba/orbit.rb', line 6

def name
  @name
end

#tleObject (readonly)

Returns the value of attribute tle.



6
7
8
# File 'lib/korba/orbit.rb', line 6

def tle
  @tle
end

Class Method Details

.from_cartesian(cartesian) ⇒ Object



18
19
20
# File 'lib/korba/orbit.rb', line 18

def from_cartesian(cartesian)
  new(cartesian:, epoch: cartesian.epoch, name: cartesian.object_name)
end

.from_keplerian(keplerian) ⇒ Object



14
15
16
# File 'lib/korba/orbit.rb', line 14

def from_keplerian(keplerian)
  new(keplerian:, epoch: keplerian.epoch, name: keplerian.object_name)
end

.from_tle(tle = nil, type: :string) ⇒ Object



9
10
11
12
# File 'lib/korba/orbit.rb', line 9

def from_tle(tle = nil, type: :string)
  tle = Tle.new(tle, type:)
  new(tle:, epoch: tle.epoch_datetime, name: tle.object_name)
end

Instance Method Details

#cartesianObject



31
32
33
# File 'lib/korba/orbit.rb', line 31

def cartesian
  @cartesian ||= tle_to_cartesian(tle) || keplerian_to_cartesian(keplerian)
end

#keplerianObject



35
36
37
# File 'lib/korba/orbit.rb', line 35

def keplerian
  @keplerian ||= tle_to_keplerian(tle) || cartesian_to_keplerian(cartesian)
end

#propagate(type:, seconds_after_epoch:, disable_j2: false) ⇒ Object



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/korba/orbit.rb', line 39

def propagate(type:, seconds_after_epoch:, disable_j2: false)
  case type.to_sym
  in :sgp4
    propagated_cartesian = tle.propagate_to(seconds_after_epoch / 60.0)
    return Orbit.from_cartesian(propagated_cartesian)
  in :rk4
    propagator = Propagator::Rk4.new(cartesian, disable_j2:)
    propagated_cartesian = propagator.propagate(seconds_after_epoch)
    return Orbit.from_cartesian(propagated_cartesian)
  in :kepler
    propagator = Propagator::Kepler.new(keplerian, disable_j2:)
    propagated_keplerian = propagator.propagate(seconds_after_epoch)
    return Orbit.from_keplerian(propagated_keplerian)
  end
end