Class: Astronoby::ExtremumCalculator

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/events/extremum_calculator.rb

Instance Method Summary collapse

Constructor Details

#initialize(body:, primary_body:, ephem:, samples_per_period: 60) ⇒ ExtremumCalculator

Returns a new instance of ExtremumCalculator.

Parameters:

  • body (Astronoby::SolarSystemBody)

    the celestial body to track

  • primary_body (Astronoby::SolarSystemBody)

    the reference body

  • ephem (::Ephem::SPK)

    ephemeris data source

  • samples_per_period (Integer) (defaults to: 60)

    number of samples per orbital period



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/astronoby/events/extremum_calculator.rb', line 9

def initialize(
  body:,
  primary_body:,
  ephem:,
  samples_per_period: 60
)
  @body = body
  @primary_body = primary_body
  @ephem = ephem
  @samples_per_period = samples_per_period
end

Instance Method Details

#apoapsis_events_between(start_time, end_time) ⇒ Array<Astronoby::ExtremumEvent>

Finds all apoapsis events between two times

Parameters:

  • start_time (Time)

    Start time

  • end_time (Time)

    End time

Returns:



25
26
27
28
29
30
31
# File 'lib/astronoby/events/extremum_calculator.rb', line 25

def apoapsis_events_between(start_time, end_time)
  find_extrema(
    Instant.from_time(start_time).tt,
    Instant.from_time(end_time).tt,
    type: :maximum
  )
end

#find_extrema(start_jd, end_jd, type: :maximum) ⇒ Array<Astronoby::ExtremumEvent>

Finds extrema (minima or maxima) in the distance between bodies within

a time range

Parameters:

  • start_jd (Float)

    Start time in Julian Date (Terrestrial Time)

  • end_jd (Float)

    End time in Julian Date (Terrestrial Time)

  • type (Symbol) (defaults to: :maximum)

    :maximum or :minimum

Returns:



51
52
53
54
55
56
57
58
# File 'lib/astronoby/events/extremum_calculator.rb', line 51

def find_extrema(start_jd, end_jd, type: :maximum)
  finder.extrema(start_jd, end_jd, type: type).map do |extremum|
    ExtremumEvent.new(
      Instant.from_terrestrial_time(extremum[:jd]),
      extremum[:value]
    )
  end
end

#periapsis_events_between(start_time, end_time) ⇒ Array<Astronoby::ExtremumEvent>

Finds all periapsis events between two times

Parameters:

  • start_time (Time)

    Start time

  • end_time (Time)

    End time

Returns:



37
38
39
40
41
42
43
# File 'lib/astronoby/events/extremum_calculator.rb', line 37

def periapsis_events_between(start_time, end_time)
  find_extrema(
    Instant.from_time(start_time).tt,
    Instant.from_time(end_time).tt,
    type: :minimum
  )
end