I am trying to calculate the weighted mean angle of a large set of angles (range: -0.5*pi to 0.5*pi). Normally this would not be an issue as this has been explained numerous times in previous questions, but in my case I am attempting to calculate the mean angle when a shift of pi (180°) does not matter.
For example, by any regular method a circular mean of -0.4*pi and 0.4*pi would lead to a mean of 0. In this case -0.4*pi is the same as 0.6*pi so another possible answer would be 0.5*pi. By the same reasoning this mean has four possible answers, namely: 0, 0.5*pi, pi, -0.5*pi.
I need the function to output the weighted circular mean taking into account that it always picks the mean over the shortest possible angular distance between the angles and outputs the value that falls within the -0.5*pi to 0.5*pi range. For a small set of angles this would be easy with a few if statements, but I'm dealing with a data set of a few thousand angles.