0% found this document useful (0 votes)
24 views

Sunrise Sunset Algorithm

The document describes an algorithm for calculating sunrise and sunset times given the date, latitude and longitude of a location. It involves multiple steps of calculating variables like the sun's mean anomaly, true longitude, right ascension and declination before determining the local hour angle and converting to the local time.

Uploaded by

patelshishir
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views

Sunrise Sunset Algorithm

The document describes an algorithm for calculating sunrise and sunset times given the date, latitude and longitude of a location. It involves multiple steps of calculating variables like the sun's mean anomaly, true longitude, right ascension and declination before determining the local hour angle and converting to the local time.

Uploaded by

patelshishir
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Sunrise/SunsetAlgorithm

S o u r c e : A l m a n a cf o rC o m p u t e r s ,1 9 9 0 p u b l i s h e db yN a u t i c a lA l m a n a cO f f i c e U n i t e dS t a t e sN a v a lO b s e r v a t o r y W a s h i n g t o n ,D C2 0 3 9 2 d a y ,m o n t h ,y e a r : d a t eo fs u n r i s e / s u n s e t l a t i t u d e ,l o n g i t u d e : l o c a t i o nf o rs u n r i s e / s u n s e t z e n i t h : S u n ' sz e n i t hf o rs u n r i s e / s u n s e t o f f i c a l =9 0d e g r e e s5 0 ' c i v i l =9 6d e g r e e s n a u t i c a l =1 0 2d e g r e e s a s t r o n o m i c a l=1 0 8d e g r e e s N O T E :l o n g i t u d ei sp o s i t i v ef o rE a s ta n dn e g a t i v ef o rW e s t N O T E :t h ea l g o r i t h ma s s u m e st h eu s eo fac a l c u l a t o rw i t ht h e t r i gf u n c t i o n si n" d e g r e e "( r a t h e rt h a n" r a d i a n " )m o d e .M o s t p r o g r a m m i n gl a n g u a g e sa s s u m er a d i a na r g u m e n t s ,r e q u i r i n gb a c k a n df o r t hc o n v e r t i o n s .T h ef a c t o ri s1 8 0 / p i .S o ,f o ri n s t a n c e , t h ee q u a t i o nR A=a t a n ( 0 . 9 1 7 6 4*t a n ( L ) )w o u l db ec o d e da sR A =( 1 8 0 / p i ) * a t a n ( 0 . 9 1 7 6 4*t a n ( ( p i / 1 8 0 ) * L ) )t og i v ead e g r e e a n s w e rw i t had e g r e ei n p u tf o rL . 1 .f i r s tc a l c u l a t et h ed a yo ft h ey e a r N 1=f l o o r ( 2 7 5*m o n t h/9 ) N 2=f l o o r ( ( m o n t h+9 )/1 2 ) N 3=( 1+f l o o r ( ( y e a r-4*f l o o r ( y e a r/4 )+2 )/3 ) ) N=N 1-( N 2*N 3 )+d a y-3 0 2 .c o n v e r tt h el o n g i t u d et oh o u rv a l u ea n dc a l c u l a t ea na p p r o x i m a t et i m e l n g H o u r=l o n g i t u d e/1 5 i fr i s i n gt i m ei sd e s i r e d : t=N+( ( 6-l n g H o u r )/2 4 ) i fs e t t i n gt i m ei sd e s i r e d : t=N+( ( 1 8-l n g H o u r )/2 4 ) 3 .c a l c u l a t et h eS u n ' sm e a na n o m a l y M=( 0 . 9 8 5 6*t )-3 . 2 8 9 4 .c a l c u l a t et h eS u n ' st r u el o n g i t u d e L=M+( 1 . 9 1 6*s i n ( M ) )+( 0 . 0 2 0*s i n ( 2*M ) )+2 8 2 . 6 3 4 N O T E :Lp o t e n t i a l l yn e e d st ob ea d j u s t e di n t ot h er a n g e[ 0 , 3 6 0 )b ya d d i n g / s u b t r a c t i n g3 6 0 5 a .c a l c u l a t et h eS u n ' sr i g h ta s c e n s i o n R A=a t a n ( 0 . 9 1 7 6 4*t a n ( L ) ) N O T E :R Ap o t e n t i a l l yn e e d st ob ea d j u s t e di n t ot h er a n g e[ 0 , 3 6 0 )b ya d d i n g / s u b t r a c t i n g3 6 0 5 b .r i g h ta s c e n s i o nv a l u en e e d st ob ei nt h es a m eq u a d r a n ta sL L q u a d r a n t =( f l o o r (L / 9 0 ) )*9 0 R A q u a d r a n t=( f l o o r ( R A / 9 0 ) )*9 0 R A=R A+( L q u a d r a n t-R A q u a d r a n t ) 5 c .r i g h ta s c e n s i o nv a l u en e e d st ob ec o n v e r t e di n t oh o u r s R A=R A/1 5 6 .c a l c u l a t et h eS u n ' sd e c l i n a t i o n s i n D e c=0 . 3 9 7 8 2*s i n ( L ) c o s D e c=c o s ( a s i n ( s i n D e c ) ) 7 a .c a l c u l a t et h eS u n ' sl o c a lh o u ra n g l e

I n p u t s :

c o s H=( c o s ( z e n i t h )-( s i n D e c*s i n ( l a t i t u d e ) ) )/( c o s D e c*c o s ( l a t i t u d e ) ) i f( c o s H> 1 ) t h es u nn e v e rr i s e so nt h i sl o c a t i o n( o nt h es p e c i f i e dd a t e ) i f( c o s H<1 ) t h es u nn e v e rs e t so nt h i sl o c a t i o n( o nt h es p e c i f i e dd a t e ) 7 b .f i n i s hc a l c u l a t i n gHa n dc o n v e r ti n t oh o u r s i fi fr i s i n gt i m ei sd e s i r e d : H=3 6 0-a c o s ( c o s H ) i fs e t t i n gt i m ei sd e s i r e d : H=a c o s ( c o s H ) H=H/1 5 8 .c a l c u l a t el o c a lm e a nt i m eo fr i s i n g / s e t t i n g T=H+R A-( 0 . 0 6 5 7 1*t )-6 . 6 2 2 9 .a d j u s tb a c kt oU T C U T=T-l n g H o u r N O T E :U Tp o t e n t i a l l yn e e d st ob ea d j u s t e di n t ot h er a n g e[ 0 , 2 4 )b ya d d i n g / s u b t r a c t i n g2 4 1 0 .c o n v e r tU Tv a l u et ol o c a lt i m ez o n eo fl a t i t u d e / l o n g i t u d e l o c a l T=U T+l o c a l O f f s e t

You might also like