Horizontal sundial calculations: Difference between revisions
Content added Content deleted
(→{{header|Java}}: Added missing variable declaration for 'hraRad'.) |
(Scala contribution added.) |
||
Line 2,504: | Line 2,504: | ||
end;</lang> |
end;</lang> |
||
=={{header|Scala}}== |
|||
<lang Scala>import java.util.Scanner |
|||
import scala.math.{atan2, cos, sin, toDegrees, toRadians} |
|||
object Sundial extends App { |
|||
var lat, slat,lng, ref = .0 |
|||
val sc = new Scanner(System.in) |
|||
⚫ | |||
lat = sc.nextDouble |
|||
print("Enter longitude: ") |
|||
lng = sc.nextDouble |
|||
print("Enter legal meridian: ") |
|||
ref = sc.nextDouble |
|||
println() |
|||
slat = Math.sin(Math.toRadians(lat)) |
|||
println(f"sine of latitude: $slat%.3f") |
|||
println(f"diff longitude: ${lng - ref}%.3f\n") |
|||
println("Hour, sun hour angle, dial hour line angle from 06h00 to 18h00") |
|||
for (h <- -6 to 6) { |
|||
val hra = 15.0 * h - lng + ref |
|||
val hraRad = toRadians(hra) |
|||
val hla = toDegrees(atan2(Math.sin(hraRad) * sin(Math.toRadians(lat)), cos(hraRad))) |
|||
println(f"HR= $h%3d;\tHRA=$hra%7.3f;\tHLA= $hla%7.3f") |
|||
} |
|||
}</lang> |
|||
=={{header|Seed7}}== |
=={{header|Seed7}}== |
||
<lang seed7>$ include "seed7_05.s7i"; |
<lang seed7>$ include "seed7_05.s7i"; |
||
Line 2,543: | Line 2,571: | ||
end func;</lang> |
end func;</lang> |
||
{{out}} |
{{out}} |
||
<pre>Enter latitude: -4.95 |
|||
<pre> |
|||
⚫ | |||
Enter longitude: -150.5 |
Enter longitude: -150.5 |
||
Enter legal meridian: -150 |
Enter legal meridian: -150 |
||
Line 2,564: | Line 2,591: | ||
HR= 4; HRA= 60.500; HLA= -8.671 |
HR= 4; HRA= 60.500; HLA= -8.671 |
||
HR= 5; HRA= 75.500; HLA= -18.451 |
HR= 5; HRA= 75.500; HLA= -18.451 |
||
HR= 6; HRA= 90.500; HLA= 84.225 |
HR= 6; HRA= 90.500; HLA= 84.225</pre> |
||
</pre> |
|||
=={{header|Sidef}}== |
=={{header|Sidef}}== |