ForHosting KIT · Math

Centroid of a triangle

Find a triangle's balance point from its three corners: vertices (0, 0), (6, 0) and (0, 9) give a centroid at (2, 3), the plain average of their x and y values. It is also where the three medians meet. Free in your browser.

  • Free
  • Runs in your browser
  • No sign-up
  • Your data stays on your device
Use it from WebAPIEmailTelegramApp soon
If you enter
X1
0
Y1
0
X2
6
Y2
0
X3
0
Y3
9
You get
X
2
Y
3

The centroid of a triangle is the point where its three medians meet, and it is also the triangle's balance point: if you cut the shape out of cardboard, it would rest level on a pin placed exactly there. You send six numbers, you get back the x and y of the centroid, rounded to six decimal places so the result is identical on every machine. No geometry engine, no approximation, no state — just the exact formula, validated and executed in one call.

What the centroid actually is

Every triangle has exactly one centroid, and it always lies inside the shape, no matter how stretched or skewed the triangle is. Geometrically it is the intersection of the three medians — the lines that join each vertex to the midpoint of the opposite side — and it divides each median in a two-to-one ratio, sitting twice as far from a vertex as from the opposite side.

Physically it is the center of mass of a uniform triangular plate, which is why engineers care about it when they compute loads and why physics textbooks call it the balance point. The remarkable thing about the centroid of a triangle is how cheap it is to compute from coordinates: you do not need to construct any median, measure any angle, or solve any equation.

The x coordinate of the centroid is the plain average of the three vertex x coordinates, and the y coordinate is the average of the three vertex y coordinates.

How to call it and what you get back

Each value must be a finite number. When the input is valid, the response is a single object with two keys, x and y, holding the centroid coordinates rounded to six decimal places. The rounding is deliberate: floating-point sums such as 0.1 + 0.2 + 0.3 can differ in the last bit between JavaScript engines, and an unrounded result could therefore compare differently on two machines; six decimals keep full practical precision while making the output byte-stable.

Where the centroid of a triangle is useful

In each case the value is not the arithmetic but the guarantee that every component of the system uses the same validated, identically rounded number, computed by one shared implementation instead of five divergent copies pasted into five codebases. There is no storage and no side effect: coordinates go in, a centroid comes out, and nothing is kept afterwards.

Label a triangular region on a map

Place a text label at the centroid of a triangular zone so it sits at the visual center of the shape regardless of how skewed the vertices are.

Center a camera or cursor on a face

Compute the centroid of a selected triangle in a mesh and move the viewport there in one call, using the same number every tool in the pipeline sees.

Normalize shapes before comparison

Translate triangles so their centroids sit at the origin, making rotation and scale comparisons independent of where the shape was drawn.

What formula does it use?

The centroid is the arithmetic mean of the vertices: x equals (x1 + x2 + x3) / 3 and y equals (y1 + y2 + y3) / 3.

Does the order of the vertices matter?

No. Averaging is commutative, so any labeling of the three vertices produces the same centroid.

Why is the result rounded to six decimals?

To keep the output byte-stable across JavaScript runtimes, whose floating-point sums can differ in the last bit. Six decimals keep full practical precision.

Can the centroid fall outside the triangle?

No. Every triangle has exactly one centroid and it always lies inside the shape, however stretched or skewed the triangle is. That makes it a safe spot for a map label or a grasp point.

How does the centroid divide each median?

In a two-to-one ratio. Along each median, the centroid sits twice as far from the vertex as from the midpoint of the opposite side.

Everything on this page is available programmatically. This section is for teams who want to wire it into their own systems; everyone else can just use the tool above.

POSThttps://api.kit.forhosting.com/math/centroid-of-a-triangle

Prefer to automate it? One authenticated POST creates the task; the result comes back by webhook or a signed link. The same capability also runs here on the web, by email and from Telegram — and soon from our app too.

curl -X POST https://api.kit.forhosting.com/math/centroid-of-a-triangle \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"x1":0,"y1":0,"x2":6,"y2":0,"x3":0,"y3":9}'
{
  "x1": 0,
  "y1": 0,
  "x2": 6,
  "y2": 0,
  "x3": 0,
  "y3": 9
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.centroid_of_a_triangle",
  "status": "queued",
  "_links": {
    "result": "/tasks/tsk_…/result"
  }
}

The API is asynchronous: the call returns a task_id immediately and the result arrives by webhook. Polling is capped at 1 req/s per task.

Per request$0.002

Published price — no tokens, no invented credits. A failed task is never charged.

HTTPCodeMeaning
401unauthorizedMissing or invalid API key.
402insufficient_balanceYour balance doesn't cover the task price.
404unknown_typeThat task type doesn't exist.
429rate_limitedToo many requests. Use the webhook instead of polling.

Given the coordinates of the three vertices, this endpoint computes that point directly as the arithmetic mean of the three x coordinates and of the three y coordinates.

What the centroid actually is

This endpoint applies that formula verbatim: it validates the six inputs, sums each axis, divides by three, and rounds the result to six decimal places so that the bytes you receive are stable across runtimes and platforms.

How to call it and what you get back

The request carries six required fields, x1 through y3, one x and one y for each of the three vertices, in any order — the average does not care which vertex you label first. If any coordinate is missing, is a string, or is NaN or Infinity, the call fails with an invalid_input error that names the offending field, and you are not charged for it; bad geometry never costs you anything.

Where a centroid endpoint earns its keep

The formula is trivial to write once, but endpoints like this earn their place when the computation must happen consistently in many places at once: a map service placing a label at the visual center of a triangular region, a game engine centering a camera on a selected face, a geometry pipeline normalizing shapes before comparison, or a robotics routine computing a grasp point over a triangular support polygon.

What does it cost?

$0.002 per request. It is also free to run in your browser on this page — the widget executes the exact same code.

What happens if a coordinate is missing or invalid?

The request fails with an invalid_input error naming the field, and it is not billed. Every coordinate must be a finite number.

Read the full KIT documentation →