Last active
April 13, 2018 18:17
-
-
Save serguei-k/74418242c993d7624f2de6f01717cd7e to your computer and use it in GitHub Desktop.
Scale 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
MVector scaleAverage(const std::vector<MVector>& values) | |
{ | |
if (values.empty()) return MVector::zero; | |
const MVector sum = std::accumulate(values.begin(), values.end(), MVector::zero, | |
[](const MVector& a, const MVector& b) | |
{ | |
// assumes [Vx, Vy, Vz] > 0 | |
return MVector(a.x + std::log(b.x), a.y + std::log(b.y), a.z + std::log(b.z)); | |
}); | |
const MVector average = sum / values.length(); | |
return MVector(std::exp(average.x), std::exp(average.y), std::exp(average.z)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment