mourner / suncalc

A tiny JavaScript library for calculating sun/moon positions and phases.
BSD 2-Clause "Simplified" License
3.03k stars 408 forks source link

Sun position azimuth less than 0 #171

Open Jakub-Plan-d-k opened 1 year ago

Jakub-Plan-d-k commented 1 year ago

Hello, in the documentation it is stated that sunPosition.azimuth is an angle in radians calculated from south to west. Therefore I assumed the values should be between 0 and 2*PI, however this is apparently not the case. How should I interpret this angle then?

Steps to reproduce: run sunPosition with arguments: date: Date Wed Jun 21 2023 11:09:23 GMT+0200 (Central European Summer Time) latitude: 50.121110169781446 longitude: 8.768237964680083

Observe that azimuth is less than 0: sunPosition.azimuth -1.0092469987441774

For the record, the sun is around south-east in real world for those parameters I posted.

Phoscur commented 2 weeks ago

I'm having similar issues with the moon's azimuth from Europe: This month (June 2024), the moon sets in the west, but it azimuth values are far too low for that.

Concerning the sun, it's the same, it sets in the West but the azimuth is too low for that.

Edit: Wait... (thank you for quoting the docs, I did not see) "south to west"? That means I need to add 180° to the Azimuth.. and now it is not far from I what I expect anymore!

Phoscur commented 2 weeks ago

@Jakub-Plan-d-k and Copilot completed my comment:

const angle = azimuth * (180 / Math.PI) + 180 // azimuth needs to be converted from -180° to 180° to 0° to 360°

Does this explain your negative value?