Class: Astronoby::ReferenceFrame

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(position:, velocity:, instant:, center:, target_body:) ⇒ ReferenceFrame

Returns a new instance of ReferenceFrame.

Parameters:



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

#centerAstronoby::Center (readonly)

Returns the center of the frame.

Returns:



18
19
20
# File 'lib/astronoby/reference_frame.rb', line 18

def center
  @center
end

#instantAstronoby::Instant (readonly)

Returns the time instant.

Returns:



15
16
17
# File 'lib/astronoby/reference_frame.rb', line 15

def instant
  @instant
end

#positionAstronoby::Vector<Astronoby::Distance> (readonly)

Returns position vector.

Returns:



9
10
11
# File 'lib/astronoby/reference_frame.rb', line 9

def position
  @position
end

#target_bodyAstronoby::Body? (readonly)

Returns the target body.

Returns:



21
22
23
# File 'lib/astronoby/reference_frame.rb', line 21

def target_body
  @target_body
end

#velocityAstronoby::Vector<Astronoby::Velocity> (readonly)

Returns velocity vector.

Returns:



12
13
14
# File 'lib/astronoby/reference_frame.rb', line 12

def velocity
  @velocity
end

Instance Method Details

#distanceAstronoby::Distance

Returns the Euclidean distance from the center.

Returns:



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

#eclipticAstronoby::Coordinates::Ecliptic

Returns ecliptic coordinates derived from the equatorial coordinates at J2000.0.

Returns:



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

#equatorialAstronoby::Coordinates::Equatorial

Returns equatorial coordinates derived from the position vector.

Returns:



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°.

Parameters:

Returns:

Raises:



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