Weighted Average of Points

I’m working in GhPython and want to find the weighted average (center point) of a set of points. I have a list of points and a list of values (from 0 to 1). Is there a Rhinocommon method for doing this?

No, but the maths is pretty trivial. Multiply all your points by their respective weight, add them all together and divide the result by the sum-total of all weights. You can either add x,y,z coordinates separately as numbers, or use a point or vector struct to store the intermediate results.

Thanks, I found the same logic elsewhere but ran into problems when I tried to sum(points). Splitting the point into its components then summing worked.

temppoint=[mypoints[i]*myvalues[i] for i in range(len(mypoints))]
tempx=sum(i.X for i in temppoint)
tempy=sum(i.Y for i in temppoint)
tempz=sum(i.Z for i in temppoint)
tempvalues=sum(myvalues)
center=rg.Point3d(tempx/tempvalues,tempy/tempvalues,tempz/tempvalues)
2 Likes