Horizontal sundial calculations: Difference between revisions
Content deleted Content added
No edit summary |
m →{{header|REXX}}: added/changed whitespace and comments, simplified some functions, corrected some typos. |
||
Line 1,590: | Line 1,590: | ||
No attempt was made to explain the inner workings of the trigonometric functions. |
No attempt was made to explain the inner workings of the trigonometric functions. |
||
<lang rexx>/*REXX |
<lang rexx>/*REXX pgm shows: hour, sun hour angle, dial hour line angle, 6am ───► 6pm*/ |
||
numeric digits 60 /*better overkill then underkill |
numeric digits 60 /*better overkill then underkill for dig*/ |
||
parse arg lat lng mer . /*get the arguments |
parse arg lat lng mer . /*get the optional arguments from the CL*/ |
||
/*None specified? Then use the default of Jules */ |
|||
/*Verne's Lincoln Island, aka Ernest Legouve Reef.*/ |
|||
⚫ | |||
if lat=='' | lat==',' then lat=-4.95 /* |
if lat=='' | lat==',' then lat=-4.95 /*Not specified? Then use the default.*/ |
||
if lng=='' | lng==',' then lng=-150.5 /* |
if lng=='' | lng==',' then lng=-150.5 /* " " " " " " */ |
||
if mer=='' | mer==',' then mer=-150 /* |
if mer=='' | mer==',' then mer=-150 /* " " " " " " */ |
||
L=max(length(lat),length(lng),length(mer)) |
L=max(length(lat), length(lng), length(mer)) |
||
say ' latitude:' right(lat,L) |
say ' latitude:' right(lat,L) |
||
say ' longitude:' right(lng,L) |
say ' longitude:' right(lng,L) |
||
say ' legal meridian:' right(mer,L) |
say ' legal meridian:' right(mer,L) |
||
sineLat=sin(d2r(lat)) |
sineLat=sin(d2r(lat)) |
||
w1=max(length('hour'),length('midnight'))+2 |
w1=max(length('hour') ,length('midnight'))+2 |
||
w2=max(length('sun hour') ,length('angle'))+2 |
w2=max(length('sun hour') ,length('angle'))+2 |
||
w3=max(length('dial hour'),length('line angle'))+2 |
w3=max(length('dial hour'),length('line angle'))+2 |
||
indent=left('',30) /*make presentation prettier. */ |
indent=left('',30) /*make the presentation prettier. */ |
||
say indent center(' ',w1) center('sun hour',w2) center('dial hour' ,w3) |
say indent center(' ',w1) center('sun hour',w2) center('dial hour' ,w3) |
||
say indent center('hour',w1) center('angle' ,w2) center('line angle',w3) |
say indent center('hour',w1) center('angle' ,w2) center('line angle',w3) |
||
call sep /*add separator line for eyeballs*/ |
call sep /*add a separator line for the eyeballs*/ |
||
do h=-6 to 6 /*Okey dokey then, let's get busy*/ |
do h=-6 to 6 /*Okey dokey then, let's get busy. */ |
||
select |
select |
||
when abs(h)==12 then hc='midnight' /*above |
when abs(h)==12 then hc='midnight' /*above the arctic circle? */ |
||
when h<0 then hc=-h 'am' /*convert hour for human beans. */ |
when h<0 then hc=-h 'am' /*convert the hour for human beans. */ |
||
when h==0 then hc='noon' /* ... |
when h==0 then hc='noon' /* ... easier to understand now. */ |
||
when h>0 then hc=h 'pm' /* ... even |
when h>0 then hc=h 'pm' /* ... even more meaningful. */ |
||
end /*select*/ |
end /*select*/ |
||
hra=15*h-lng+mer |
hra=15*h-lng+mer |
||
Line 1,627: | Line 1,626: | ||
call sep |
call sep |
||
exit /*stick a fork in it, we're done.*/ |
exit /*stick a fork in it, we're all done. */ |
||
/*──────────────────────────────────subroutines───────────────────────────────*/ |
|||
⚫ | |||
/*──────────────────────────────────subroutines─────────────────────────*/ |
|||
⚫ | |||
/*looking at subroutines is like looking at saugages being made. Don't.*/ |
|||
⚫ | |||
⚫ | |||
r2d: return d2d((arg(1)*180 / pi())) /*convert radians ──► degrees. */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
r2d: return d2d((arg(1)*180/pi())) /*convert radians ──► degrees. */ |
|||
⚫ | |||
⚫ | |||
⚫ | |||
tellErr: say; say '*** error! ***'; say; say arg(1); say; exit 13 |
tellErr: say; say '*** error! ***'; say; say arg(1); say; exit 13 |
||
AsinErr: call tellErr 'Asin(x), X must be in the range of -1 ──► +1, X='||x |
AsinErr: call tellErr 'Asin(x), X must be in the range of -1 ──► +1, X=' ||x |
||
sqrtErr: call tellErr "sqrt(x), X can't be negative, X="||x |
sqrtErr: call tellErr "sqrt(x), X can't be negative, X="||x |
||
AcosErr: call tellErr 'Acos(x), X must be in the range of -1 ──► +1, X='||x |
AcosErr: call tellErr 'Acos(x), X must be in the range of -1 ──► +1, X=' ||x |
||
Acos: procedure; arg x; if x<-1|x>1 then call AcosErr; return .5*pi()-Asin(x) |
Acos: procedure; arg x; if x<-1|x>1 then call AcosErr; return .5*pi()-Asin(x) |
||
Line 1,661: | Line 1,652: | ||
return .sincos(1,1,-1) |
return .sincos(1,1,-1) |
||
.sinCos: parse arg z,_,i; x=x*x; p=z |
.sinCos: parse arg z,_,i; x=x*x; p=z |
||
do k=2 by 2; _=-_*x/(k*(k+i));z=z+_; if z=p then leave; p=z; end; return z |
|||
Asin: procedure; parse arg x; if x<-1 | x>1 then call AsinErr; s=x*x |
Asin: procedure; parse arg x; if x<-1 | x>1 then call AsinErr; s=x*x |
||
Line 1,668: | Line 1,659: | ||
return z |
return z |
||
pi: return, /*a bit of an overkill, but hey !! */ |
|||
⚫ | |||
⚫ | |||
g=.sqrtGuess(); do j=0 while p>9; m.j=p; p=p%2+1; end |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
.sqrtGuess: if x<0 then call sqrtErr; numeric form scientific; m.=11; p=d+d%4+2 |
|||
⚫ | |||
⚫ | |||
{{out}} |
|||
numeric digits 9; if x<0 then do; x=-x; i='i'; end; numeric form; h=d+2 |
|||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
'''pit[it''' |
|||
<pre> |
<pre> |
||
latitude: -4.95 |
latitude: -4.95 |