Averages/Mean angle: Difference between revisions
Content deleted Content added
MaiconSoft (talk | contribs) No edit summary |
m →{{header|Phix}}: minor tidy, use builtin atan2, round to 10dp. |
||
Line 1,483: | Line 1,483: | ||
=={{header|Phix}}== |
=={{header|Phix}}== |
||
Copied from [[Euphoria]], and slightly improved |
Copied from [[Averages/Mean_angle#Euphoria|Euphoria]], and slightly improved |
||
<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) |
||
end for |
end for |
||
if abs(x)<1e-16 then return "not meaningful" end if |
if abs(x)<1e-16 then return "not meaningful" end if |
||
return sprintf("% |
return sprintf("%g",round(atan2(y,x)*180/PI,1e10)) |
||
end function |
end function |
||
constant AngleLists = {{350,10},{90,180,270,360},{10,20,30},{180},{0,180}} |
constant AngleLists = {{350,10},{90,180,270,360},{10,20,30},{180},{0,180}} |
||
sequence ai |
|||
for i=1 to length(AngleLists) do |
for i=1 to length(AngleLists) do |
||
ai = AngleLists[i] |
sequence ai = AngleLists[i] |
||
printf(1,"% |
printf(1,"%16v: Mean Angle is %s\n",{ai,MeanAngle(ai)}) |
||
end for |
end for</lang> |
||
{} = wait_key()</lang> |
|||
{{out}} |
{{out}} |
||
<pre> |
<pre> |
||
{350,10}: Mean Angle is |
{350,10}: Mean Angle is 0 |
||
{90,180,270,360}: Mean Angle is not meaningful |
{90,180,270,360}: Mean Angle is not meaningful |
||
{10,20,30}: Mean Angle is |
{10,20,30}: Mean Angle is 20 |
||
{180}: Mean Angle is 180 |
{180}: Mean Angle is 180 |
||
{0,180}: Mean Angle is not meaningful |
{0,180}: Mean Angle is not meaningful |
||
</pre> |
</pre> |