# How can I calculate the centroid of polygon?

What is the way to calculate the centroid of polygon? I have a concave polygon of 16 points, and I want know the centroid of that.

thanks

-
You've seen this? –  Ｊ. Ｍ. Dec 11 '11 at 14:09
As for a Mathematica routine: PolygonCentroid[pts_?MatrixQ] := With[{dif = Map[Det, Partition[pts, 2, 1]]}, ((ListConvolve[{1, 1}, #] & /@ Transpose[pts]).dif)/(3 Total[dif])]. Maybe somebody can do better than me... –  Ｊ. Ｍ. Dec 11 '11 at 14:19
thanks but i will be delighted if u could a bit explain me thx –  Csabi Dec 11 '11 at 14:22
Explain what? The formula? The code? You're a bit vague... –  Ｊ. Ｍ. Dec 11 '11 at 14:30

Label your 16 points $(x_1,y_1)$ through $(x_{16},y_{16})$. Then, according to the Wikipedia article...

$$C = \left(\frac{x_1+x_2+\cdots+x_{16}}{16}, \frac{y_1+y_2+\cdots+y_{16}}{16}\right)$$

-
I don't mind giving a quick answer, but please notice that you have not asked a good question. Sure, the wording is fine and the centroid of a polygon does need to be computed, but any research (say, on the Wikipedia page) on your part would have led you to the answer. –  The Chaz 2.0 Dec 11 '11 at 15:04
Does this actually work? I tried it with many vertices on one side, and few on the other side, but it doesn't seem uniform at all. –  Dan the Man Dec 31 '13 at 23:38
This is highly wrong. This doesn't even match the wiki article it claims to quote... –  anorton Mar 4 at 20:56
My apologies! Probably beyond repair at this point... if OP would unaccept, I'd delete it. –  The Chaz 2.0 2 days ago

(The accepted answer is incorrect. May I?)
I. CONSIDERATIONS.

Case: Point List

I have sixteen marbles of equal mass. Let us agree they all lie in one plane.

Q1: What is the center of mass of the set of marbles?

The center of mass of a sphere is its center. So let the coordinates of the marble centers be:

$\;\;\;\;\;Pts = A_1, A_2.... A_{16}.$

To find the centroid C, average them:

$\;\;\;\;\;C =(A_1+A_2+....+A_{16})/16.$

Case: Polygon

Now, using (Pts) as the vertices, I cut out a 16-sided polygon, Jerome.

Q2: What is the center of mass of Jerome?

This is not the same question. How can I ask it correctly? The are two problems:

1. There are many concave polygons through 16 given points. Which did I cut out? I must uniquely identify the region (area) I want to measure. Here are two ways:

a) Break up Jerome into distinct, convex regions. If a set of points are the vertices of a convex polygon, that polygon is unique. Each convex region of Jerome is uniquely determined by its vertices.

b) Arrange Pts so that the order (A1 -> A2 -> A3 .... ->An) follows the perimeter in a single direction, without leaps or self-intersections. A unique perimeter is a unique polygon.

Both ways allow me to draw the figure. Note that the simple average does not distinguish order; it cannot give the correct answer.

2. Jerome is a plane figure: Its mass is proportional to area. But I know "the mean of coordinates" is not the same thing as "proportional to area". Area of of what? Again, the simple average cannot, in general, give the correct answer.

I now have a unique definition of the task, and the accepted answer cannot distinguish the terms of the problem. Only when the balance point of every figure through the given points is the same, could the mean give the correct answer ( and, in fact, does: e.g. regular polygons). Note that I have discarded the simple average where it cannot apply, without knowing the answer or doing any math.

Now to solve the problem.

(A correct formula is given here: Why doesn't a simple mean give the position of a centroid in a polygon? , but I want to know how to obtain that formula.)

-

II. SOLVE THE PROBLEM

Why doesn't a simple mean give the position of a centroid in a polygon? leads to formulas.

Frown. I want to know how to set up and solve the problem. A solution can always be converted to a formula. The reverse --figuring out how a problem was solved by looking at the formula-- is very hard. So I will solve problem from scratch.

A working demonstration of the method below can be found here.

A. Observation
The centroid of triangle $\Delta ABC$ is the simple average of its vertices:
$\;\;\;D = (A+ B + C)/3$.
What? Point order does not matter here: take the vertices A,B,C, in any order, they are the same triangle. To prove the formula is correct, I might Integrate the triangle area; Find the balance point of figure ABC; or, with compass and straightedge, draw the intersection of the medians. I say, the point is the same in every case.

B. Procedure
I will convert the problem into one I know how to solve:
Proposition: Find the centroid of a set of weighted points.

1. Chop Jerome up into mutually exclusive triangles.

2. Say there are m triangles. For each triangle $\;\Delta_k, \;k =1, 2, \ldots, m,\;$ find the centroid $C_k$, and the area (weight) $w_k$. The set of weighted points is then $[\frac{w_k C_k}{J}],$ where J is the area of Jerome.

3. Solution: Add 'em up. I say, the resulting point is the centroid of the polygon.

I have a general solution (I can always carry out this procedure). But it's messy: I don't have a triangulation rule. Now what? A good way to generalize is to start with a case I can solve.

C. Case: Jerome is Convex
It is commonly known that, given a convex polygon $P$, we may choose any vertex, $V,$ draw segments from $V$ to every non-adjacent vertex, and $P$ is correctly triangulated.

I will also use the following formulas:
-Let any two sides of $\Delta ABC$ be vectors ${\rm u, v}.\;$ Then
$\;\;\;{\rm Area}_{\Delta ABC} = \tfrac{1}{2}|{\rm u \times v}|,\;\;\;\;\;$where ${\rm u \times v}=u_1 v_2-u_2v_1$.

-Let sides $AB, AC$ of $\Delta ABC$ be vectors ${\rm u, v}.\;$ Then the centroid D= (A+B+C)/3 can be written
$\;\;\;D = A + \tfrac{1}{3}|{\rm u + v}|.$

I have gathered what I need.

D. Solution

1. Let the counterclockwise path of our n-gon be given, in order, by
$\;\;[A_i] = A_1, A_2, \ldots, A_n$
For covenience, I choose $V=A_1$.

2. Draw the n-1 vectors from A_1 to the other vertices:
$\;\;[{\rm a_i}] = (A_{k+1}-A_1),\;\; k = 1, 2, \ldots n\!-\!1$

3. I have n-2 adjacent triangles with centroids
$\;\;[C_i] = A_1 + \tfrac{1}{3}{\rm (a_k+a_{k+1})},\;\; k = 1, 2, \ldots n\!-\!2$
And areas (regions)
$\;\;[R_i] = \tfrac{1}{2}{\rm (a_k\times a_{k+1})},\;\; k = 1, 2, \ldots n\!-\!2$
(I did not take absolute value: counter-clockwise path, positive determinants.) Then
Total area = $\sum_{k=1}^{n-2} R_k$ and

4. The centroid $C_J$ of Jerome is the sum of weighted triangle 'roids, divided by total area:
$\;\;C_J= {\large \frac{\sum_{k=1}^{n-2} R_k C_k}{\sum_{k=1}^{n-2} R_k}}$,

which can be written

$$\;\;C_J= A_1+{\large \frac{1}{3} \frac{\sum_{k=1}^{n-2} ({\rm a_k+ a_{k+1}})({\rm a_k \times a_{k+1}})}{\sum_{k=1}^{n-2} ({\rm a_k \times a_{k+1}})} }$$

I say, that this is in fact the complete solution: the determinants give signed areas: +/- according as the direction of rotation from $A_k$ to $A_{k+1}$, about $A_1$ is positive or negative, preserving measure in either case.

Being the thing to be done.

-