Horizontal sundial calculations: Difference between revisions

add Ada
m ('round' defaults to 3)
(add Ada)
Line 5:
 
Wikipedia: A [[wp:sundial|sundial]] is a device that measures time by the position of the [[wp:Sun|Sun]]. In common designs such as the horizontal sundial, the sun casts a [[wp:shadow|shadow]] from its ''style'' (also called its [[wp:Gnomon|Gnomon]], a thin rod or a sharp, straight edge)<!-- The style is the time telling edge of the gnomon, Waugh,1973 p29--> onto a flat surface marked with lines indicating the hours of the day. As the sun moves across the sky, the shadow-edge progressively aligns with different hour-lines on the plate. Such designs rely on the style being aligned with the axis of the Earth's rotation. Hence, if such a sundial is to tell the correct time, the style must point towards [[wp:true north|true north]] (not the [[wp:North Magnetic Pole|north]] or [[wp:Magnetic South Pole|south magnetic pole]]) and the style's angle with horizontal must equal the sundial's geographical [[wp:latitude|latitude]].
 
=={{header|Ada}}==
 
sundial.adb:
<lang Ada>with Ada.Text_IO;
with Ada.Numerics.Elementary_Functions;
procedure Sundial is
use Ada.Numerics.Elementary_Functions;
use Ada.Numerics;
package Float_IO is new Ada.Text_IO.Float_IO (Float);
 
Latitude, Longitude, Meridian : Float;
Latitude_Sine : Float;
begin
Ada.Text_IO.Put ("Enter latitude: ");
Float_IO.Get (Latitude);
Ada.Text_IO.Put ("Enter longitude: ");
Float_IO.Get (Longitude);
Ada.Text_IO.Put ("Enter legal meridian: ");
Float_IO.Get (Meridian);
Ada.Text_IO.New_Line;
 
Latitude_Sine := Sin (Latitude * Pi / 180.0);
Ada.Text_IO.Put_Line
(" sine of latitude:" & Float'Image (Latitude_Sine));
Ada.Text_IO.Put_Line
(" diff longitude:" & Float'Image (Longitude - Meridian));
Ada.Text_IO.New_Line;
 
Ada.Text_IO.Put_Line
("hour, sun hour angle, dial hour line angle from 6am to 6pm");
for H in -6 .. 6 loop
declare
Hour_Angle : constant Float :=
15.0 * Float (H) - (Longitude - Meridian);
Line_Angle : constant Float :=
Arctan (Latitude_Sine * Tan (Hour_Angle * Pi / 180.0)) * 180.0 /
Pi;
begin
Ada.Text_IO.Put_Line
("HR=" &
Integer'Image (H) &
"; HRA=" &
Float'Image (Hour_Angle) &
"; HLA=" &
Float'Image (Line_Angle));
end;
end loop;
end Sundial;</lang>
 
Output:
<pre>Enter latitude: -4.95
Enter longitude: -150.5
Enter legal meridian: -150
 
sine of latitude:-8.62864E-02
diff longitude:-5.00000E-01
 
hour, sun hour angle, dial hour line angle from 6am to 6pm
HR=-6; HRA=-8.95000E+01; HLA= 8.42248E+01
HR=-5; HRA=-7.45000E+01; HLA= 1.72829E+01
HR=-4; HRA=-5.95000E+01; HLA= 8.33371E+00
HR=-3; HRA=-4.45000E+01; HLA= 4.84671E+00
HR=-2; HRA=-2.95000E+01; HLA= 2.79487E+00
HR=-1; HRA=-1.45000E+01; HLA= 1.27835E+00
HR= 0; HRA= 5.00000E-01; HLA=-4.31443E-02
HR= 1; HRA= 1.55000E+01; HLA=-1.37079E+00
HR= 2; HRA= 3.05000E+01; HLA=-2.90964E+00
HR= 3; HRA= 4.55000E+01; HLA=-5.01802E+00
HR= 4; HRA= 6.05000E+01; HLA=-8.67140E+00
HR= 5; HRA= 7.55000E+01; HLA=-1.84510E+01
HR= 6; HRA= 9.05000E+01; HLA= 8.42248E+01</pre>
 
=={{header|ALGOL 68}}==
256

edits