Centroid Calculator
Calculate the centroid (center of mass) of any 2D polygon. Enter vertices or draw interactively. Supports composite shapes with Shoelace formula.
About
Miscalculating a centroid propagates errors into every downstream computation: structural load analysis shifts, CNC toolpath offsets drift, and finite-element meshes distort. This tool computes the geometric centroid C(xฬ , yฬ ) of any simple (non-self-intersecting) polygon using the exact closed-form solution derived from the Shoelace (Gauss) area formula. It handles convex and concave polygons with n โฅ 3 vertices. The algorithm runs in O(n) time and produces machine-precision results identical to those from ISO 16792-compliant CAD software. Note: this tool assumes a planar, non-self-intersecting polygon with uniform density. For shapes with holes or variable density, decompose into sub-regions and apply the composite centroid method provided in the reference table.
Formulas
The centroid of a simple polygon with n vertices (x0, y0), โฆ, (xnโ1, ynโ1) is computed from the signed area and first moments.
Signed area via the Shoelace formula:
A = 12 nโ1โi=0 (xiyi+1 โ xi+1yi)Centroid coordinates:
Cx = 16A nโ1โi=0 (xi + xi+1)(xiyi+1 โ xi+1yi)Cy = 16A nโ1โi=0 (yi + yi+1)(xiyi+1 โ xi+1yi)
Where A = signed area of the polygon (positive for CCW winding). xi, yi = coordinates of the i-th vertex. Index n wraps to 0 (i.e., xn = x0). For composite shapes, the weighted centroid is C = โ Ai โ Ciโ Ai, where subtracted regions use negative area.
Reference Data
| Shape | Centroid Location | Area Formula | Notes |
|---|---|---|---|
| Triangle | (x1+x2+x33, y1+y2+y33) | 12|x1(y2โy3)+x2(y3โy1)+x3(y1โy2)| | Intersection of medians |
| Rectangle | (w2, h2) | w ร h | Geometric center |
| Circle | Center point | ฯr2 | By symmetry |
| Semicircle | (0, 4r3ฯ) | ฯr22 | Above diameter axis |
| Quarter Circle | (4r3ฯ, 4r3ฯ) | ฯr24 | First quadrant |
| Right Triangle | (b3, h3) | 12bh | From right-angle vertex |
| Trapezoid | yฬ = h3 โ a+2ba+b | (a+b)2h | a, b are parallel sides |
| Regular Pentagon | Geometric center | 54s2 โ cot(ฯ5) | All regular polygons: centroid = center |
| Regular Hexagon | Geometric center | 3โ32s2 | 6 equilateral triangles |
| Ellipse | Center point | ฯab | By dual symmetry |
| Circular Sector | 2r sinฮธ3ฮธ | r2ฮธ2 | ฮธ in radians, from center along bisector |
| Parabolic Segment | (0, 2h5) | 23bh | From base midpoint |
| Composite Shape | โAiCiโAi | Sum of sub-areas | Subtract holes with negative A |
| I-Beam (Composite) | Weighted average of 3 rectangles | Sum of flange + web areas | Critical for structural engineering |
| L-Shape (Angle) | Weighted average of 2 rectangles | Sum of leg areas | Centroid lies outside shape if thin |