Horizontal sundial calculations: Difference between revisions

Added FutureBasic example
m (another small bit of explanation)
(Added FutureBasic example)
Line 788:
 
end program SunDial</lang>
 
 
=={{header|FutureBasic}}==
<lang futurebasic>
include "ConsoleWindow"
 
local fn rad2deg( theta as double ) as double
end fn = theta * 180 / pi
 
local fn deg2rad( theta as double ) as double
end fn = theta * pi / 180
 
local fn SolarHourAngle( latitude as double, longitude as double, meridian as double )
dim as long hour
dim as double hra, hla, time
dim as Str15 ap
 
print "Latitude = "; latitude; chr$(13); "Longitude = "; longitude; chr$(13); "Meridian = "; meridian
print : print "sine of Latitude:"; sin(latitude * pi / 180 ); chr$(13), "diff longitude: "; longitude - meridian
print : print "Time", "Sun hour angle", "Dial hour line angle"
for hour = 6 to 18
hra = ( 15 * hour ) - longitude + meridian - 180
hla = fn rad2deg( atn( sin( fn deg2rad( latitude ) ) * tan( fn deg2rad( hra ) )))
if abs( hra ) > 90 then hla = hla + 180 * sgn( hra * latitude )
if hour > 12 then time = hour - 12 : ap = " a.m." else time = hour : ap = " p.m."
print using "##"; time; ap, using "####.##"; hra, using "####.###"; hla
next hour
end fn
fn SolarHourAngle( -4.95, -150.5, -150.0 )
</lang>
 
Output:
<pre>
Latitude = -4.95
Longitude = -150.5
Meridian = -150
 
sine of Latitude:-0.0862863658
diff longitude: -0.5
 
Time Sun hour angle Dial hour line angle
6 p.m. -89.50 84.225
7 p.m. -74.50 17.283
8 p.m. -59.50 8.334
9 p.m. -44.50 4.847
10 p.m. -29.50 2.795
11 p.m. -14.50 1.278
12 p.m. 0.50 -0.043
1 a.m. 15.50 -1.371
2 a.m. 30.50 -2.910
3 a.m. 45.50 -5.018
4 a.m. 60.50 -8.671
5 a.m. 75.50 -18.451
6 a.m. 90.50 -95.775
</pr>
 
=={{header|Go}}==
729

edits