- Home /
Calculate weighted mean based on direction
Technical version: I need to calculate the weighted mean of a set of points, using an arbitrarily decided 'forward' direction. The more 'forward' a point is from the rest of the group, the more weight is has.
Contextual version: I have a camera that is tracking a group of players. I'd like to reward the people who are in the 'front' of the pack by giving them more camera influence (or giving the players in the 'back', less).
I'd really appreciate some help!
Well, first thing to do is have a way to sort your points on how 'forward' they are. Best way is probably to calculate the distance of each point to a plane perpendicular to your direction vector (plane in 3d, line in 2D). (You should probably pick the plane to be such that one of the points in your set lies on it).
Then of course you should map the distances you get to a more suitable interval, and then you can calculate weights based on that.
I say map it because since I picked a 'random' plane here, there could be negative distance values and that could be rather impractical in your case (you do not want negative weights in your case).