Class: Ephem::Core::Orientation
- Inherits:
-
Object
- Object
- Ephem::Core::Orientation
- 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
-
#phi ⇒ Numeric
readonly
First Euler angle (radians).
-
#psi ⇒ Numeric
readonly
Third Euler angle (radians).
-
#rates ⇒ Array<Numeric>?
readonly
- phi, theta, psi
-
rates (radians/day), or nil when the orientation carries no rates.
-
#theta ⇒ Numeric
readonly
Second Euler angle (radians).
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#[](index) ⇒ Numeric
The angle at the given index.
- #hash ⇒ Object
-
#initialize(phi, theta, psi, rates: nil) ⇒ Orientation
constructor
A new instance of Orientation.
- #inspect ⇒ Object (also: #to_s)
-
#rates? ⇒ Boolean
Whether this orientation carries rates.
-
#to_a ⇒ Array<Numeric>
The three Euler angles [phi, theta, psi].
-
#to_matrix ⇒ Array<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).
Constructor Details
#initialize(phi, theta, psi, rates: nil) ⇒ Orientation
Returns a new instance of Orientation.
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
#phi ⇒ Numeric (readonly)
Returns first Euler angle (radians).
16 17 18 |
# File 'lib/ephem/core/orientation.rb', line 16 def phi @phi end |
#psi ⇒ Numeric (readonly)
Returns third Euler angle (radians).
22 23 24 |
# File 'lib/ephem/core/orientation.rb', line 22 def psi @psi end |
#rates ⇒ Array<Numeric>? (readonly)
Returns [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 |
#theta ⇒ Numeric (readonly)
Returns 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.
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 |
#hash ⇒ Object
96 97 98 |
# File 'lib/ephem/core/orientation.rb', line 96 def hash [phi, theta, psi, rates, self.class].hash end |
#inspect ⇒ Object 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.
55 56 57 |
# File 'lib/ephem/core/orientation.rb', line 55 def rates? !@rates.nil? end |
#to_a ⇒ Array<Numeric>
Returns 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_matrix ⇒ Array<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.
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 |