Skip to content

Commit

Permalink
Added a running mean math version for quaternions
Browse files Browse the repository at this point in the history
  • Loading branch information
cs-util committed Feb 7, 2024
1 parent 44a359d commit baf4426
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ public static Vector3 CalcRunningMean(Vector3 oldAverage, Vector3 newValue, int
var newZ = CalcRunningMean(oldAverage.Z, newValue.Z, count);
return new Vector3(newX, newY, newZ);
}

/// <summary> Internally uses Quaternion.Slerp to approximate the latest mean rotation </summary>
/// <param name="oldAverage"> The current average </param>
/// <param name="newValue"> The new value that should contribute to the old average </param>
/// <param name="count"> The number of elements that already contributed to the average </param>
public static Quaternion CalcRunningMean(this Quaternion oldAverage, Quaternion newValue, int count) {
return Quaternion.Slerp(oldAverage, newValue, 1f / count);
}

/// <summary>
/// This allows to calculate the mean of a list without storing all entries of the list.
Expand Down

0 comments on commit baf4426

Please sign in to comment.