I'm working on a model editor and I have a set center function to reset the center of a model. I can do this a few ways which I have implemented.

method 1) add vertices and average them and move the model

pseudocode

for each point

dx += point.x

dy += point.y

dz += point.z

count ++

dx/=count

dy/=count

dz/=count

for each point

point.x-=dx

point.y-=dy

point.z-=dz

the problem: If the model has many points in one area, the deviation favors that area. Which is not always good because some models have many many points like at the tip of a gun or the cone of a ship.

method 2) find min max of vertices, average the min max into a deviation and moved the model

for each point

mindx = min(point.x,mindx)

maxdx = max(point.x,maxdx)

same for y and z

count ++

dx = (mindx+maxdx)/2

same for dy,dz;

for each point

point.x-=dx

same for y and z

That works OK.

QUESTION

For my 3rd method, I would really like to center the model on its estimated center mass.

I have a series of 3 points defining the planes/faces. I figure I could plug either the plane area or perimeter into the deviation calculation. That way many points defining a tiny area would not affect the calculation that much. But I cant figure out the right math for this.

**Edited by icuurd12b42, 24 September 2008 - 11:52 PM.**