Class: Astronoby::Sun

Inherits:
Object
  • Object
show all
Defined in:
lib/astronoby/bodies/sun.rb

Constant Summary collapse

SEMI_MAJOR_AXIS_IN_METERS =
149_598_500_000
ANGULAR_DIAMETER =
Angle.from_degrees(0.533128)
INTERPOLATION_FACTOR =
BigDecimal("24.07")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(epoch:) ⇒ Sun

Returns a new instance of Sun.

Parameters:

  • epoch (Numeric)

    Considered epoch, in Julian days



40
41
42
# File 'lib/astronoby/bodies/sun.rb', line 40

def initialize(epoch:)
  @epoch = epoch
end

Class Method Details

.equation_of_time(date:) ⇒ Integer

Returns Equation of time in seconds.

Parameters:

  • date (Date)

    Requested date

Returns:

  • (Integer)

    Equation of time in seconds



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/astronoby/bodies/sun.rb', line 17

def self.equation_of_time(date:)
  noon = Time.utc(date.year, date.month, date.day, 12)
  epoch_at_noon = Epoch.from_time(noon)
  sun_at_noon = new(epoch: epoch_at_noon)
  equatorial_hours = sun_at_noon
    .apparent_ecliptic_coordinates
    .to_apparent_equatorial(epoch: epoch_at_noon)
    .right_ascension
    .hours
  gst = GreenwichSiderealTime
    .new(date: date, time: equatorial_hours)
    .to_utc

  (noon - gst).to_i
end

Instance Method Details

#angular_sizeAstronoby::Angle

Returns Apparent Sun’s angular size.

Returns:



138
139
140
141
142
# File 'lib/astronoby/bodies/sun.rb', line 138

def angular_size
  Angle.from_degrees(
    ANGULAR_DIAMETER.degrees * distance_angular_size_factor
  )
end

#apparent_ecliptic_coordinatesObject



51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/astronoby/bodies/sun.rb', line 51

def apparent_ecliptic_coordinates
  nutation = Nutation.for_ecliptic_longitude(epoch: @epoch)
  longitude_with_aberration = Aberration.for_ecliptic_coordinates(
    coordinates: true_ecliptic_coordinates,
    epoch: @epoch
  ).longitude
  apparent_longitude = nutation + longitude_with_aberration

  Coordinates::Ecliptic.new(
    latitude: Angle.zero,
    longitude: apparent_longitude
  )
end

#earth_distanceNumeric

Returns Earth-Sun distance in meters.

Returns:

  • (Numeric)

    Earth-Sun distance in meters



133
134
135
# File 'lib/astronoby/bodies/sun.rb', line 133

def earth_distance
  SEMI_MAJOR_AXIS_IN_METERS / distance_angular_size_factor
end

#horizontal_coordinates(latitude:, longitude:) ⇒ Astronoby::Coordinates::Horizontal

Computes the Sun’s horizontal coordinates

Parameters:

Returns:



70
71
72
73
74
75
76
# File 'lib/astronoby/bodies/sun.rb', line 70

def horizontal_coordinates(latitude:, longitude:)
  time = Epoch.to_utc(@epoch)

  apparent_ecliptic_coordinates
    .to_apparent_equatorial(epoch: @epoch)
    .to_horizontal(time: time, latitude: latitude, longitude: longitude)
end

#longitude_at_perigeeAstronoby::Angle

Returns Sun’s longitude at perigee.

Returns:



161
162
163
164
165
# File 'lib/astronoby/bodies/sun.rb', line 161

def longitude_at_perigee
  Angle.from_degrees(
    (281.2208444 + 1.719175 * centuries + 0.000452778 * centuries**2) % 360
  )
end

#orbital_eccentricityAstronoby::Angle

Returns Sun’s orbital eccentricity.

Returns:



168
169
170
171
172
# File 'lib/astronoby/bodies/sun.rb', line 168

def orbital_eccentricity
  Angle.from_degrees(
    (0.01675104 - 0.0000418 * centuries - 0.000000126 * centuries**2) % 360
  )
end

#rising_azimuth(observer:) ⇒ Astronoby::Angle?

Returns Azimuth of sunrise.

Parameters:

Returns:



96
97
98
99
100
101
102
103
# File 'lib/astronoby/bodies/sun.rb', line 96

def rising_azimuth(observer:)
  equatorial_coordinates = apparent_ecliptic_coordinates
    .to_apparent_equatorial(epoch: @epoch)
  Body.new(equatorial_coordinates).rising_azimuth(
    latitude: observer.latitude,
    vertical_shift: vertical_shift
  )
end

#rising_time(observer:) ⇒ Time

Returns Time of sunrise.

Parameters:

Returns:

  • (Time)

    Time of sunrise



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/astronoby/bodies/sun.rb', line 80

def rising_time(observer:)
  event_date = Epoch.to_utc(@epoch).to_date
  lst1 = event_local_sidereal_time_for_date(event_date, observer, :rising)
  next_day = event_date.next_day(1)
  lst2 = event_local_sidereal_time_for_date(next_day, observer, :rising)
  time = (INTERPOLATION_FACTOR * lst1) / (INTERPOLATION_FACTOR + lst1 - lst2)

  LocalSiderealTime.new(
    date: event_date,
    time: time,
    longitude: observer.longitude
  ).to_gst.to_utc
end

#setting_azimuth(observer:) ⇒ Astronoby::Angle?

Returns Azimuth of sunset.

Parameters:

Returns:



123
124
125
126
127
128
129
130
# File 'lib/astronoby/bodies/sun.rb', line 123

def setting_azimuth(observer:)
  equatorial_coordinates = apparent_ecliptic_coordinates
    .to_apparent_equatorial(epoch: @epoch)
  Body.new(equatorial_coordinates).setting_azimuth(
    latitude: observer.latitude,
    vertical_shift: vertical_shift
  )
end

#setting_time(observer:) ⇒ Time

Returns Time of sunset.

Parameters:

Returns:

  • (Time)

    Time of sunset



107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/astronoby/bodies/sun.rb', line 107

def setting_time(observer:)
  event_date = Epoch.to_utc(@epoch).to_date
  lst1 = event_local_sidereal_time_for_date(event_date, observer, :setting)
  next_day = event_date.next_day(1)
  lst2 = event_local_sidereal_time_for_date(next_day, observer, :setting)
  time = (INTERPOLATION_FACTOR * lst1) / (INTERPOLATION_FACTOR + lst1 - lst2)

  LocalSiderealTime.new(
    date: event_date,
    time: time,
    longitude: observer.longitude
  ).to_gst.to_utc
end

#true_anomalyAstronoby::Angle

Returns Sun’s true anomaly.

Returns:



145
146
147
148
149
150
151
152
153
154
155
156
157
158
# File 'lib/astronoby/bodies/sun.rb', line 145

def true_anomaly
  eccentric_anomaly = Util::Astrodynamics.eccentric_anomaly_newton_raphson(
    mean_anomaly,
    orbital_eccentricity.degrees,
    2e-06,
    10
  )

  tan = Math.sqrt(
    (1 + orbital_eccentricity.degrees) / (1 - orbital_eccentricity.degrees)
  ) * Math.tan(eccentric_anomaly.radians / 2)

  Angle.from_degrees((Angle.atan(tan).degrees * 2) % 360)
end

#true_ecliptic_coordinatesObject



44
45
46
47
48
49
# File 'lib/astronoby/bodies/sun.rb', line 44

def true_ecliptic_coordinates
  Coordinates::Ecliptic.new(
    latitude: Angle.zero,
    longitude: true_longitude
  )
end