Created
April 13, 2018 06:55
-
-
Save serguei-k/dfcb5c90d78e493c5da632a23959c039 to your computer and use it in GitHub Desktop.
Rotation Average
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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