Class: Astronoby::ReferenceFrame
- Inherits:
-
Object
- Object
- Astronoby::ReferenceFrame
- Defined in:
- lib/astronoby/reference_frame.rb
Overview
Base class for reference frames in the astronomical reference frame chain. Each frame represents a body’s position and velocity relative to a center, at a specific instant.
Direct Known Subclasses
Apparent, Astrometric, Geometric, MeanOfDate, Teme, Topocentric
Instance Attribute Summary collapse
-
#center ⇒ Astronoby::Center
readonly
The center of the frame.
-
#instant ⇒ Astronoby::Instant
readonly
The time instant.
-
#position ⇒ Astronoby::Vector<Astronoby::Distance>
readonly
Position vector.
-
#target_body ⇒ Astronoby::Body?
readonly
The target body.
-
#velocity ⇒ Astronoby::Vector<Astronoby::Velocity>
readonly
Velocity vector.
Instance Method Summary collapse
-
#distance ⇒ Astronoby::Distance
The Euclidean distance from the center.
-
#ecliptic ⇒ Astronoby::Coordinates::Ecliptic
Ecliptic coordinates derived from the equatorial coordinates at J2000.0.
-
#equatorial ⇒ Astronoby::Coordinates::Equatorial
Equatorial coordinates derived from the position vector.
-
#initialize(position:, velocity:, instant:, center:, target_body:) ⇒ ReferenceFrame
constructor
A new instance of ReferenceFrame.
-
#separation_from(other) ⇒ Astronoby::Angle
The angular separation, between 0° and 180°.
Constructor Details
#initialize(position:, velocity:, instant:, center:, target_body:) ⇒ ReferenceFrame
Returns a new instance of ReferenceFrame.
28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/astronoby/reference_frame.rb', line 28 def initialize( position:, velocity:, instant:, center:, target_body: ) @position = position @velocity = velocity @instant = instant @center = center @target_body = target_body end |
Instance Attribute Details
#center ⇒ Astronoby::Center (readonly)
Returns the center of the frame.
18 19 20 |
# File 'lib/astronoby/reference_frame.rb', line 18 def center @center end |
#instant ⇒ Astronoby::Instant (readonly)
Returns the time instant.
15 16 17 |
# File 'lib/astronoby/reference_frame.rb', line 15 def instant @instant end |
#position ⇒ Astronoby::Vector<Astronoby::Distance> (readonly)
Returns position vector.
9 10 11 |
# File 'lib/astronoby/reference_frame.rb', line 9 def position @position end |
#target_body ⇒ Astronoby::Body? (readonly)
Returns the target body.
21 22 23 |
# File 'lib/astronoby/reference_frame.rb', line 21 def target_body @target_body end |
#velocity ⇒ Astronoby::Vector<Astronoby::Velocity> (readonly)
Returns velocity vector.
12 13 14 |
# File 'lib/astronoby/reference_frame.rb', line 12 def velocity @velocity end |
Instance Method Details
#distance ⇒ Astronoby::Distance
Returns the Euclidean distance from the center.
64 65 66 67 68 69 70 |
# File 'lib/astronoby/reference_frame.rb', line 64 def distance @distance ||= begin return Distance.zero if @position.zero? @position.magnitude end end |
#ecliptic ⇒ Astronoby::Coordinates::Ecliptic
Returns ecliptic coordinates derived from the equatorial coordinates at J2000.0.
54 55 56 57 58 59 60 61 |
# File 'lib/astronoby/reference_frame.rb', line 54 def ecliptic @ecliptic ||= begin return Coordinates::Ecliptic.zero if distance.zero? j2000 = Instant.from_terrestrial_time(JulianDate::J2000) equatorial.to_ecliptic(instant: j2000) end end |
#equatorial ⇒ Astronoby::Coordinates::Equatorial
Returns equatorial coordinates derived from the position vector.
44 45 46 47 48 49 50 |
# File 'lib/astronoby/reference_frame.rb', line 44 def equatorial @equatorial ||= begin return Coordinates::Equatorial.zero if distance.zero? Coordinates::Equatorial.from_position_vector(@position) end end |
#separation_from(other) ⇒ Astronoby::Angle
Returns the angular separation, between 0° and 180°.
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/astronoby/reference_frame.rb', line 77 def separation_from(other) ensure_comparable!(other) return Angle.zero if @position.zero? || other.position.zero? position_vector = @position.map(&:m) other_position_vector = other.position.map(&:m) cross = Util::Maths.cross_product(position_vector, other_position_vector) cross_magnitude = Math.sqrt(Util::Maths.dot_product(cross, cross)) dot = Util::Maths.dot_product(position_vector, other_position_vector) Angle.from_radians(Math.atan2(cross_magnitude, dot)) end |