Class: Korba::Propagator::Rk4

Inherits:
Object
  • Object
show all
Defined in:
lib/korba/propagator/rk4.rb

Instance Method Summary collapse

Constructor Details

#initialize(initial_car, disable_j2: false) ⇒ Rk4

Returns a new instance of Rk4.



4
5
6
7
# File 'lib/korba/propagator/rk4.rb', line 4

def initialize(initial_car, disable_j2: false)
  @initial_car = initial_car
  @disable_j2 = disable_j2
end

Instance Method Details

#propagate(seconds_after_epoch, dt = 1.0) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/korba/propagator/rk4.rb', line 9

def propagate(seconds_after_epoch, dt = 1.0)
  steps = (seconds_after_epoch / dt).to_i
  t = 0.0
  y = Vector[@initial_car.x, @initial_car.y, @initial_car.z, @initial_car.vx, @initial_car.vy, @initial_car.vz]

  steps.times do
    y = step(t, y, dt)
    t += dt
  end

  Car.new(
    object_name: @initial_car.object_name,
    epoch: @initial_car.epoch + seconds_after_epoch,
    x: y[0],
    y: y[1],
    z: y[2],
    vx: y[3],
    vy: y[4],
    vz: y[5],
  )
end