As part of a project at work I have to calculate the centroid of a set of points in 3D space. Right now I\'m doing it in a way that seems simple but naive -- by taking the avera
Potentially more efficient: if you're calculating this multiple times, you can speed this up quite a bit by keeping two standing variables
N # number of points
sums = dict(x=0,y=0,z=0) # sums of the locations for each point
then changing N and sums whenever points are created or destroyed. This changes things from O(N) to O(1) for calculations at the cost of more work every time a point is created, moves, or is destroyed.