## Compute the Centroid of a 3D Planar Polygon

Given a list of 3D coordinates that define the surface( Point3D1, Point3D2, Point3D3, and so on), how to calculate the centroid of the surface?

More specifically, I am looking for a natural extension of the following 2D centroid algorithm in 3 or more dimension:

Any idea?

P/S: All the points are coplanar, this is the assumption.

-
Before asking for the centroid of a surface bounded by a polygonal cycle, you should define more clearly what the surface is. Are all the vertices required to lie on the same plane as each other, so you really just have a 2d polygon embedded into 3d? Or are you trying to describe non-flat 3d surfaces? – David Eppstein Mar 4 2010 at 3:14
I don't think this question is well-defined unless all your points are coplanar. In that case you'd probably just want to project down onto R^2. – Michael Lugo Mar 4 2010 at 3:16
Then the centroid sits over the centroid of its projection to any plane. So, you can use the formulas for two coordinates to compute each coordinate for the centroid. – Douglas Zare Mar 4 2010 at 6:43
to add to what Douglas says, since the points are coplanar, just find that plane and rotate the object so it's in the x,y plane, and proceed as before – Suresh Venkat Mar 18 2010 at 20:18
To subtract from what Suresh says, you don't need to rotate anything. Just project onto the (x,y)-plane to get the x- and y-coordinates, and project onto the (x,z)-plane to get the z-coordinate. – TonyK May 4 2010 at 20:30

In response to JBL's comment, I offer this answer merely to close out this topic. It has been effectively answered in the comments: Simply project to xy and to xz and compute the centroid there. (One tiny wrinkle not addressed is if the polygon lies in a plane perpendicular to xy or to xz. But then simply chose the coordinate planes in which it does not lie.)

On the advice of Andrew Stacey, I am designating this answer "community wiki," and hope that someone will vote it up so it will no longer be bumped to the top of the active list by the MO background process.

-
 Well, I would have voted you up in any case. :) Mentioning the "extra wrinkle" is good, too. – JBL Jun 16 2010 at 13:02 I think you meant 'perpendicular', not 'parallel'. Another wrinkle is that this method generates two values for the x-coordinate of the centroid, and you have to decide what to do when they are not equal due to rounding errors. Probably you should take the one that came from the 'least perpendicular' projection, i.e. the one with the greater area A. – TonyK Jun 17 2010 at 18:41 @TonyK: Thanks for the correction, now edited. In practice I have simply averaged the two x-coordinates, although your method may be more accurate. – Joseph O'Rourke Jun 29 2010 at 11:25

These formulas could be deduced using Green's theorem . For example the formula used to compute the polygon's area is proved using the vector field F=(-y/2,x/2).

Maybe you can do the same in the space using analogous vector fields and Stokes' theorem .

-

I'm not sure about the centroid of the surface area, but I might be able to help with the centroid of it's enclosed volume under some specific circumstances.

If each surface formed by the points creates a triangle (as is the case with the vast majority of computer related applications) then you can use this method that i outlined in StackOverflow (i understand its not in the from a mathematician would like it in, but if you read the explanation the answer is fairly simple).

http://stackoverflow.com/questions/2083771/a-method-to-calculate-the-centre-of-mass-from-a-stl-stereo-lithography-file

Hopefully that helps

-

Related to this topic: what if the points do not lie all in the same plane ? I need to calculate the center of an hexagon. However, the hexagon in not planar (it is a 3D object, a distorted hexagon). Can the above formulas be exended to calculate the centroid of this hexagon ?

-
 You need to define what "this hexagon" is. If you triangulate it, then you could compute the centroid of each triangle, and then the centroid of those area-weighted centroids. – Joseph O'Rourke Nov 7 2011 at 19:12