我有一个 Vector3 列表,每个都有 x、y、z 值。
List<Vector3> list = new List<Vector3>();
我想遍历这个列表,找到平均值并从中创建一个向量:
所得向量:
averageVector.X = average of all the x values;
averageVector.Y= average of all the y values;
averageVector.Z = average of all the z values;
return averageVector;
我正在尝试为此创建一个功能,并且希望得到您的帮助!
您可以使用Enumerable.Aggregate
对向量求和,然后除以计数即可得到平均值。
var average = list.Aggregate(new Vector3(0,0,0), (s,v) => s + v) / (float)list.Count;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)