My apologies for taking a break from the quadratic programming thread. I will be coming back to it. But for now I thought I would record a method for finding the true centroid of a planar polygon, given as a sequence of vertices that traverse the boundary in order. A quick and dirty approximation is to simply take the barycenter of the vertices. This is often good enough, and for convex polygons, is guaranteed to lie within the interior of the polygon, but consider the following example. Take any polygon and then split one of its vertices into two vertices connected by a very short edge. This new polygon should have approximately the same centroid, but the barycenter of its vertices changes quite a bit since the split vertex now exerts twice the pull on the centroid than it did before.
Luckily there is a very simple way to get the centroid, at least for planar polygons. I believe the formulas should generalize to higher dimensional embeddings of polygons, but have not given the matter sufficient thought. We start with Green's Theorem
$$\iint_R \frac{\partial M}{\partial x}-\frac{\partial L}{\partial y}\,dx\,dy = \oint_{\partial R} L\,dx+M\,dy$$
for integrating a 1-form on the boundary of a region.
As a warm-up, let $M=x$ and $L=0$. Then we discover that the area of the polygon is the integral
$$\oint_{\partial R} x\,dy$$ along its boundary. This integral can be evaluated on each line segment comprising the boundary to get a simple combinatorial formula.
Let $p_0=\left(\begin{matrix} x_0\\y_0\end{matrix}\right)$ and $p_1=\left(\begin{matrix} x_1\\y_1\end{matrix}\right)$. Then the path connecting them is $(1-t)p_0+tp_1$ for $0\leq t \leq 1$.
Then $dy = (y_1-y_0)\,dt$ and $x= (1-t)x_0+tx_1$, so we get
$$\int_0^1 ((1-t)x_0+tx_1)(y_1-y_0)\,dt= \frac{1}{2}(x_1+x_0)(y_1-y_0).$$
This gives us a beautiful formula for area. If the polygon has $n$ points $p_1,\ldots,p_n$ we have
$$A=\frac{1}{2}\sum_{i=1}^n(x_i+x_{i+1})(y_{i+1}-y_i)$$
where the indices are read modulo $n$. $x_{n+1}=x_1, y_{n+1}=y_1$. As an exercise see if you can find two more similar formulas for area with different choices of $L$ and $M$ above. These types of formulas are the basis for mechanical planimeters which calculate area by tracing around the perimeter.
Returning to the centroid, we need to calculate the average position of both $x$ and $y$:
$$\overline{x} = \frac{1}{A}\iint_R x\,dx\,dy,\,\,\,\overline{y} = \frac{1}{A}\iint_R y\,dx\,dy$$
Tackling the $x$ coordinate, let $M=\frac{x^2}{2}$ and $L=0$. Then we have
$$\iint_R x\,dx = \sum_{i=1}^n\int_0^1 \frac{((1-t)x_i)^2+t x_{i+1}}{2}(y_{i+1}-y_i)\,dt$$
$$\iint_R x\,dx = \frac{1}{6}\sum_{i=1}^n (x_i^2+x_ix_{i+1}+x_{i+1}^2)(y_{i+1}-y_i)$$
In a similar way we can derive the formula
$$\iint_R y\,dy = \frac{1}{6}\sum_{i=1}^n (y_i^2+y_iy_{i+1}+y_{i+1}^2)(x_{i}-x_{i+1}).$$
It does not feel to me like these formulas are unique to planar embeddings of polygons, but the technique of proof, using Green's theorem, will not work for higher ambient dimensions.