Oh crap... I was writing in a brain-damaged mode, sorry for that! My previous post was not on topic (well, actually it is a little bit relevant).
Again sorry for wasting your time! Anyways, here's how I would find the centroid of a figure [Edit:] *without triangulation, provided the points of the figure are given in clockwise order*. First of all, let me point out that the formula for doing this is actually in the wikipedia article under paragraph "Centroid by geometric decomposition".
http://en.wikipedia.org/wiki/Centroid#Centroid_of_a_finite_set_of_points
The punchline is that you don't need any *real* triangulation: simply take the formula as it is given, but allow *signed* areas. Let me explain:
The formula I am pointing you to is
(\sum_k C_i A_i)/(\sum A_i)
For the triangulation, simply pick the "fake" triangulation
T_1=(x_1, y_1) (x_2, y_2) (x_3,y_3)
T_2=(x_1, y_1) (x_3,y_3) (x_4,y_4)
...
T_{n-2}= (x_1, y_1) (x_{n-1},y_{n-1}) (x_n,y_n)
Now if A_{k-2} is the area of triangle T_{k-2}= x_1 x_{k-1} x_k, then A_{k-2} is given by the formula
1 2
|
1/2 det |x_k-x_1 y_k-y_1 |
|x_{k-1}-x_1 y_{k-1}-y_1|
|
Note that the above formula gives at times negative area, and at times - positive. That will precisely account for the fact that some of the triangles in our triangulation have pieces lying outside of our figure.
The centroid C_k of each T_{k-2} is of course given by:
|
C_k= 1/3((x_1+x_{k-1}+x_k),(y_1+y_{k-1}+y_k) )
|
.
I hope you now see how to apply the above formula. The simplicity of this approach is now evident: it works in arbitrary dimension. All you need to do in arbitrary dimension (for example, in 3D or 1D), is to
note that the area in dimension D of a simplex(=triangle in 2D, tetrahedron in 3D - simplex is the general word for arbitrary dimension) will be given by:
Let the simplex be given with points P_0= (x0_1, x0_2, ..., x0_D) ... P_{D}= (xD_1, xD_2, ..., xD_D) (a simplex in N dimensions has always N+1 vertices - triangle has 3 and tetrahedron has 4). Then the area of the enclosed simplex is given by the D by D determinant
1 2 3
|
1/(D!) det |x0_1-x1_1 ... x0_D-x1_D|
| ... |
|x0_1-xD_1 ... x0_D-xD_D|
|
Of course, you must also normalize the centroids properly: they will be the average of D+1 points, so you must always divide by 1/(D+1).
Do you know how to compute determinants?
Cheers