Class: Ephem::Core::Orientation

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

Overview

The orientation of a body, expressed as the three Euler angles that rotate a reference frame (e.g. J2000/ICRF) into the body-fixed frame, optionally with their time derivatives.

For binary PCK orientation kernels the angles are the classical 3-1-3 (Z-X-Z) sequence: phi and theta orient the pole and psi is the rotation about it (the prime meridian). Angles are in radians and rates, when present, in radians per day — matching ephem’s per-day rate convention for SPK velocities (divide by 86400 for radians per second).

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(phi, theta, psi, rates: nil) ⇒ Orientation

Returns a new instance of Orientation.

Parameters:

  • phi (Numeric)

    first Euler angle (radians)

  • theta (Numeric)

    second Euler angle (radians)

  • psi (Numeric)

    third Euler angle (radians)

  • rates (Array<Numeric>, nil) (defaults to: nil)

    optional [phi, theta, psi] rates (radians/day)

Raises:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/ephem/core/orientation.rb', line 34

def initialize(phi, theta, psi, rates: nil)
  unless phi.is_a?(Numeric) && theta.is_a?(Numeric) && psi.is_a?(Numeric)
    raise InvalidInputError, "Orientation angles must be numeric"
  end

  unless rates.nil? || valid_rates?(rates)
    raise InvalidInputError, "Orientation rates must be three numerics"
  end

  @phi = phi
  @theta = theta
  @psi = psi
  @rates = rates&.freeze
  freeze
end

Instance Attribute Details

#phiNumeric (readonly)

Returns first Euler angle (radians).

Returns:

  • (Numeric)

    first Euler angle (radians)



16
17
18
# File 'lib/ephem/core/orientation.rb', line 16

def phi
  @phi
end

#psiNumeric (readonly)

Returns third Euler angle (radians).

Returns:

  • (Numeric)

    third Euler angle (radians)



22
23
24
# File 'lib/ephem/core/orientation.rb', line 22

def psi
  @psi
end

#ratesArray<Numeric>? (readonly)

Returns [phi, theta, psi] rates (radians/day), or nil when the orientation carries no rates.

Returns:

  • (Array<Numeric>, nil)
    phi, theta, psi

    rates (radians/day),

    or nil when the orientation carries no rates



26
27
28
# File 'lib/ephem/core/orientation.rb', line 26

def rates
  @rates
end

#thetaNumeric (readonly)

Returns second Euler angle (radians).

Returns:

  • (Numeric)

    second Euler angle (radians)



19
20
21
# File 'lib/ephem/core/orientation.rb', line 19

def theta
  @theta
end

Class Method Details

.[](phi, theta, psi, rates: nil) ⇒ Object



50
51
52
# File 'lib/ephem/core/orientation.rb', line 50

def self.[](phi, theta, psi, rates: nil)
  new(phi, theta, psi, rates: rates)
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



100
101
102
103
104
105
106
# File 'lib/ephem/core/orientation.rb', line 100

def ==(other)
  unless other.is_a?(self.class)
    raise InvalidInputError, "Can only compare with another Orientation"
  end

  to_a == other.to_a && rates == other.rates
end

#[](index) ⇒ Numeric

Returns the angle at the given index.

Parameters:

  • index (Integer)

    0 for phi, 1 for theta, 2 for psi

Returns:

  • (Numeric)

    the angle at the given index

Raises:



80
81
82
83
84
85
86
87
# File 'lib/ephem/core/orientation.rb', line 80

def [](index)
  case index
  when 0 then phi
  when 1 then theta
  when 2 then psi
  else raise IndexError, "Invalid index: #{index}"
  end
end

#hashObject



96
97
98
# File 'lib/ephem/core/orientation.rb', line 96

def hash
  [phi, theta, psi, rates, self.class].hash
end

#inspectObject Also known as: to_s



89
90
91
92
93
# File 'lib/ephem/core/orientation.rb', line 89

def inspect
  body = "phi: #{phi}, theta: #{theta}, psi: #{psi}"
  body += ", rates: #{rates}" if rates?
  "Orientation[#{body}]"
end

#rates?Boolean

Returns whether this orientation carries rates.

Returns:

  • (Boolean)

    whether this orientation carries rates



55
56
57
# File 'lib/ephem/core/orientation.rb', line 55

def rates?
  !@rates.nil?
end

#to_aArray<Numeric>

Returns the three Euler angles [phi, theta, psi].

Returns:

  • (Array<Numeric>)

    the three Euler angles [phi, theta, psi]



60
61
62
# File 'lib/ephem/core/orientation.rb', line 60

def to_a
  [phi, theta, psi]
end

#to_matrixArray<Array<Float>>

The rotation matrix that maps the reference frame into the body-fixed frame, built from the 3-1-3 (Z-X-Z) Euler angles: M = Rz(psi) * Rx(theta) * Rz(phi). Rates are ignored.

Returns:

  • (Array<Array<Float>>)

    a 3x3 rotation matrix



69
70
71
72
73
74
75
# File 'lib/ephem/core/orientation.rb', line 69

def to_matrix
  Rotation.multiply(
    Rotation.about_z(psi),
    Rotation.about_x(theta),
    Rotation.about_z(phi)
  )
end