For my History of Engineering course, I was reading about how studying astronomy and mathematics helped early Muslims calculate prayer times. Since they did not have graphing calculators back then, large tables with precomputed values were used. I thought it would be interesting to make a program to calculate these times for a given location and date.

Here's what I have so far:


Code:
// |LAZAN:
// 1: Time zone
// 2: Longitude
// 3: Latitude
// 4: Elevation in meters
// 5: Fajr Angle
// 6: Isha Angle
// 7: Asr mode 1:obj+nshadow/2, 2:2*obj+nshadow/s
// 8: Maghrib mode: 0=Sunni, 1=Shia
// Presets:
// Mecca{3,39.826168,21.42251,300,18,17,1,0->|LAZAN
// Phoenix{~7,~112.074,33.4484,300,15,15,1,0->|LAZAN
// New York
{~4,~73.935,40.731,7,15,15,1,0->|LAZAN
Degree
Func
getDate->L1
getTime->L2
dbd(101,100*L1(3)+L1(2)+(L1(1)-2000)/100)+(L2(1)-|LAZAN(1)-12)/24->T //days since noon 1 Jan 2000 UTC
357.529+.98560028*T->G
280.459+.98564736*T->Q
Q+1.915sin(G)+.020sin(2G->L
1.00014-0.01671cos(G)-.00014cos(2G->R
23.439-36|E~8T->F
sin^-1(sin(F)sin(L->D  // declination of sun
Q/15-R>Ptheta(cos(L),cos(F)sin(L))/15->E // equation of time
// Dhuhr
12+|LAZAN(1)-|LAZAN(2)/15-E/3600->H
// T
"1/15*cos^-1((~sin(X)-sin(L)sin(D))/(cos(L)cos(D"->{Y1}
{Y1}(.833+.0347sqrt(|LAZAN(4->I
// Sunrise
H-I->A
// Sunset
H+I->B
// Fajr
H-{Y1}(~|LAZAN(5->F
// Isha
H+{Y1}(~|LAZAN(6->I
"1/15*cos^-1((sin(tan^-1((X+tan(L-D))^^-1))-sin(L)sin(D))/(cos(L)cos(D"->{Y2}
// Asr
1/tan(90-abs(|LAZAN(3)-D))->L
H+{Y2}(L/2+|LAZAN(7->S
// Maghrib
If |LAZAN(8
Then
   H+{Y1}(4->M
   Else
   B->M
End
// Midnight
12+.5(A+B
Ans-24(Ans>24->O
ClrHome
Disp "Fajr","Sunrise","Dhuhr","Asr","Sunset","Maghrib","Isha'a"
Output(8,1,"Midnight
{F,A,H,S,B,M,I,O->L1
For(N,1,8
   Output(N,10+(L1(N)<=9),int(L1(N
   Output(N,12,":0
   int(60fPart(L1(N
   Output(N,13+(Ans<=9),Ans
End
Pause




The user configurable settings are stored in ʟAZAN most importantly stores the current time zone, longitude, and latitude. Since different schools calculate the times slightly differently, the remaining elements allow the user to configure those options. I will add a setup menu to make configuring these settings easier in the future.

Most of the equations that I used can be found here. The equation stored in Y₁ calculates the time of day that the sun is at a particular angle. The equation in Y₂ calculates the time at which an object's shadow reaches a particular length. There is a slight error in the way PrayerTimes.org page says to use this equation since the shadow must not only be the length of the object - but the length of the object plus half its shadow length at noon. The shadow length at noon depends both on the declination of the sun and the latitude.

The calculated times seem to match pretty well with times from online prayer time calculators, but the Isha time is still pretty far off (~20 minutes). This could be because some calculators add extra time to this number to ensure that the Belt of Venus (red glow on opposite side of the sky) is no longer visible.

I have included three preconstructed lists with settings for Mecca, Phoenix, and New York. I selected the Fajr and Isha angles based on the conventions used by prominent Muslim organizations in those locations.
And then the clock was invented Very Happy
Battlesquid wrote:
And then the clock was invented Very Happy


In a way, this problem would have been easier before the invention of the clock. Since the sundial automatically adjusts for the actual position of the sun, there would be no need to calculate the difference between the apparent solar time (sundial) and mean solar time (clock). This is done with the "equation of time" in this program.
jonbush wrote:
Battlesquid wrote:
And then the clock was invented Very Happy


In a way, this problem would have been easier before the invention of the clock. Since the sundial automatically adjusts for the actual position of the sun, there would be no need to calculate the difference between the apparent solar time (sundial) and mean solar time (clock). This is done with the "equation of time" in this program.


That's true...perhaps someone could make a modern sundial based clock. I can imagine how I would do this; grab my Arduino then hook it up with a photocell and then program stuff for it. Something like that Razz
I added a configuration menu that appears during the first run (or whenever the config list has been deleted).

This is actually quite cool, I like the idea!
In SAX (as I am posting this), I saw you say that "The sunrise and sunset times should be accurate to within one minute for times within 200 years of 1 Jan 2000." (literally copied and pasted)

Why would it become inaccurate?
_iPhoenix_ wrote:
This is actually quite cool, I like the idea!
In SAX (as I am posting this), I saw you say that "The sunrise and sunset times should be accurate to within one minute for times within 200 years of 1 Jan 2000." (literally copied and pasted)

Why would it become inaccurate?


The approximation is already inaccurate; however, this level of inaccuracy is acceptable in this application. Due to the limited amount of precision in the constants and various phenomena that are not accounted for by this approximation, the calculated solar position gets farther off the further into the future or past you go.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement