ForHosting KIT · Math

Polygon diagonals calculator

Enter the number of sides and get how many diagonals the polygon has: a hexagon has 9, a pentagon 5, a quadrilateral 2 and a triangle none, all from the formula n(n−3)/2. 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
Sides
6
You get
Diagonals
9

A convex polygon with n sides has a fixed number of diagonals once n is known. From each vertex you can draw lines to every other vertex except itself and its two immediate neighbors, which gives n minus three diagonals leaving that vertex; counting every vertex double-counts each diagonal, so the total is n times n minus three over two. That single closed form recovers zero diagonals for a triangle, two for a quadrilateral, five for a pentagon, nine for a hexagon, and grows quadratically as n increases. Students meet the formula in combinatorics and plane geometry units; teachers and contest platforms need a stable numeric oracle; engineers sometimes need the count when budgeting chord layouts or graph edges on a cycle.

What a polygon diagonal is and why the count is n(n−3)/2

In a simple polygon a diagonal is a line segment that joins two non-adjacent vertices and lies in the interior of the figure when the polygon is convex. For a convex n-gon every pair of non-adjacent vertices determines exactly one such segment, so counting diagonals is a pure combinatorial problem on the vertex set. The complete graph on n labeled vertices has n choose two edges; the polygon already uses n of those edges as sides; the remainder are diagonals.

Algebraically that is n(n−1)/2 minus n, which simplifies to n(n−3)/2. The same expression appears if you fix a vertex, note that it contributes n minus three diagonals, multiply by n, and divide by two to undo double counting. Search intent clusters around polygon diagonals calculator, number of diagonals in a polygon, how many diagonals does an n-gon have, and the formula n times n minus three over two.

People want a number they can check against a textbook answer key or an automated grader, not only a proof sketch.

How this calculator validates input and applies the closed-form count

Non-numeric strings, missing fields, and non-integer side counts also fail with a clear message. After validation the engine evaluates diagonals as sides times sides minus three, all over two. For every integer n the product n times n minus three is even, so the quotient is always an exact integer with no floating-point rounding step.

Edge cases are explicit: sides equal to two or one, zero, negative values, and omitted sides all fail; sides equal to three succeeds and returns zero diagonals, which is the correct count for a triangle. Large but reasonable n values remain exact within JavaScript safe integer limits for typical homework and contest ranges; an upper bound rejects pathological inputs that would exceed the engine contract.

Practical use, limits, pricing, and delivery channels

Use the browser tool when you want an immediate diagonal count while checking homework, preparing contest solutions, or verifying a worksheet answer without installing a computer-algebra system. Results are fully deterministic: the same sides value always yields the same diagonals field and the same formula string. There is no language model, no external geometry service, and no randomness, so the capacity is safe to pin in continuous-integration checks and reproducible lesson materials.

Remember that this tool counts diagonals of a convex polygon; it does not measure diagonal lengths, does not draw the figure, and does not enumerate which vertex pairs form each diagonal.

Homework and exam polygon-diagonal drills

Students and graders confirm the number of diagonals for triangles through large n-gons, including zero diagonals for a triangle and rejection when the side count is below three.

Which formula does the calculator use?

Diagonals = n·(n−3)/2. A triangle has 0, a quadrilateral has 2, a pentagon has 5, and a hexagon has 9.

What happens if sides is below 3?

A convex polygon requires at least three sides; digons and monogons are rejected and those calls are not charged.

Is the polygon diagonals calculator free?

The browser tool runs free on your device.

Does this return diagonal lengths or only the count?

Only the count. The capacity returns how many diagonals a convex n-gon has; it does not compute lengths, coordinates, or drawings.

How many diagonals does a hexagon have?

A hexagon has 9 diagonals: six sides times three, divided by two. For comparison, a pentagon has 5, a quadrilateral 2 and a triangle has none, because every pair of its corners is already joined by a 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/geom/polygon-diagonals

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/geom/polygon-diagonals \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"sides":6}'
{
  "sides": 6
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "geom.polygon_diagonals",
  "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.

This capacity accepts an integer side count of three or more, rejects digons and monogons with a clear invalid_input error, and returns sides, diagonals, the formula string, and a method tag as structured JSON.

How this calculator validates input and applies the closed-form count

Send a JSON body with sides set to an integer greater than or equal to three. The field may also be supplied under the short alias n. Values below three fail with invalid_input because a convex Euclidean polygon under this contract needs at least three sides; digons and monogons are rejected before any arithmetic runs.

Practical use, limits, pricing, and delivery channels

Each successful request is one billable item at $0.002; failed validation does not consume balance. Accepted inputs must satisfy sides greater than or equal to three; digons, monogons, and non-integer side counts are rejected with a clear invalid_input message. Wire the endpoint into polygon drills, combinatorics answer checkers, graph-on-cycle edge counters, or floating preprocessing steps where you already prefer explicit domain errors over opaque black-box widgets that cannot show why sides below three are rejected.

Deterministic fixtures for geometry and combinatorics tests

Pipelines that seed unit tests or interactive polygon demos can call a pure diagonals oracle instead of reimplementing n(n−3)/2 in every language.

Lesson platforms and contest answer checkers

Online courses and contest systems need a stable JSON count for many n values under one contract, with clear invalid_input when n is not a valid polygon side count.

How do I compute the number of diagonals with this API?

Send a JSON body with sides (integer ≥ 3, alias n) to geom.polygon_diagonals. The response returns sides, diagonals, formula, and method.

Read the full KIT documentation →