Comments and answers for "Average of Vectors [Math]"
http://answers.unity.com/questions/1605901/average-of-vectors-math.html
The latest comments and answers for the question "Average of Vectors [Math]"Comment by Bunny83 on Bunny83's comment
http://answers.unity.com/comments/1606702/view.html
Yes, this would improve the algorithm. Though you would always remove at least 4 values. So this only works if you always have enough values, say at least 7 or more, otherwise it just picks a rather random point of the given points and not an average.
<br>
Here's an illustration what your original code does:
<img src="https://www.dropbox.com/s/r6x702xlizuce1y/Vector3AverageWrong.gif?raw=1">
The two circle mark the "distance" of the greatest and smallest points which are not trimmed, so the first and last element of the list after trimming. Any points within that torus would be considered "close". The yellow point is the calculated average from the trimmed list.Tue, 26 Feb 2019 16:46:34 GMTBunny83Comment by Ymrasu on Ymrasu's comment
http://answers.unity.com/comments/1606660/view.html
We could run this for each axis; so if two vectors with the same magnitude but say an x of 23 and an x of -23, the outlier would be more likely to be trimmed.Tue, 26 Feb 2019 14:34:23 GMTYmrasuComment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1606635/view.html
Since we just had a [slightly similar question][1] I just thought about this again and just realised that this might not doesn't work as intended. This solution sorts the position based on the absolute distance from the world origin. However that means any two vectors that are on the same radial orbit around the world center will be considered "near" to each other, even they could be very far apart. The current approach only works if the desired position is actually the world origin. Any other position will do a strange selection of vectors. This approach would remove jitter in the radial direction from the world origin, however orthogonal / tangential would jitter would stay. The "selection shape" would be a very strange morphed area.
[1]: https://answers.unity.com/questions/1606589/taking-average-of-multiple-vector3s.htmlTue, 26 Feb 2019 13:26:34 GMTBunny83Comment by Bunny83 on Bunny83's answer
http://answers.unity.com/comments/1606015/view.html
Note that you may get better performance with something like this:
List<Vector3> trimmedList = list.OrderBy(x => x.sqrMagnitude)
.Skip(trim).Take(list.Count - trim*2).ToList();
return trimmedList;Mon, 25 Feb 2019 03:52:53 GMTBunny83Comment by Ay-mak on Ay-mak's answer
http://answers.unity.com/comments/1605923/view.html
That's exactly what I was looking for thank you !Sun, 24 Feb 2019 21:56:02 GMTAy-makAnswer by Ymrasu
http://answers.unity.com/answers/1605916/view.html
There is something called Trimmed Mean to get the average while avoiding outliers. I don't think Unity has a built in function for it. Here is a quick one I threw together:
// using System.Linq;
List<Vector3> TrimmedMean(List<Vector3> list, float percent = 0.01f)
{
int trim = Mathf.CeilToInt(percent * list.Count);
List<Vector3> trimmedList = list.OrderBy(x => x.sqrMagnitude).ToList();
trimmedList.RemoveRange(trimmedList.Count-trim, trim);
trimmedList.RemoveRange(0, trim);
return trimmedList;
}
It takes a list of vectors and a percent (0-1). It sorts the vectors by their sqrMagnitude and trims out the top and bottom by the percentage of vectors in the list. That gets rid of extreme values, but can also get rid of normal values at the ends too.Sun, 24 Feb 2019 21:47:34 GMTYmrasu