public static double WeightedMean(double[] angles, double[] weights) { double cos = 0, sin = 0; for (int i = 0; i < angles.Length; i++) { cos += Math.Cos(angles[i]) * weights[i]; sin += Math.Sin(angles[i]) * weights[i]; } return Math.Atan2(sin, cos); }