DECLARE FUNCTION Atan2# (y AS DOUBLE, x AS DOUBLE) DECLARE FUNCTION MeanAngle# (angles#()) CONST PI# = 3.141592653589793# REDIM angles1#(1 TO 2) angles1#(1) = 350 angles1#(2) = 10 REDIM angles2#(1 TO 4) angles2#(1) = 90 angles2#(2) = 180 angles2#(3) = 270 angles2#(4) = 360 REDIM angles3#(1 TO 3) angles3#(1) = 10 angles3#(2) = 20 angles3#(3) = 30 PRINT USING "Mean for angles 1 is : ####.## degrees"; MeanAngle#(angles1#()) PRINT USING "Mean for angles 2 is : ####.## degrees"; MeanAngle#(angles2#()) PRINT USING "Mean for angles 3 is : ####.## degrees"; MeanAngle#(angles3#()) FUNCTION Atan2# (y AS DOUBLE, x AS DOUBLE) IF x > 0 THEN Atan2# = ATN(y / x) ELSEIF x < 0 THEN IF y >= 0 THEN Atan2# = ATN(y / x) + PI# ELSE Atan2# = ATN(y / x) - PI# END IF ELSE ' x = 0 IF y > 0 THEN Atan2# = PI# / 2 ELSEIF y < 0 THEN Atan2# = -PI# / 2 ELSE ' y = 0 Atan2# = 0 END IF END IF END FUNCTION FUNCTION MeanAngle# (angles#()) length# = UBOUND(angles#) - LBOUND(angles#) + 1 sinSum# = 0! cosSum# = 0! FOR i% = LBOUND(angles#) TO UBOUND(angles#) sinSum# = sinSum# + SIN(angles#(i%) * PI# / 180!) cosSum# = cosSum# + COS(angles#(i%) * PI# / 180!) NEXT i% MeanAngle# = Atan2#(sinSum# / length#, cosSum# / length#) * 180! / PI# END FUNCTION