function shift2center(mList)
local n = #mList
local denom = 0
local numerX = 0
local numerY = 0
for i = 1, n do
denom = denom + mList[i].m
numerX = numerX + mList[i].m * mList[i].x
numerY = numerY + mList[i].m * mList[i].y
end
local cx = numerX / denom
local cy = numerY / denom
for i = 1, n do
mList[i].x = mList[i].x - cx
mList[i].y = mList[i].y - cy
end
return mList
end
mList = {{m = 3, x = 1 + 10, y = 3 - 20},
{m = 4, x = -2 + 10, y = -1 - 20},
{m = 5, x = 1 + 10, y = -1 - 20},}
mList = shift2center(mList)
for i = 1, #mList do
print(string.format("mList[%d], x = %f, y = %f", i, mList[i].x, mList[i].y))
end