{
  "id": "centroid",
  "version": "8076b6742cee",
  "status": "published",
  "name": "Centroid Calculator",
  "question": "Where is the centroid?",
  "summary": "Finds the centroid of a triangle or any set of points (with optional masses), or the centroid of a polygon’s area from its vertices, with the working.",
  "category": "math",
  "subcategory": "geometry",
  "url": "https://www.acalculator.org/math/centroid-calculator",
  "markdown": "https://www.acalculator.org/math/centroid-calculator.md",
  "kind": "function",
  "method": "Points: x̄ = Σmx ÷ Σm, ȳ = Σmy ÷ Σm (m = 1 when no mass is typed). Polygon: A = ½Σ(xᵢyᵢ₊₁ − xᵢ₊₁yᵢ), x̄ = Σ(xᵢ + xᵢ₊₁)(xᵢyᵢ₊₁ − xᵢ₊₁yᵢ) ÷ 6A, ȳ = Σ(yᵢ + yᵢ₊₁)(xᵢyᵢ₊₁ − xᵢ₊₁yᵢ) ÷ 6A.",
  "assumptions": [
    "A triangle’s centroid is the same as the centroid of its three vertices with equal masses.",
    "Polygon vertices are typed in order around the outline (either direction), and the outline does not cross itself.",
    "Typed decimals are read exactly; each result is rounded once."
  ],
  "inputs": {
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "type": "object",
    "properties": {
      "mode": {
        "title": "Find the centroid of",
        "description": "The points themselves (a triangle’s vertices, or point masses) or the area inside a polygon.",
        "type": "string",
        "enum": [
          "points",
          "polygon"
        ]
      },
      "points": {
        "title": "Points",
        "description": "The points or vertices in order around the shape, up to 20. A mass applies to points only.",
        "type": "array",
        "items": {
          "type": "object",
          "properties": {
            "x": {
              "title": "x",
              "description": "The x coordinate.",
              "type": "number",
              "minimum": -1000000000000,
              "maximum": 1000000000000
            },
            "y": {
              "title": "y",
              "description": "The y coordinate.",
              "type": "number",
              "minimum": -1000000000000,
              "maximum": 1000000000000
            },
            "m": {
              "title": "Mass (optional)",
              "description": "The mass or weight of this point; 1 when left empty. Ignored for a polygon.",
              "type": "number",
              "exclusiveMinimum": 0,
              "maximum": 1000000000000
            }
          }
        }
      }
    }
  },
  "outputs": {
    "centroid": {
      "label": "Centroid",
      "description": "The centroid (x̄, ȳ).",
      "format": "text"
    },
    "cx": {
      "label": "x̄",
      "description": "The x coordinate of the centroid.",
      "format": "number"
    },
    "cy": {
      "label": "ȳ",
      "description": "The y coordinate of the centroid.",
      "format": "number"
    },
    "area": {
      "label": "Polygon area",
      "description": "The area inside the polygon, from the shoelace formula (polygon only).",
      "format": "number"
    },
    "steps": {
      "label": "Working",
      "description": "The sums and the division.",
      "format": "text"
    }
  },
  "defaultAnswer": {
    "inputs": {
      "mode": "points",
      "points": [
        {
          "x": 0,
          "y": 0
        },
        {
          "x": 6,
          "y": 0
        },
        {
          "x": 0,
          "y": 3
        }
      ]
    },
    "outputs": {
      "centroid": "(2, 1)",
      "cx": 2,
      "cy": 1,
      "steps": "total mass m = 3; Σmx = 6; x̄ = 6 ÷ 3 = 2; Σmy = 3; ȳ = 3 ÷ 3 = 1"
    },
    "text": "The centroid is at (2, 1)."
  },
  "examples": [
    {
      "given": {
        "mode": "points",
        "points": [
          {
            "x": -1,
            "y": 3,
            "m": 2
          },
          {
            "x": 1,
            "y": 1,
            "m": 6
          },
          {
            "x": 2,
            "y": -2,
            "m": 4
          }
        ]
      },
      "expect": {
        "centroid": "(1, 0.3333333333)",
        "cx": 1,
        "cy": 0.3333333333333333
      },
      "source": "OpenStax, Calculus Volume 2, §2.6 Moments and Centers of Mass (x̄ = My ÷ m, ȳ = Mx ÷ m for point masses; Example 2.30: 2 kg at (−1, 3), 6 kg at (1, 1) and 4 kg at (2, −2) balance at (1, 1/3)), https://openstax.org/books/calculus-volume-2/pages/2-6-moments-and-centers-of-mass (retrieved 2026-10-05)"
    },
    {
      "given": {
        "mode": "points",
        "points": [
          {
            "x": 0,
            "y": 0
          },
          {
            "x": 6,
            "y": 0
          },
          {
            "x": 0,
            "y": 3
          }
        ]
      },
      "expect": {
        "centroid": "(2, 1)"
      },
      "source": "hand calculation in content.mdx: ((0 + 6 + 0) ÷ 3, (0 + 0 + 3) ÷ 3); OpenStax, Calculus Volume 2, §2.6 Moments and Centers of Mass (x̄ = My ÷ m, ȳ = Mx ÷ m for point masses; Example 2.30: 2 kg at (−1, 3), 6 kg at (1, 1) and 4 kg at (2, −2) balance at (1, 1/3)), https://openstax.org/books/calculus-volume-2/pages/2-6-moments-and-centers-of-mass (retrieved 2026-10-05)"
    },
    {
      "given": {
        "mode": "polygon",
        "points": [
          {
            "x": 0,
            "y": 0
          },
          {
            "x": 6,
            "y": 0
          },
          {
            "x": 0,
            "y": 3
          }
        ]
      },
      "expect": {
        "centroid": "(2, 1)",
        "area": 9
      },
      "source": "hand calculation in content.mdx; Wikipedia, Centroid, section \"Of a polygon\" (the shoelace area and Cx = (1 ÷ 6A)Σ(xᵢ + xᵢ₊₁)(xᵢyᵢ₊₁ − xᵢ₊₁yᵢ)), https://en.wikipedia.org/wiki/Centroid#Of_a_polygon (retrieved 2026-10-05)"
    },
    {
      "given": {
        "mode": "polygon",
        "points": [
          {
            "x": 0,
            "y": 0
          },
          {
            "x": 4,
            "y": 0
          },
          {
            "x": 4,
            "y": 1
          },
          {
            "x": 1,
            "y": 1
          },
          {
            "x": 1,
            "y": 3
          },
          {
            "x": 0,
            "y": 3
          }
        ]
      },
      "expect": {
        "centroid": "(1.5, 1)",
        "cx": 1.5,
        "cy": 1,
        "area": 6
      },
      "source": "hand calculation in content.mdx: (4 × (2, 0.5) + 2 × (0.5, 2)) ÷ 6 = (1.5, 1); Wikipedia, Centroid, section \"Of a polygon\" (the shoelace area and Cx = (1 ÷ 6A)Σ(xᵢ + xᵢ₊₁)(xᵢyᵢ₊₁ − xᵢ₊₁yᵢ)), https://en.wikipedia.org/wiki/Centroid#Of_a_polygon (retrieved 2026-10-05)"
    }
  ],
  "sources": [
    "OpenStax, Calculus Volume 2, §2.6 Moments and Centers of Mass (x̄ = My ÷ m and ȳ = Mx ÷ m for point masses in a plane; Example 2.30), CC BY-NC-SA 4.0. https://openstax.org/books/calculus-volume-2/pages/2-6-moments-and-centers-of-mass (retrieved 2026-10-05)",
    "Wikipedia, Centroid, section \"Of a polygon\" (the shoelace area and the centroid sums for a non-self-intersecting closed polygon). https://en.wikipedia.org/wiki/Centroid#Of_a_polygon (retrieved 2026-10-05)"
  ],
  "related": [
    "midpoint",
    "orthocenter",
    "triangle",
    "area"
  ],
  "changelog": []
}
