Class: Ephem::Core::State

Inherits:
Object
  • Object
show all
Defined in:
lib/ephem/core/state.rb

Overview

Represents the state of a celestial object in space, consisting of its position and velocity vectors. This class is fundamental for describing orbital motion and performing astronomical calculations.

Examples:

Create a state for a celestial object

position = Ephem::Vector.new(1.0, 2.0, 3.0)
velocity = Ephem::Vector.new(0.1, 0.2, 0.3)
state = Ephem::State.new(position, velocity)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(position, velocity) ⇒ State

Creates a new State instance.

Examples:

Create a state at the solar system barycenter with zero velocity

position = Ephem::Vector.new(0.0, 0.0, 0.0)
velocity = Ephem::Vector.new(0.0, 0.0, 0.0)
state = Ephem::State.new(position, velocity)

Parameters:

  • position (Ephem::Vector)

    The position vector

  • velocity (Ephem::Vector)

    The velocity vector



29
30
31
32
# File 'lib/ephem/core/state.rb', line 29

def initialize(position, velocity)
  @position = position
  @velocity = velocity
end

Instance Attribute Details

#positionEphem::Vector (readonly)

Returns The position vector of the object.

Returns:

  • (Ephem::Vector)

    The position vector of the object



15
16
17
# File 'lib/ephem/core/state.rb', line 15

def position
  @position
end

#velocityEphem::Vector (readonly)

Returns The velocity vector of the object.

Returns:

  • (Ephem::Vector)

    The velocity vector of the object



18
19
20
# File 'lib/ephem/core/state.rb', line 18

def velocity
  @velocity
end

Class Method Details

.from_arrays(position, velocity) ⇒ Ephem::State

Creates a State instance from arrays of position and velocity components.

Examples:

Create a state from arrays

position = [1.0, 2.0, 3.0]
velocity = [0.1, 0.2, 0.3]
state = Ephem::State.from_arrays(position, velocity)

Parameters:

  • position (Array<Numeric>)

    Array of [x, y, z] position components

  • velocity (Array<Numeric>)

    Array of [vx, vy, vz] velocity components

Returns:

  • (Ephem::State)

    A new State instance



47
48
49
50
51
52
# File 'lib/ephem/core/state.rb', line 47

def self.from_arrays(position, velocity)
  new(
    Vector.new(position[0], position[1], position[2]),
    Vector.new(velocity[0], velocity[1], velocity[2])
  )
end

Instance Method Details

#to_arraysArray<Array<Numeric>>

Converts the state vectors to arrays.

Examples:

Get position and velocity components as arrays

pos_arr, vel_arr = state.to_arrays

Returns:

  • (Array<Array<Numeric>>)

    Array containing position and velocity arrays



61
62
63
# File 'lib/ephem/core/state.rb', line 61

def to_arrays
  [position.to_a, velocity.to_a]
end