Jump to content

Horizontal sundial calculations: Difference between revisions

(→‎{{header|REXX}}: fixed the program to correctly calculate the sundial hour line angle when the sun hour angle is greated than a right angle.)
Line 1,366:
 
''Output'': hour in ''РX'', sun hour angle in ''РY'', dial hour line angle in ''РZ''.
 
=={{header|Modula-2}}==
{{trans|ALGOL-68}}
{{works with|ADW Modula-2|any (Compile with the linker option ''Console Application'').}}
<lang modula2>
MODULE SunDial;
 
FROM STextIO IMPORT
WriteString, WriteLn, SkipLine;
FROM SRealIO IMPORT
ReadReal, WriteFixed, WriteFloat;
FROM SWholeIO IMPORT
WriteInt;
FROM RealMath IMPORT
sin, pi, arctan, tan;
 
VAR
Lat, Slat, Lng, Ref: REAL;
Hour: INTEGER;
HourAngle, HourLineAngle: REAL;
BEGIN
WriteString("Enter latitude => ");
ReadReal(Lat);
SkipLine;
WriteString("Enter longitude => ");
ReadReal(Lng);
SkipLine;
WriteString("Enter legal meridian => ");
ReadReal(Ref);
SkipLine;
WriteLn;
Slat := sin(Lat * pi / 180.0);
WriteString(" sine of latitude: ");
WriteFloat(Slat, 2, 8);
WriteLn;
WriteString(" diff longitude: ");
WriteFixed(Lng - Ref, 3, 1);
WriteLn;
WriteLn;
WriteString("Hour, sun hour angle, dial hour line angle from 6am to 6pm");
WriteLn;
FOR Hour := -6 TO 6 DO
HourAngle := FLOAT(15 * Hour);
HourAngle := HourAngle - (Lng - Ref); (* correct for longitude difference *)
HourLineAngle := arctan(Slat * tan(HourAngle * pi / 180.0)) * 180.0 / pi;
WriteString("HR=");
WriteInt(Hour, 3);
WriteString("; HRA=");
WriteFixed(HourAngle, 3, 8);
WriteString("; HLA=");
WriteFixed(HourLineAngle, 3, 8);
WriteLn;
END;
END SunDial.
</lang>
{{out}}
Enter latitude => -4.95
Enter longitude => -150.5
Enter legal meridian => -150
sine of latitude: -8.6E-02
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
 
=={{header|Nim}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.