Averages/Mean time of day: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: minor tidy, use builtin atan2, name h/m/s) |
|||
Line 1,539: | Line 1,539: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
<lang Phix>function |
<lang Phix>function MeanAngle(sequence angles) |
||
⚫ | |||
return 2*arctan((sqrt(power(x,2)+power(y,2))-x)/y) |
|||
⚫ | |||
end function |
|||
⚫ | |||
function MeanAngle(sequence angles) |
|||
⚫ | |||
integer l=length(angles) |
|||
⚫ | |||
⚫ | |||
x += cos(ai_rad) |
x += cos(ai_rad) |
||
y += sin(ai_rad) |
y += sin(ai_rad) |
||
Line 1,569: | Line 1,563: | ||
if s<0 then s+=360 end if |
if s<0 then s+=360 end if |
||
s = 24*60*60*s/360 |
s = 24*60*60*s/360 |
||
atom hours = floor(s/3600), |
|||
mins = floor(remainder(s,3600)/60), |
|||
secs = remainder(s,60) |
|||
s = sprintf("%02d:%02d:%02d",{hours,mins,secs}) |
|||
end if |
end if |
||
return s |
return s |
||
end function |
end function |
||
printf(1,"Mean Time is %s\n",{toHMS(MeanAngle(Times))}) |
printf(1,"Mean Time is %s\n",{toHMS(MeanAngle(Times))})</lang> |
||
{} = wait_key()</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |