Take the 2-minute tour ×
Astronomy Stack Exchange is a question and answer site for astronomers and astrophysicists. It's 100% free, no registration required.

I am trying to program a sunrise/sunset calculator using this formula tutorial.

If you follow the steps, eventually you get to this formula for "H" (the "hour angle"):

$H = \arccos( [\sin(-0.83) - \sin(ln) * \sin(δ)] / [\cos(ln) * \cos(δ)] )$

Which comes with a note attached:

Note: If H is undefined, then there is either no sunrise (in winter) or no sunset (in summer) for the supplied latitude.

Now, as it turns out, this happens quite often (because inverse cosine has a domain of -1 to 1). I ran a program and here are all of the dates where the H is defined from Jan 2008 through Dec 2014 (using a longitude west of -77.0368710 and latitude north of 38.9071920 [Washington D.C.]):

January 1 2008
January 3 2008
January 4 2008
January 11 2008
January 30 2008
******************************
February 5 2008
February 24 2008
******************************
March 2 2008
March 24 2008
March 25 2008
March 29 2008
March 31 2008
******************************
April 3 2008
April 4 2008
April 6 2008
April 11 2008
April 12 2008
April 13 2008
April 14 2008
April 17 2008
April 19 2008
April 22 2008
April 23 2008
April 25 2008
April 26 2008
April 30 2008
******************************
May 2 2008
May 3 2008
May 5 2008
May 6 2008
May 8 2008
May 14 2008
May 15 2008
May 19 2008
May 21 2008
May 24 2008
May 25 2008
May 27 2008
******************************
June 1 2008
June 2 2008
June 3 2008
June 4 2008
June 7 2008
June 9 2008
June 12 2008
June 13 2008
June 15 2008
June 16 2008
June 20 2008
June 22 2008
June 23 2008
June 25 2008
June 26 2008
June 28 2008
******************************
July 4 2008
July 5 2008
July 9 2008
July 11 2008
July 14 2008
July 15 2008
July 17 2008
July 22 2008
July 23 2008
July 24 2008
July 25 2008
July 28 2008
July 30 2008
******************************
August 2 2008
August 3 2008
August 5 2008
August 6 2008
August 10 2008
August 12 2008
August 13 2008
August 15 2008
August 16 2008
August 18 2008
August 24 2008
August 25 2008
August 29 2008
August 31 2008
******************************
September 3 2008
September 4 2008
September 6 2008
September 11 2008
September 12 2008
September 13 2008
September 14 2008
September 17 2008
September 19 2008
September 22 2008
September 23 2008
September 25 2008
September 26 2008
September 30 2008
******************************
October 2 2008
October 3 2008
October 5 2008
October 6 2008
October 8 2008
October 14 2008
October 15 2008
October 19 2008
October 21 2008
October 24 2008
October 25 2008
October 27 2008
******************************
November 1 2008
November 2 2008
November 3 2008
November 4 2008
November 7 2008
November 9 2008
November 12 2008
November 13 2008
November 15 2008
November 16 2008
November 20 2008
November 22 2008
November 23 2008
November 25 2008
November 26 2008
November 28 2008
******************************
December 4 2008
December 5 2008
December 9 2008
December 11 2008
December 14 2008
December 15 2008
December 17 2008
December 22 2008
December 23 2008
December 24 2008
December 25 2008
December 28 2008
December 30 2008
******************************
January 2 2009
January 3 2009
January 16 2009
January 23 2009
******************************
February 11 2009
February 17 2009
******************************
March 8 2009
March 15 2009
March 23 2009
March 25 2009
March 26 2009
March 28 2009
March 29 2009
March 31 2009
******************************
April 6 2009
April 7 2009
April 11 2009
April 13 2009
April 16 2009
April 17 2009
April 19 2009
April 24 2009
April 25 2009
April 26 2009
April 27 2009
April 30 2009
******************************
May 2 2009
May 5 2009
May 6 2009
May 8 2009
May 9 2009
May 13 2009
May 15 2009
May 16 2009
May 18 2009
May 19 2009
May 21 2009
May 27 2009
May 28 2009
******************************
June 1 2009
June 3 2009
June 6 2009
June 7 2009
June 9 2009
June 14 2009
June 15 2009
June 16 2009
June 17 2009
June 20 2009
June 22 2009
June 25 2009
June 26 2009
June 28 2009
June 29 2009
******************************
July 3 2009
July 5 2009
July 6 2009
July 8 2009
July 9 2009
July 11 2009
July 17 2009
July 18 2009
July 22 2009
July 24 2009
July 27 2009
July 28 2009
July 30 2009
******************************
August 4 2009
August 5 2009
August 6 2009
August 7 2009
August 10 2009
August 12 2009
August 15 2009
August 16 2009
August 18 2009
August 19 2009
August 23 2009
August 25 2009
August 26 2009
August 28 2009
August 29 2009
August 31 2009
******************************
September 6 2009
September 7 2009
September 11 2009
September 13 2009
September 16 2009
September 17 2009
September 19 2009
September 24 2009
September 25 2009
September 26 2009
September 27 2009
September 30 2009
******************************
October 2 2009
October 5 2009
October 6 2009
October 8 2009
October 9 2009
October 13 2009
October 15 2009
October 16 2009
October 18 2009
October 19 2009
October 21 2009
October 27 2009
October 28 2009
******************************
November 1 2009
November 3 2009
November 6 2009
November 7 2009
November 9 2009
November 14 2009
November 15 2009
November 16 2009
November 17 2009
November 20 2009
November 22 2009
November 25 2009
November 26 2009
November 28 2009
November 29 2009
******************************
December 3 2009
December 5 2009
December 6 2009
December 8 2009
December 9 2009
December 11 2009
December 17 2009
December 18 2009
December 22 2009
December 24 2009
December 27 2009
December 28 2009
December 30 2009
******************************
January 4 2010
January 10 2010
January 17 2010
January 29 2010
******************************
February 5 2010
February 24 2010
******************************
March 2 2010
March 9 2010
March 21 2010
March 23 2010
March 25 2010
March 28 2010
March 29 2010
March 31 2010
******************************
April 1 2010
April 5 2010
April 7 2010
April 8 2010
April 10 2010
April 11 2010
April 13 2010
April 19 2010
April 20 2010
April 24 2010
April 26 2010
April 29 2010
April 30 2010
******************************
May 2 2010
May 7 2010
May 8 2010
May 9 2010
May 10 2010
May 13 2010
May 15 2010
May 18 2010
May 19 2010
May 21 2010
May 22 2010
May 26 2010
May 28 2010
May 29 2010
May 31 2010
******************************
June 1 2010
June 3 2010
June 9 2010
June 10 2010
June 14 2010
June 16 2010
June 19 2010
June 20 2010
June 22 2010
June 27 2010
June 28 2010
June 29 2010
June 30 2010
******************************
July 3 2010
July 5 2010
July 8 2010
July 9 2010
July 11 2010
July 12 2010
July 16 2010
July 18 2010
July 19 2010
July 21 2010
July 22 2010
July 24 2010
July 30 2010
July 31 2010
******************************
August 4 2010
August 6 2010
August 9 2010
August 10 2010
August 12 2010
August 17 2010
August 18 2010
August 19 2010
August 20 2010
August 23 2010
August 25 2010
August 28 2010
August 29 2010
August 31 2010
******************************
September 1 2010
September 5 2010
September 7 2010
September 8 2010
September 10 2010
September 11 2010
September 13 2010
September 19 2010
September 20 2010
September 24 2010
September 26 2010
September 29 2010
September 30 2010
******************************
October 2 2010
October 7 2010
October 8 2010
October 9 2010
October 10 2010
October 13 2010
October 15 2010
October 18 2010
October 19 2010
October 21 2010
October 22 2010
October 26 2010
October 28 2010
October 29 2010
October 31 2010
******************************
November 1 2010
November 3 2010
November 9 2010
November 10 2010
November 14 2010
November 16 2010
November 19 2010
November 20 2010
November 22 2010
November 27 2010
November 28 2010
November 29 2010
November 30 2010
******************************
December 3 2010
December 5 2010
December 8 2010
December 9 2010
December 11 2010
December 12 2010
December 16 2010
December 18 2010
December 19 2010
December 21 2010
December 22 2010
December 24 2010
December 30 2010
December 31 2010
******************************
January 17 2011
January 23 2011
January 30 2011
******************************
February 11 2011
February 18 2011
******************************
March 9 2011
March 15 2011
March 22 2011
March 23 2011
March 25 2011
March 30 2011
March 31 2011
******************************
April 1 2011
April 2 2011
April 5 2011
April 7 2011
April 10 2011
April 11 2011
April 13 2011
April 14 2011
April 18 2011
April 20 2011
April 21 2011
April 23 2011
April 24 2011
April 26 2011
******************************
May 2 2011
May 3 2011
May 7 2011
May 9 2011
May 12 2011
May 13 2011
May 15 2011
May 20 2011
May 21 2011
May 22 2011
May 23 2011
May 26 2011
May 28 2011
May 31 2011
******************************
June 1 2011
June 3 2011
June 4 2011
June 8 2011
June 10 2011
June 11 2011
June 13 2011
June 14 2011
June 16 2011
June 22 2011
June 23 2011
June 27 2011
June 29 2011
******************************
July 2 2011
July 3 2011
July 5 2011
July 10 2011
July 11 2011
July 12 2011
July 13 2011
July 16 2011
July 18 2011
July 21 2011
July 22 2011
July 24 2011
July 25 2011
July 29 2011
July 31 2011
******************************
August 1 2011
August 3 2011
August 4 2011
August 6 2011
August 12 2011
August 13 2011
August 17 2011
August 19 2011
August 22 2011
August 23 2011
August 25 2011
August 30 2011
August 31 2011
******************************
September 1 2011
September 2 2011
September 5 2011
September 7 2011
September 10 2011
September 11 2011
September 13 2011
September 14 2011
September 18 2011
September 20 2011
September 21 2011
September 23 2011
September 24 2011
September 26 2011
******************************
October 2 2011
October 3 2011
October 7 2011
October 9 2011
October 12 2011
October 13 2011
October 15 2011
October 20 2011
October 21 2011
October 22 2011
October 23 2011
October 26 2011
October 28 2011
October 31 2011
******************************
November 1 2011
November 3 2011
November 4 2011
November 8 2011
November 10 2011
November 11 2011
November 13 2011
November 14 2011
November 16 2011
November 22 2011
November 23 2011
November 27 2011
November 29 2011
******************************
December 2 2011
December 3 2011
December 5 2011
December 10 2011
December 11 2011
December 12 2011
December 13 2011
December 16 2011
December 18 2011
December 21 2011
December 22 2011
December 24 2011
December 25 2011
December 29 2011
December 31 2011
******************************
January 1 2012
January 3 2012
January 4 2012
January 11 2012
January 30 2012
******************************
February 5 2012
February 12 2012
February 24 2012
******************************
March 2 2012
March 24 2012
March 25 2012
March 26 2012
March 29 2012
March 31 2012
******************************
April 3 2012
April 4 2012
April 6 2012
April 11 2012
April 12 2012
April 13 2012
April 14 2012
April 17 2012
April 19 2012
April 22 2012
April 23 2012
April 25 2012
April 26 2012
April 30 2012
******************************
May 2 2012
May 3 2012
May 5 2012
May 6 2012
May 8 2012
May 14 2012
May 15 2012
May 16 2012
May 19 2012
May 21 2012
May 24 2012
May 25 2012
May 27 2012
******************************
June 1 2012
June 2 2012
June 3 2012
June 4 2012
June 7 2012
June 9 2012
June 12 2012
June 13 2012
June 15 2012
June 16 2012
June 20 2012
June 22 2012
June 23 2012
June 25 2012
June 26 2012
June 28 2012
******************************
July 4 2012
July 5 2012
July 6 2012
July 9 2012
July 11 2012
July 14 2012
July 15 2012
July 17 2012
July 22 2012
July 23 2012
July 24 2012
July 25 2012
July 28 2012
July 30 2012
******************************
August 2 2012
August 3 2012
August 5 2012
August 6 2012
August 10 2012
August 12 2012
August 13 2012
August 15 2012
August 16 2012
August 18 2012
August 24 2012
August 25 2012
August 26 2012
August 29 2012
August 31 2012
******************************
September 3 2012
September 4 2012
September 6 2012
September 11 2012
September 12 2012
September 13 2012
September 14 2012
September 17 2012
September 19 2012
September 22 2012
September 23 2012
September 25 2012
September 26 2012
September 30 2012
******************************
October 2 2012
October 3 2012
October 5 2012
October 6 2012
October 8 2012
October 14 2012
October 15 2012
October 16 2012
October 19 2012
October 21 2012
October 24 2012
October 25 2012
October 27 2012
******************************
November 1 2012
November 2 2012
November 3 2012
November 4 2012
November 7 2012
November 9 2012
November 12 2012
November 13 2012
November 15 2012
November 16 2012
November 20 2012
November 22 2012
November 23 2012
November 25 2012
November 26 2012
November 28 2012
******************************
December 4 2012
December 5 2012
December 6 2012
December 9 2012
December 11 2012
December 14 2012
December 15 2012
December 17 2012
December 22 2012
December 23 2012
December 24 2012
December 25 2012
December 28 2012
December 30 2012
******************************
January 2 2013
January 3 2013
January 4 2013
January 16 2013
January 23 2013
******************************
February 11 2013
February 17 2013
February 24 2013
******************************
March 8 2013
March 15 2013
March 23 2013
March 25 2013
March 26 2013
March 28 2013
March 29 2013
March 31 2013
******************************
April 6 2013
April 7 2013
April 8 2013
April 11 2013
April 13 2013
April 16 2013
April 17 2013
April 19 2013
April 24 2013
April 25 2013
April 26 2013
April 27 2013
April 30 2013
******************************
May 2 2013
May 6 2013
May 8 2013
May 9 2013
May 13 2013
May 15 2013
May 16 2013
May 18 2013
May 19 2013
May 21 2013
May 27 2013
May 28 2013
May 29 2013
******************************
June 1 2013
June 3 2013
June 6 2013
June 7 2013
June 9 2013
June 14 2013
June 15 2013
June 16 2013
June 17 2013
June 20 2013
June 22 2013
June 26 2013
June 28 2013
June 29 2013
******************************
July 3 2013
July 5 2013
July 6 2013
July 8 2013
July 9 2013
July 11 2013
July 17 2013
July 18 2013
July 19 2013
July 22 2013
July 24 2013
July 27 2013
July 28 2013
July 30 2013
******************************
August 4 2013
August 5 2013
August 6 2013
August 7 2013
August 10 2013
August 12 2013
August 16 2013
August 18 2013
August 19 2013
August 23 2013
August 25 2013
August 26 2013
August 28 2013
August 29 2013
August 31 2013
******************************
September 6 2013
September 7 2013
September 8 2013
September 11 2013
September 13 2013
September 16 2013
September 17 2013
September 19 2013
September 24 2013
September 25 2013
September 26 2013
September 27 2013
September 30 2013
******************************
October 2 2013
October 6 2013
October 8 2013
October 9 2013
October 13 2013
October 15 2013
October 16 2013
October 18 2013
October 19 2013
October 21 2013
October 27 2013
October 28 2013
October 29 2013
******************************
November 1 2013
November 3 2013
November 6 2013
November 7 2013
November 9 2013
November 14 2013
November 15 2013
November 16 2013
November 17 2013
November 20 2013
November 22 2013
November 26 2013
November 28 2013
November 29 2013
******************************
December 3 2013
December 5 2013
December 6 2013
December 8 2013
December 9 2013
December 11 2013
December 17 2013
December 18 2013
December 19 2013
December 22 2013
December 24 2013
December 27 2013
December 28 2013
December 30 2013
******************************
January 4 2014
January 10 2014
January 17 2014
January 29 2014
******************************
February 5 2014
February 24 2014
******************************
March 2 2014
March 9 2014
March 21 2014
March 23 2014
March 25 2014
March 29 2014
March 31 2014
******************************
April 1 2014
April 5 2014
April 7 2014
April 8 2014
April 10 2014
April 11 2014
April 13 2014
April 19 2014
April 20 2014
April 21 2014
April 24 2014
April 26 2014
April 29 2014
April 30 2014
******************************
May 2 2014
May 7 2014
May 8 2014
May 9 2014
May 10 2014
May 13 2014
May 15 2014
May 19 2014
May 21 2014
May 22 2014
May 26 2014
May 28 2014
May 29 2014
May 31 2014
******************************
June 1 2014
June 3 2014
June 9 2014
June 10 2014
June 11 2014
June 14 2014
June 16 2014
June 19 2014
June 20 2014
June 22 2014
June 27 2014
June 28 2014
June 29 2014
June 30 2014
******************************
July 3 2014
July 5 2014
July 9 2014
July 11 2014
July 12 2014
July 16 2014
July 18 2014
July 19 2014
July 21 2014
July 22 2014
July 24 2014
July 30 2014
July 31 2014
******************************
August 1 2014
August 4 2014
August 6 2014
August 9 2014
August 10 2014
August 12 2014
August 17 2014
August 18 2014
August 19 2014
August 20 2014
August 23 2014
August 25 2014
August 29 2014
August 31 2014
******************************
September 1 2014
September 5 2014
September 7 2014
September 8 2014
September 10 2014
September 11 2014
September 13 2014
September 19 2014
September 20 2014
September 21 2014
September 24 2014
September 26 2014
September 29 2014
September 30 2014
******************************
October 2 2014
October 7 2014
October 8 2014
October 9 2014
October 10 2014
October 13 2014
October 15 2014
October 19 2014
October 21 2014
October 22 2014
October 26 2014
October 28 2014
October 29 2014
October 31 2014
******************************
November 1 2014
November 3 2014
November 9 2014
November 10 2014
November 11 2014
November 14 2014
November 16 2014
November 19 2014
November 20 2014
November 22 2014
November 27 2014
November 28 2014
November 29 2014
November 30 2014
******************************
December 3 2014
December 5 2014
December 9 2014
December 11 2014
December 12 2014
December 16 2014
December 18 2014
December 19 2014
December 21 2014
December 22 2014
December 24 2014
December 30 2014
December 31 2014

You'll notice there are quite a lot of dates where H (the hour angle) is undefined. I understand from a trigonometric standpoint why it is incalculable, but is there a scientific reason for this? Also, how do they calculate when the sun will set and when the sun will rise on those days? Is it an average of the last known date and the next known date?

What is the hour angle, exactly, and how do you calculate the sunrise/sunset if you can't calculate it?

share|improve this question

1 Answer 1

Did you consider the degree to radian conversion and vice versa? There seems to be something like that happening. Note that -0.83 is in degrees - which is the correction for the size of the sun and refraction effects at horizon. (More details here: https://en.wikipedia.org/wiki/Sunrise_equation) At latitude 38 N, there shouldn't be any day where sunrise/sunset is not defined.

Also, Hour Angle at any time is the time since culmination (culmination is the passing of a body through the meridian; meridian is the great circle passing through the North cardinal point, North Pole, Zenith and South cardinal point. In this case, Hour Angle gives the time between sunrise and noon (i.e. culmination of the sun), or noon and sunset.

share|improve this answer
    
Yes thank you. Later I realized what the note is saying exactly: At certain latitudes (South Pole, North Pole), there are days with no sunrise (winter) and no sunset (summer). It wasn't clear at first, but now I see what you're saying. The hour angle should never be undefined for certain latitudes. –  ryvantage Jul 12 at 12:40
    
So, my calculations are inaccurate somewhere. –  ryvantage Jul 12 at 12:41
    
No, I did not consider any degree vs radian offset. Do you think I should convert the degrees to radians for my calculations? –  ryvantage Jul 12 at 12:41
    
Ok so when it says "mod 360", should that be "mod $2\pi$? –  ryvantage Jul 12 at 12:55
    
Arccos will give output in radians. Similarly cos usually will take input in radians. So, you should change everything to radians for convenience. Any $\theta$ in degrees then becomes $\theta\times\pi/180$ in radians. (A simple multiplicative factor. This should also sort out the mod factor.) –  Takku Jul 12 at 13:07

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.