Jump to content

Horizontal sundial calculations: Difference between revisions

added python
(→‎{{header|PureBasic}}: Added PureBasic)
(added python)
Line 140:
Define.f hra, hla
hra=15*h
hra=hra-(lng-ref)
hla=ATan(slat*Tan(hra*2*#PI/360))*360/(2*#PI)
PrintN("HR="+RSet(Str(h),3)+"; HRA="+RSet(StrF(hra,3),7)+"; HLA="+RSet(StrF(hla,3),7))
Line 147:
EndIf</lang>
<pre>Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
 
sine of latitude: -0.086
diff longitude: -0.500
 
Hour, sun hour angle, dial hour line angle from 6am to 6pm
HR= -6; HRA=-89.500; HLA= 84.225
HR= -5; HRA=-74.500; HLA= 17.283
HR= -4; HRA=-59.500; HLA= 8.334
HR= -3; HRA=-44.500; HLA= 4.847
HR= -2; HRA=-29.500; HLA= 2.795
HR= -1; HRA=-14.500; HLA= 1.278
HR= 0; HRA= 0.500; HLA= -0.043
HR= 1; HRA= 15.500; HLA= -1.371
HR= 2; HRA= 30.500; HLA= -2.910
HR= 3; HRA= 45.500; HLA= -5.018
HR= 4; HRA= 60.500; HLA= -8.671
HR= 5; HRA= 75.500; HLA=-18.451
HR= 6; HRA= 90.500; HLA= 84.225
</pre>
 
=={{header|Python}}==
{{trans|ALGOL 68}}
<lang python>from __future__ import print_function
import math
 
lat = float(raw_input("Enter latitude => "))
lng = float(raw_input("Enter longitude => "))
ref = float(raw_input("Enter legal meridian => "))
print()
 
slat = math.sin(math.radians(lat))
print(" sine of latitude: %.3f" % slat)
print(" diff longitude: %.3f" % (lng-ref))
print()
print("Hour, sun hour angle, dial hour line angle from 6am to 6pm")
 
for h in range(-6, 7):
hra = 15 * h
hra -= lng - ref
hla = math.degrees(math.atan(slat * math.tan(math.radians(hra))))
print("HR=%3d; HRA=%7.3f; HLA=%7.3f" % (h, hra, hla))</lang>
<pre>
Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.