Horizontal sundial calculations: Difference between revisions
Content deleted Content added
Grouping BASIC dialects |
m →{{header|Wren}}: Minor tidy |
||
(5 intermediate revisions by 3 users not shown) | |||
Line 345:
=={{header|BASIC}}==
==={{header|ANSI BASIC}}===
{{trans|ALGOL-68|ANSI BASIC has a possibility to use degrees in calculations.}}
{{works with|Decimal BASIC}}
100 REM Horizontal sundial calculations
110 INPUT PROMPT "Enter latitude => ": Lat
120 INPUT PROMPT "Enter longitude => ": Lng
130 INPUT PROMPT "Enter legal meridian => ": Ref
140 PRINT
150 OPTION ANGLE DEGREES
160 LET Slat = SIN(Lat)
170 PRINT " sine of latitude: "; Slat
180 PRINT " diff longitude: "; Lng - Ref
190 PRINT
200 PRINT "Hour, sun hour angle, dial hour line angle from 6am to 6pm"
210 FOR Hour = -6 TO 6
220 LET HourAngle = 15 * Hour
230 LET HourAngle = HourAngle - (Lng - Ref) ! correct for longitude difference
240 LET HourLineAngle = ATN(Slat * TAN(HourAngle))
250 PRINT USING "HR=###; HRA=####.###; HLA=####.###": Hour, HourAngle, HourLineAngle
260 NEXT Hour
270 END
</syntaxhighlight>
{{out}}
<pre>
Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -8.62863657979234E-2
diff longitude: -.5
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= .500; HLA= -.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|BASIC256}}===
<syntaxhighlight lang="basic256">call SolarhoraAngle(-4.95, -150.5, -150.0)
Line 417 ⟶ 465:
17.00 75.500 -18.451
18.00 90.500 -95.775</pre>
==={{header|Chipmunk Basic}}===
{{works with|Chipmunk Basic|3.6.4}}
<syntaxhighlight lang="qbasic">10 CLS
20 DEF FNR(x) = x * PI/180
30 DEF FND(x) = x * 180/PI
40 INPUT " Enter latitude (degrees): ";latitude
50 INPUT " Enter longitude (degrees): ";longitude
60 INPUT "Enter legal meridian (degrees): ";meridian
70 PRINT
80 PRINT " Time Sun hour angle Dial hour line angle"
90 FOR h = 6 TO 18
100 hra = 15*h-longitude+meridian-180
110 hla = FN D(ARCTAN(SIN(FN R(latitude))*TAN(FN R(hra))))
120 IF ABS(hra) > 90 THEN hla = hla+180*SGN(hra*latitude)
130 PRINT USING "##.##";h;TAB (10)
140 PRINT USING "####.###";hra;TAB (27)
150 PRINT USING "####.###";hla
160 NEXT h
170 END</syntaxhighlight>
{{out}}
<pre>Same as FreeBASIC entry.</pre>
==={{header|FreeBASIC}}===
Line 1,315 ⟶ 1,385:
=={{header|EasyLang}}==
<syntaxhighlight lang="text">
func
write s$
v = number input
print v
return v
.
slat = sin lat
diff = lng - merid
Line 1,331 ⟶ 1,403:
print "Hour\tSun hour angle\tDial hour line angle"
for h = -6 to 6
hra = 15 * h - diff
hla = atan2 (slat * sin hra) cos hra
print h + 12 & "\t" & hra & "\t\t" & hla
.
▲.</syntaxhighlight>
</syntaxhighlight>
=={{header|ERRE}}==
Line 3,620 ⟶ 3,693:
{{trans|Go}}
{{libheader|Wren-fmt}}
<syntaxhighlight lang="
import "./fmt" for Fmt
var getNum = Fn.new { |prompt|
|