ForHosting KIT · Math

Length and width of a rectangle from perimeter and side ratio

Enter a rectangle's perimeter and the ratio of its sides and get both dimensions: a perimeter of 36 with a 2 to 1 ratio gives a length of 12 and a width of 6. Handy for fencing, frames with a fixed proportion and homework. 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
Perimeter
36
Ratio
2
You get
Length
12
Width
6

Given the perimeter of a rectangle and the ratio between its sides, this capability recovers the two dimensions: the length and the width. The problem shows up constantly — a fence budget fixes the perimeter, a design fixes the proportion, and what you actually need is the two side lengths.

From perimeter and ratio to real dimensions

A perimeter alone does not determine a rectangle: infinitely many pairs of length and width add up to the same perimeter. The missing piece of information is the proportion between the sides. Once you know that the length is, say, twice the width, the geometry collapses into one equation.

Half the perimeter equals the length plus the width, so the width is that semi-perimeter divided by the ratio plus one, and the length follows by multiplying the width by the ratio. You send two numbers, you get back two numbers, and the result is the same every time because there is no randomness, no clock and no network involved anywhere in the calculation.

How the inputs are validated and normalized

Both inputs must be positive finite numbers, and both are checked before any arithmetic happens. One deliberate normalization deserves a mention: the ratio is defined as length divided by width, with the length being the longer side, so a ratio below one describes the same rectangle looked at from the other side. Numeric strings such as "2.5" are accepted, which keeps form submissions simple.

Where it fits and what it costs

The typical caller is a tool, not a person: a fencing calculator that has a total budget of material, a layout engine that must fit a panel of fixed aspect ratio into a fixed border length, a homework checker validating student answers, or a generator producing consistent geometry exercises. Results are rounded to six decimal places so that automated comparisons stay stable across machines.

Layout with a fixed aspect ratio

A frame's total trim length is fixed and the panel must keep a 16:9 proportion. Get the exact panel dimensions in one call.

Generating or checking math exercises

Produce consistent rectangle problems or verify student answers programmatically from a perimeter and a ratio.

Can the ratio be less than 1?

Yes. The ratio is defined as length over width with length as the longer side, so a value below 1 is replaced by its reciprocal. The normalized ratio is included in the output.

How precise is the result?

Length and width are rounded to six decimal places so the output is stable and byte-for-byte reproducible across machines.

Can I send numbers as strings?

Yes. Numeric strings like "36" or "2.5" are accepted, but anything that does not parse as a positive finite number is rejected.

Is anything stored?

No. The two numbers are processed and discarded; only the computed dimensions are returned.

How are the two sides worked out from the perimeter?

Half the perimeter is the length plus the width, and the ratio splits that half into parts. With 36 and a 2 to 1 ratio, the half is cut into three parts: the width gets one, 6, and the length two, 12.

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/length-and-width-of-rectangle-given-perimeter

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/length-and-width-of-rectangle-given-perimeter \
  -H "Authorization: Bearer $KIT_KEY" \
  -H "Content-Type: application/json" \
  -d '{"perimeter":36,"ratio":2}'
{
  "perimeter": 36,
  "ratio": 2
}
{
  "task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
  "type": "math.length_and_width_of_rectangle_given_perimeter",
  "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.

max_mb1
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.

The endpoint solves the small linear system deterministically: half the perimeter is the sum of the sides, and the ratio distributes that sum between length and width. It runs free in your browser on this page, and the same code answers API calls at $0.002 per request.

From perimeter and ratio to real dimensions

The length and width of rectangle given perimeter endpoint performs exactly this computation and returns both sides, plus the normalized ratio it used.

How the inputs are validated and normalized

A perimeter of zero or less is not a rectangle, and neither is a ratio of zero, a negative ratio, an infinite value or a piece of text that does not parse as a number; every one of those is rejected with a typed invalid_input error that is never billed. Rather than failing, the endpoint swaps it for its reciprocal and reports the normalized ratio in the output, so a ratio of 0.5 and a ratio of 2 produce the same rectangle.

Where it fits and what it costs

Because the math is a handful of floating-point operations, the response is essentially instant and the cost is a flat $0.002 per request — there is no per-unit surcharge, since the work does not grow with the size of the numbers. The identical code runs on this page for free, so you can verify an answer by hand before wiring the API into your system, and you only pay once you automate the calls.

Fence and border planning

You have 120 meters of fencing and want a pen twice as long as it is wide. The endpoint returns length 40, width 20 — no trial and error.

What does it cost?

$0.002 per request, flat. It is also free to run in your browser on this page.

What happens if the perimeter is zero or negative?

The request is rejected with an invalid_input error stating that the perimeter must be a positive finite number. Rejected requests are never billed.

Read the full KIT documentation →