Class: Astronoby::Coordinates::Horizontal

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/coordinates/horizontal.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(azimuth:, altitude:, observer:) ⇒ Horizontal

Returns a new instance of Horizontal.



8
9
10
11
12
13
14
15
16
# File 'lib/astronoby/coordinates/horizontal.rb', line 8

def initialize(
  azimuth:,
  altitude:,
  observer:
)
  @azimuth = azimuth
  @altitude = altitude
  @observer = observer
end

Instance Attribute Details

#altitudeObject (readonly)

Returns the value of attribute altitude.



6
7
8
# File 'lib/astronoby/coordinates/horizontal.rb', line 6

def altitude
  @altitude
end

#azimuthObject (readonly)

Returns the value of attribute azimuth.



6
7
8
# File 'lib/astronoby/coordinates/horizontal.rb', line 6

def azimuth
  @azimuth
end

#observerObject (readonly)

Returns the value of attribute observer.



6
7
8
# File 'lib/astronoby/coordinates/horizontal.rb', line 6

def observer
  @observer
end

Instance Method Details

#to_equatorial(time:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/astronoby/coordinates/horizontal.rb', line 18

def to_equatorial(time:)
  t0 = @altitude.sin * latitude.sin +
    @altitude.cos * latitude.cos * @azimuth.cos

  declination = Angle.asin(t0)

  t1 = @altitude.sin - latitude.sin * declination.sin

  hour_angle_degrees = Angle
    .acos(t1 / (latitude.cos * declination.cos))
    .degrees

  if @azimuth.sin.positive?
    hour_angle_degrees = Angle
      .from_degrees(Constants::DEGREES_PER_CIRCLE - hour_angle_degrees)
      .degrees
  end

  hour_angle_hours = Angle.from_degrees(hour_angle_degrees).hours
  lst = GreenwichSiderealTime
    .from_utc(time.utc)
    .to_lst(longitude: longitude)
  right_ascension_decimal = lst.time - hour_angle_hours

  if right_ascension_decimal.negative?
    right_ascension_decimal += Constants::HOURS_PER_DAY
  end

  right_ascension = Angle.from_hours(right_ascension_decimal)

  Equatorial.new(
    right_ascension: right_ascension,
    declination: declination
  )
end