rhannequin / astronoby

Ruby library based on astronomy and astrometry books
https://dev.to/rhannequin/series/17782
MIT License
59 stars 2 forks source link

Handle Sun's sunrise and sunset azimuth #39

Closed rhannequin closed 8 months ago

rhannequin commented 8 months ago

Knowing when the Sun rises or sets is interesting, but it can also be interesting to know where on the horizon these events are going to happen.

The location of the Sun on the horizon's axis is the azimuth.

This change adds support of the computing the azimuth angle of the Sun's at sunrise and sunset.

Sun#rising_azimuth and Sun#setting_azimuth can return nil as the Sun sometimes never rises or never sets at some places on Earth, like locations close to the poles.

date = Date.new(2015, 2, 5)
epoch = Astronoby::Epoch.from_time(date)
observer = Astronoby::Observer.new(
  latitude: Astronoby::Angle.as_degrees(38),
  longitude: Astronoby::Angle.as_degrees(-78)
)
sun = Astronoby::Sun.new(epoch: epoch)

sun.setting_azimuth(observer: observer)&.str(:dms)