How to resolve the algorithm Horizontal sundial calculations step by step in the Seed7 programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Horizontal sundial calculations step by step in the Seed7 programming language

Table of Contents

Problem Statement

Create a program that calculates the hour, sun hour angle, dial hour line angle from 6am to 6pm for an operator entered location.

For example, the user is prompted for a location and inputs the latitude and longitude 4°57′S 150°30′W (4.95°S 150.5°W of Jules Verne's Lincoln Island, aka Ernest Legouve Reef), with a legal meridian of 150°W. (Note: the "meridian" is approximately the same concept as the "longitude" - the distinction is that the meridian is used to determine when it is "noon" for official purposes. This will typically be slightly different from when the sun appears at its highest location, because of the structure of time zones. For most, but not all, time zones (hour wide zones with hour zero centred on Greenwich), the legal meridian will be an even multiple of 15 degrees.) Wikipedia: A sundial is a device that measures time by the position of the Sun. In common designs such as the horizontal sundial, the sun casts a shadow from its style (also called its Gnomon, a thin rod or a sharp, straight edge) onto a flat surface marked with lines indicating the hours of the day (also called the dial face or dial plate). 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 true north (not the north or south magnetic pole) and the style's angle with horizontal must equal the sundial's geographical latitude.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Horizontal sundial calculations step by step in the Seed7 programming language

Source code in the seed7 programming language

$ include "seed7_05.s7i";
  include "float.s7i";
  include "math.s7i";

const float: radianToDegrees is 57.295779513082320876798154814114;
const float: degreesToRadian is 0.017453292519943295769236907684883;

const proc: main is func
  local
    var float: lat is 0.0;
    var float: slat is 0.0;
    var float: lng is 0.0;
    var float: meridian is 0.0;
    var float: hla is 0.0;
    var float: hra is 0.0;
    var integer: h is 0;
  begin
    write("Enter latitude: ");
    readln(lat);
    write("Enter longitude: ");
    readln(lng);
    write("Enter legal meridian: ");
    readln(meridian);
    writeln;
    slat := sin(degreesToRadian * lat);
    writeln("sine of latitude: " <& slat digits 3);
    writeln("diff longitude: " <& lng - meridian digits 3);
    writeln;
    writeln("Hour, sun hour angle, dial hour line angle from 6am to 6pm");
    for h range -6 to 6 do
      hra := 15.0 * flt(h);
      hra := hra - lng + meridian;
      hla := radianToDegrees * atan(slat * tan(degreesToRadian * hra));
      writeln("HR= " <& h lpad 2 <& "; HRA= " <& hra digits 3 lpad 7 <&
              "; HLA= " <& hla digits 3 lpad 7);
    end for;
  end func;

  

You may also check:How to resolve the algorithm Left factorials step by step in the Run BASIC programming language
You may also check:How to resolve the algorithm Regular expressions step by step in the Bracmat programming language
You may also check:How to resolve the algorithm Combinations with repetitions step by step in the C programming language
You may also check:How to resolve the algorithm Hello world/Graphical step by step in the Objeck programming language
You may also check:How to resolve the algorithm Conway's Game of Life step by step in the Vedit macro language programming language