Centroid of a Polygon: Easy Formula, Examples & Step-by-Step Guide

Isabella Sep 08, 2026

Ask most people where the center of a triangle sits and they will confidently point to the spot where the three medians cross. That intuition holds up beautifully for triangles, but the moment you move to a four-sided shape, a fifty-sided property boundary, or an irregular lake outline, the answer stops being obvious. The centroid of a polygon is the single point that balances the entire shape as if it were cut from a sheet of perfectly uniform material, and finding it takes more than a quick average of coordinates.

Area of a Polygon Formulas – Triangle, Quadrilateral, Rhombus, Rectangle, Square and Trapezoid
Area of a Polygon Formulas – Triangle, Quadrilateral, Rhombus, Rectangle, Square and Trapezoid

Whether you are writing GIS software, placing a label on a map region, computing the pivot point for a rotating game sprite, or setting up a finite element model, the centroid is one of the most frequently requested values in geometry code. This article walks through what the centroid actually represents, how the standard shoelace-based algorithm derives it, and which edge cases tend to break naive implementations in production systems.

Illustrative Mathematics
Illustrative Mathematics

What Exactly Is the Centroid of a Polygon?

The centroid of a two-dimensional polygon is the point where the total first moment of area equals zero in every direction. In plain language, imagine cutting the polygon out of a rigid sheet of metal with uniform thickness and density, then trying to balance it on the tip of a pencil. The point where it balances is the centroid. Mathematically, it is the area-weighted average position of every infinitesimal piece of the region, which is why a large lobe of a shape pulls the centroid toward itself far more than a small, narrow sliver does.

Geometry Worksheets
Geometry Worksheets

For convex polygons such as rectangles, regular polygons, and triangles, the centroid always lies strictly inside the shape. Concave polygons break that guarantee. A crescent, a horseshoe, or an L-shaped floor plan can have a centroid that falls outside the boundary entirely, floating in the empty space between the arms of the shape. This is not a bug or a numerical failure; it is a direct consequence of how area moments distribute weight across a non-convex region.

Geometric Center Versus Center of Mass

Centroid of a Triangle: Intersection of Three Medians
Centroid of a Triangle: Intersection of Three Medians

The terms centroid and center of mass get used interchangeably, and for most practical purposes they are the same thing. The distinction only matters when density varies. A uniform steel plate and its geometric outline share an identical centroid and center of mass, but a plate that is twice as thick on one side has a center of mass shifted toward the heavier half while the geometric centroid remains fixed on the outline's shape. When people talk about the centroid of a polygon, they almost always mean the purely geometric, area-weighted point.

It also helps to separate the centroid from other "centers" that get conflated with it. The circumcenter is equidistant from all vertices, the incenter is equidistant from all edges, and the bounding-box center is simply the midpoint of the axis-aligned extents. Each of these produces a different point and each solves a different problem. Label placement algorithms, for instance, sometimes prefer the pole of inaccessibility because it guarantees a point inside the shape with maximum clearance, something the centroid cannot promise for concave geometry.

Why the Vertex Average Is Usually Wrong

Mastering Centroids:  A Guide to Calculating the Balance Point of Compound Shapes
Mastering Centroids:  A Guide to Calculating the Balance Point of Compound Shapes

A tempting shortcut is to add up all the vertex coordinates and divide by the number of vertices. This approach, sometimes called the vertex centroid or barycenter of the point set, treats every vertex as equally important. Polygon area does not work that way. A long straight edge contributes only two vertices no matter how long it is, while a tightly clustered set of vertices along a curved segment contributes many points to the average. The result gets dragged toward regions with dense vertex spacing rather than toward regions with large actual area.

There are a few special cases where the shortcut happens to be correct. Any triangle, any parallelogram, and any polygon with sufficient rotational or affine symmetry will produce the same answer either way, which is exactly why the mistake is so easy to make during quick testing. Test your implementation against an asymmetric shape before trusting it. A simple irregular quadrilateral with one clipped corner is usually enough to expose the flaw immediately.

The Standard Formula Behind the Computation

Theorems on Centroid, Orthocenter, and Circumcenter
Theorems on Centroid, Orthocenter, and Circumcenter

Computing a polygon centroid reliably requires two ingredients: the polygon's signed area and its first moments about the coordinate axes. Both come from the same compact double summation, often called the shoelace formula or Gauss's area formula. The centroid formulas that follow are direct algebraic consequences of applying the centroid definition to a triangulated version of the polygon, with every triangle sharing the origin as a common vertex.

One elegant property of this approach is translation invariance. The origin itself is arbitrary; the algebra is constructed so that whatever contribution the origin makes to the individual triangles cancels out in the final sum. That means you can shift your coordinate system anywhere convenient, including to a point near the polygon, without changing the result. It also means the algorithm runs comfortably in linear time with respect to the number of vertices, using a single pass and a handful of accumulators.

an image of polygons and their properties
an image of polygons and their properties
an octagon is shown with numbers on the side and two circles in the middle
an octagon is shown with numbers on the side and two circles in the middle
four different types of intersecting triangles with the names and their corresponding angles in each triangle
four different types of intersecting triangles with the names and their corresponding angles in each triangle
Interactive Math Activities, Demonstrations, Lessons with definitions and examples, worksheets, Interactive Activities and other Resources
Interactive Math Activities, Demonstrations, Lessons with definitions and examples, worksheets, Interactive Activities and other Resources
Medians and Centroid Dance
Medians and Centroid Dance
Each Interior Angle of a Regular Polygon Explained | Easy Geometry Formula Guide
Each Interior Angle of a Regular Polygon Explained | Easy Geometry Formula Guide
a circle with different colored lines in it
a circle with different colored lines in it
an inscribed circle with two intersecting lines in the center
an inscribed circle with two intersecting lines in the center
36 Facts About Centroid
36 Facts About Centroid
File:Regular polygon 20 annotated.svg - Wikimedia Commons
File:Regular polygon 20 annotated.svg - Wikimedia Commons

Signed Area and the Shoelace Identity

Before the centroid can be computed, the signed area must be established. For a polygon with vertices (x_1, y_1) through (x_n, y_n) listed in order around the perimeter, the signed area is given by A = 1/2 × Σ (x_i × y_(i+1) − x_(i+1) × y_i), where the index wraps around so that vertex n connects back to vertex 1. If the vertices are ordered counterclockwise, this value is positive. If they are ordered clockwise, it comes out negative. The absolute value is the true area; the sign is a useful diagnostic.

With the signed area in hand, the centroid coordinates follow from two more accumulations. The x-coordinate is Cx = 1/(6A) × Σ (x_i + x_(i+1)) × (x_i × y_(i+1) − x_(i+1) × y_i), and the y-coordinate uses the identical structure with (y_i + y_(i+1)) in place of the x sum. Notice that the term inside the second set of parentheses is the same cross product that appears in the shoelace area, so a well-written implementation computes it once per edge and reuses it for all three accumulations.

The complete algorithm, in order, looks like this:

  1. Verify that the vertex list contains at least three points and that the first point is not duplicated at the end of the list.
  2. Walk the edges, computing the cross product x_i × y_(i+1) − x_(i+1) × y_i for each pair of consecutive vertices, including the closing edge from the last vertex back to the first.
  3. Accumulate the cross products to obtain twice the signed area, and accumulate (x_i + x_(i+1)) times the cross product for the x moment and (y_i + y_(i+1)) times the cross product for the y moment.
  4. Divide the x and y moment sums by three times the signed area total, then verify the result lies within the polygon's bounding box as a sanity check.

Because the signed area appears in the denominator, any polygon with zero net area will produce a division by zero. Self-intersecting shapes and degenerate point sets both fall into that category, so a robust routine should test the area magnitude against a small epsilon before performing the final division and return a sensible fallback, such as the bounding box center, when the test fails.

A Complete Worked Example

Take an irregular quadrilateral with vertices listed counterclockwise: A(2, 1), B(8, 2), C(6, 7), and D(1, 4). Walking the edges and computing each cross product gives −4 for AB, 44 for BC, 17 for CD, and −7 for DA. Those four values sum to 50, so the signed area is 25 square units and the winding direction is confirmed as counterclockwise.

For the x moment, multiply each cross product by the sum of the two x-coordinates on that edge: (2 + 8) × (−4) = −40, (8 + 6) × 44 = 616, (6 + 1) × 17 = 119, and (1 + 2) × (−7) = −21. The total is 674, and dividing by six times the area gives Cx = 674 / 150 ≈ 4.4933. Repeating the process with the y-coordinate sums yields (1 + 2) × (−4) = −12, (2 + 7) × 44 = 396, (7 + 4) × 17 = 187, and (4 + 1) × (−7) = −35, for a total of 536 and Cy = 536 / 150 ≈ 3.5733.

Now compare that answer to the naive vertex average, which comes out to (4.25, 3.5). The two points sit roughly a quarter of a unit apart, a difference that would be clearly visible if you dropped a marker at each location. That gap is not rounding error; it is the structural difference between weighting vertices equally and weighting area correctly.

Degenerate and Tricky Cases

Polygons with holes, such as the boundary of a lake containing an island, cannot be treated as a single simple ring. The usual technique is to model the outer boundary and each hole as separate closed rings, then combine the results as area-weighted contributions, treating holes with reversed winding so their signed areas subtract. Concatenating an outer ring and an inner ring into one vertex list without adjusting the winding produces garbage, and the failure is often subtle enough to slip through casual testing.

Self-intersecting polygons, often called complex or "bowtie" polygons, produce a signed area that reflects the algebraic sum of the lobes rather than any physical area. If the two lobes have equal magnitude, the signed area is zero and the centroid is undefined by the formula even though the shape clearly has a visual middle. Most geometry libraries handle this by rejecting the input, while a few compute something closer to a lamina centroid using absolute areas. Know which behavior your downstream code expects before choosing a library.

Floating-point precision also deserves attention. When coordinates are very large, such as unprojected latitude and longitude values, or when the polygon is very small relative to its distance from the origin, the intermediate products can lose significant digits. Subtracting a local reference point from every vertex before running the accumulation restores accuracy at almost no cost, and the result can be shifted back afterward because the algorithm is translation invariant.

Where Centroid Calculations Matter in Practice

The centroid shows up in far more places than most developers expect. It is a building block in map rendering, collision detection, physics simulation, mesh analysis, and even in the automated placement of annotation callouts on technical drawings. Whenever software needs a single representative point that genuinely reflects a shape's mass distribution, the centroid is the default candidate.

What makes it so broadly useful is its stability. Small perturbations to a polygon's vertices produce proportionally small changes in the centroid, whereas metrics like the bounding box center can jump abruptly when an extreme vertex moves. That smooth, area-weighted behavior is exactly what you want when a point needs to track a shape as it deforms, animates, or gets edited by a user dragging a control handle.

Geographic Information Systems and Map Labeling

In GIS work, the centroid is the go-to anchor for labeling counties, parcels, census tracts, and hydrological features. Rendering a name at the centroid produces a label that visually feels centered on the region, even when the boundary is highly irregular. Many cartographic pipelines pair the centroid with a containment test: if the point falls outside the polygon, as happens with crescent-shaped or U-shaped regions, the algorithm switches to the pole of inaccessibility or a weighted variant to keep the text inside the boundary.

Geographic coordinates introduce complications that planar geometry does not have. A polygon crossing the antimeridian can produce a wildly incorrect centroid if the longitude values are naively averaged, because the ring appears to straddle the entire globe. Similarly, computing a centroid in raw latitude and longitude is not the same as computing it in an equal-area projection, and the discrepancy grows with latitude. Serious cartographic software projects the polygon into a suitable equal-area coordinate system, computes the centroid there, and then transforms the result back.

Game Development and Physics Simulation

In game engines, the centroid serves as the natural pivot for rotating a sprite, a mesh, or a collider around its own visual center. Setting an object's origin to its centroid makes torque calculations feel correct, prevents the object from appearing to orbit an arbitrary point, and simplifies the math for rigid body dynamics. When a destructible object breaks apart, each fragment's centroid becomes its local origin and its center of mass for subsequent physics simulation.

Collision detection benefits as well. A broad-phase test can approximate each polygon with a circle centered at its centroid and radius equal to the farthest vertex distance, which cheaply rules out most non-colliding pairs before any narrow-phase work begins. Spawning particles, placing decals, or positioning a camera focus point inside a playable region all rely on the same underlying computation, usually called thousands of times per second across a scene.

Understanding the centroid properly pays off the first time a shape misbehaves in your code and you can trace the problem back to an averaged vertex list or a ring with the wrong winding order. The formula itself is only four lines of arithmetic, and once it is wrapped in a function that handles degenerate inputs, it will quietly serve every rotation, label, and mass calculation you throw at it for years.