Skip to content

Instantly share code, notes, and snippets.

@serguei-k
Created April 13, 2018 06:55
Show Gist options
  • Save serguei-k/dfcb5c90d78e493c5da632a23959c039 to your computer and use it in GitHub Desktop.
Save serguei-k/dfcb5c90d78e493c5da632a23959c039 to your computer and use it in GitHub Desktop.
Rotation Average
MEulerRotation rotationAverage(const std::vector<MQuaternion>& values)
{
if (values.empty()) return MEulerRotation::identity;
const MQuaternion sum = std::accumulate(values.begin(), values.end(), MQuaternion::identity,
[](const MQuaternion& a, const MQuaternion& b)
{
return a + b.log();
});
const MQuaternion average(sum.x / values.size(), sum.y / values.size(), sum.z / values.size(), sum.w / values.size());
return average.exp().asEulerRotation();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment