Skip to content

Instantly share code, notes, and snippets.

@serguei-k
Last active April 13, 2018 18:17
Show Gist options
  • Save serguei-k/74418242c993d7624f2de6f01717cd7e to your computer and use it in GitHub Desktop.
Save serguei-k/74418242c993d7624f2de6f01717cd7e to your computer and use it in GitHub Desktop.
Scale Average
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