Class: Ephem::Segments::Segment

Inherits:
BaseSegment show all
Includes:
ChebyshevType2
Defined in:
lib/ephem/segments/segment.rb

Overview

SPK trajectory segment: position (type 2) and position/velocity (type 3) of a target body relative to a center body, stored as Chebyshev coefficients.

Examples:

Computing position at a specific time

segment = Ephem::Segments::Segment.new(
  daf: daf_object,
  source: "DE440.bsp",
  descriptor: [...]
)
position = segment.compute(time)  # returns Vector

Computing position and velocity

state = segment.compute_and_differentiate(time)  # returns State

See Also:

Constant Summary collapse

COMPONENT_COUNTS =
{
  2 => 3,  # Type 2: position (x, y, z)
  3 => 6   # Type 3: position (x, y, z) and velocity (vx, vy, vz)
}.freeze

Constants inherited from BaseSegment

BaseSegment::TARGET_NAMES

Instance Attribute Summary

Attributes inherited from BaseSegment

#center, #daf, #end_jd, #source, #start_jd, #target

Instance Method Summary collapse

Methods included from ChebyshevType2

#clear_data

Methods inherited from BaseSegment

#clear_data, #covers?, #describe, #to_s

Methods included from Core::CalendarCalculations

format_date, julian_to_gregorian

Constructor Details

#initialize(daf:, source:, descriptor:) ⇒ Segment

Returns a new instance of Segment.



31
32
33
34
35
# File 'lib/ephem/segments/segment.rb', line 31

def initialize(daf:, source:, descriptor:)
  super
  @data_loaded = false
  @data_lock = Mutex.new
end

Instance Method Details

#compute(tdb, tdb2 = 0.0) ⇒ Ephem::Core::Vector Also known as: position_at

Computes the position of the target body relative to the center body at the specified time.

Parameters:

  • tdb (Numeric, Array<Numeric>)

    Time(s) in TDB Julian Date

  • tdb2 (Numeric) (defaults to: 0.0)

    Optional fractional part of TDB date

Returns:

Raises:



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ephem/segments/segment.rb', line 44

def compute(tdb, tdb2 = 0.0)
  load_data
  tdb_seconds = convert_to_seconds(tdb, tdb2)

  case tdb_seconds
  when Numeric
    position = generate_position(tdb_seconds)
    Core::Vector.new(position[0], position[1], position[2])
  else
    tdb_seconds.map do |t|
      position = generate_position(t)
      Core::Vector.new(position[0], position[1], position[2])
    end
  end
end

#compute_and_differentiate(tdb, tdb2 = 0.0) ⇒ Ephem::Core::State+ Also known as: state_at

Computes both position and velocity vectors at the specified time.

Parameters:

  • tdb (Numeric, Array<Numeric>)

    Time(s) in TDB Julian Date

  • tdb2 (Numeric) (defaults to: 0.0)

    Optional fractional part of TDB date

Returns:

Raises:



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/ephem/segments/segment.rb', line 69

def compute_and_differentiate(tdb, tdb2 = 0.0)
  load_data
  tdb_seconds = convert_to_seconds(tdb, tdb2)

  case tdb_seconds
  when Numeric
    pos_array, vel_array = generate_single(tdb_seconds)
    Core::State.new(
      Core::Vector.new(pos_array[0], pos_array[1], pos_array[2]),
      Core::Vector.new(vel_array[0], vel_array[1], vel_array[2])
    )
  else
    generate_multiple(tdb_seconds).map do |pos_array, vel_array|
      Core::State.new(
        Core::Vector.new(pos_array[0], pos_array[1], pos_array[2]),
        Core::Vector.new(vel_array[0], vel_array[1], vel_array[2])
      )
    end
  end
end