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
|
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 |
||||
|
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)$$ |
|||||||||
|
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... – J. M. Dec 11 '11 at 14:19