Class: Astronoby::Correction::LightTimeDelay

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/corrections/light_time_delay.rb

Constant Summary collapse

LIGHT_SPEED_CORRECTION_MAXIMUM_ITERATIONS =
10
LIGHT_SPEED_CORRECTION_PRECISION =
1e-12

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(center:, target:, ephem:) ⇒ LightTimeDelay

Returns a new instance of LightTimeDelay.



13
14
15
16
17
# File 'lib/astronoby/corrections/light_time_delay.rb', line 13

def initialize(center:, target:, ephem:)
  @center = center
  @target = target
  @ephem = ephem
end

Class Method Details

.compute(center:, target:, ephem:) ⇒ Object



9
10
11
# File 'lib/astronoby/corrections/light_time_delay.rb', line 9

def self.compute(center:, target:, ephem:)
  new(center: center, target: target, ephem: ephem).compute
end

Instance Method Details

#computeObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/astronoby/corrections/light_time_delay.rb', line 26

def compute
  @corrected_position ||= begin
    corrected_position = Vector[
      Distance.zero,
      Distance.zero,
      Distance.zero
    ]
    corrected_velocity = Vector[
      Velocity.zero,
      Velocity.zero,
      Velocity.zero
    ]
    @delay = initial_delta_in_seconds

    LIGHT_SPEED_CORRECTION_MAXIMUM_ITERATIONS.times do
      new_instant = Instant.from_terrestrial_time(
        instant.tt - @delay / Constants::SECONDS_PER_DAY
      )
      corrected = @target
        .target_body
        .geometric(ephem: @ephem, instant: new_instant)
      corrected_position = corrected.position
      corrected_velocity = corrected.velocity

      corrected_distance_in_km = Math.sqrt(
        (corrected_position.x.km - position.x.km)**2 +
          (corrected_position.y.km - position.y.km)**2 +
          (corrected_position.z.km - position.z.km)**2
      )

      new_delay = corrected_distance_in_km / Velocity.light_speed.kmps

      break if (new_delay - @delay).abs < LIGHT_SPEED_CORRECTION_PRECISION

      @delay = new_delay
    end

    [corrected_position, corrected_velocity]
  end
end

#delayObject



19
20
21
22
23
24
# File 'lib/astronoby/corrections/light_time_delay.rb', line 19

def delay
  @_delay ||= begin
    compute
    @delay
  end
end