You can create a custom extension method that will allow you to calculate the sum and average of a Vector3 in a more readable way and use it as you would use the built-in Sum and Average methods.
public static class Vector3Extensions
{
public static float Sum(this Vector3 vector)
{
return vector.X + vector.Y + vector.Z;
}
public static float Average(this Vector3 vector)
{
return vector.Sum() / 3;
}
}
Then you can use it as
Vector3 vector = new Vector3(10, 20, 30);
Console.WriteLine("The sum of the vector is: " + vector.Sum());
Console.WriteLine("The average of the vector is: " + vector.Average());
Amit MohantyPosted Jan 23, 2023, 4:35 AM
You can create a custom extension method that will allow you to calculate the sum and average of a Vector3 in a more readable way and use it as you would use the built-in Sum and Average methods.
Then you can use it as
Naimish MakwanaPosted Jan 23, 2023, 3:39 AM
To Average vector, you can do like below.
For Vector Sum (double) type :
The
Dotmethod calculates the dot product of the two vectors, which is defined for two vectorsAandBof sizenasA1 * B1 + A2 * B2 + ... + An * BnReference
https://stackoverflow.com/questions/33170643/finding-the-average-of-vectors-in-a-list
https://stackoverflow.com/questions/35514685/sum-of-elements-in-system-numerics-vectort-in-net-4-6
Thanks