24 lines
652 B
Text
24 lines
652 B
Text
function atan2(atom y, atom x)
|
|
return 2*arctan((sqrt(power(x,2)+power(y,2))-x)/y)
|
|
end function
|
|
|
|
function MeanAngle(sequence angles)
|
|
atom x=0, y=0, ai_rad
|
|
integer l=length(angles)
|
|
|
|
for i=1 to l do
|
|
ai_rad = angles[i]*PI/180
|
|
x += cos(ai_rad)
|
|
y += sin(ai_rad)
|
|
end for
|
|
if abs(x)<1e-16 then return "not meaningful" end if
|
|
return sprintf("%9.5f",atan2(y,x)*180/PI)
|
|
end function
|
|
|
|
constant AngleLists = {{350,10},{90,180,270,360},{10,20,30},{180},{0,180}}
|
|
sequence ai
|
|
for i=1 to length(AngleLists) do
|
|
ai = AngleLists[i]
|
|
printf(1,"%+16s: Mean Angle is %s\n",{sprint(ai),MeanAngle(ai)})
|
|
end for
|
|
{} = wait_key()
|