Solve a right triangle from two legs
Enter the lengths of the two perpendicular legs to solve the complete right triangle in one calculation.
Run — free
The calculator applies the Pythagorean theorem to find the hypotenuse, uses inverse trigonometry to determine both acute angles in degrees, and reports the area and perimeter alongside the three side lengths. It is useful for checking homework, planning construction dimensions, preparing drawings, or automating geometry calculations. Both inputs must be finite numbers greater than zero because zero-length or negative sides cannot form a valid triangle.
Enter the two perpendicular leg lengths
A right triangle has two sides that meet at the ninety-degree angle. Those sides are called the legs, and this calculator labels them leg A and leg B. Enter one positive length for each leg, using the same unit for both values. The unit can be millimetres, centimetres, metres, inches, feet, or any other consistent length unit; because the equations are scale independent, you do not need to select that unit in the form. A 3-by-4 triangle, for example, returns a hypotenuse of 5 in the same unit. Decimal values are supported, so measurements such as 2.75 and 6.4 are valid. Do not include unit abbreviations inside a numeric field. Both legs must be finite and strictly greater than zero. A missing value, zero, a negative length, or text that is not a number produces a clear input error instead of a misleading geometric result. Keeping the input rule strict also makes this endpoint safe to place inside automated estimating and validation workflows.
Understand how every result is calculated
The hypotenuse is the side opposite the right angle and is always the longest side. It is calculated from the Pythagorean theorem as the square root of leg A squared plus leg B squared. Each acute angle is then calculated with a stable two-argument arctangent: angle A is opposite leg A, while angle B is opposite leg B. The two reported acute angles therefore add to ninety degrees, apart from harmless decimal rounding. Area is half the product of the legs because the legs are also the base and perpendicular height. Perimeter is the sum of leg A, leg B, and the calculated hypotenuse. Results are rounded to a consistent number of decimal places so small floating-point artifacts do not clutter the response. The calculator uses the entered scale without conversion: if both legs are in metres, side and perimeter results are metres and area is square metres. This direct correspondence makes the output easy to copy into a worksheet, drawing note, bill of quantities, or another API call.
Check and apply the solved triangle
Before relying on the answer, confirm that both entered values describe the perpendicular legs rather than a leg and the hypotenuse. This tool is intentionally designed for the two-leg case; entering the longest side as a leg creates a different valid triangle, but not the one you intended to model. You can perform quick consistency checks on the response: the hypotenuse must exceed either leg, the acute angles must each lie between zero and ninety degrees, their sum must be ninety degrees, and the perimeter must exceed twice the hypotenuse. Common uses include determining a diagonal brace from horizontal and vertical spans, finding a ramp or roof angle from rise and run, checking the diagonal of a rectangular panel, and completing right-triangle exercises. For automation, the API returns named numeric fields instead of a formatted paragraph, which lets a program store or compare individual measurements. Browser calculation is convenient for occasional work, while API requests cost $0.002 each when the same calculation needs to be repeated reliably in software.
What you can do with it
Calculate a rectangular diagonal
Use the rectangle's width and height as the two legs to find its corner-to-corner diagonal and associated angles.
Plan a ramp or roof slope
Enter horizontal run and vertical rise to obtain the sloped length, both acute angles, area, and perimeter.
Automate geometry checks
Return consistently named measurements for estimating software, educational tools, drawing validation, or engineering prechecks.
FAQ
What inputs are required?
Provide both perpendicular leg lengths as positive finite numbers. Use the same measurement unit for each leg.
Which angle is angle A?
Angle A is the acute angle opposite leg A. Angle B is opposite leg B, and the two add to 90 degrees.
What units does the calculator return?
Side lengths and perimeter use your input unit, area uses its square, and angles are returned in degrees.
Why are zero and negative lengths rejected?
A geometric triangle requires every side length to be greater than zero, so non-positive legs cannot define a valid right triangle.
How much does an API calculation cost?
Each API request costs $0.002. The browser calculator can be used directly for occasional interactive calculations.
For developers — API access
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.
API endpoint
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.
Call it from your stack
curl -X POST https://api.kit.forhosting.com/trig/right-triangle-two-legs \
-H "Authorization: Bearer $KIT_KEY" \
-H "Content-Type: application/json" \
-d '{"leg_a":3,"leg_b":4}'const res = await fetch("https://api.kit.forhosting.com/trig/right-triangle-two-legs", {
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.KIT_KEY}`,
"Content-Type": "application/json"
},
body: JSON.stringify({
"leg_a": 3,
"leg_b": 4
})
});
const { task_id } = await res.json();import os, requests
res = requests.post(
"https://api.kit.forhosting.com/trig/right-triangle-two-legs",
headers={"Authorization": f"Bearer {os.environ['KIT_KEY']}"},
json={
"leg_a": 3,
"leg_b": 4
},
)
task_id = res.json()["task_id"]<?php
$res = file_get_contents("https://api.kit.forhosting.com/trig/right-triangle-two-legs", false, stream_context_create([
"http" => [
"method" => "POST",
"header" => "Authorization: Bearer " . getenv("KIT_KEY") . "\r\nContent-Type: application/json",
"content" => '{"leg_a":3,"leg_b":4}',
],
]));
$task = json_decode($res, true);body := bytes.NewBufferString(`{"leg_a":3,"leg_b":4}`)
req, _ := http.NewRequest("POST", "https://api.kit.forhosting.com/trig/right-triangle-two-legs", body)
req.Header.Set("Authorization", "Bearer "+os.Getenv("KIT_KEY"))
req.Header.Set("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)Example request
{
"leg_a": 3,
"leg_b": 4
}Example response
{
"task_id": "tsk_a1b2c3d4e5f6a1b2c3d4e5f6",
"type": "trig.right_triangle_two_legs",
"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.
Pricing
Published price — no tokens, no invented credits. A failed task is never charged.
Errors
| HTTP | Code | Meaning |
|---|---|---|
401 | unauthorized | Missing or invalid API key. |
402 | insufficient_balance | Your balance doesn't cover the task price. |
404 | unknown_type | That task type doesn't exist. |
429 | rate_limited | Too many requests. Use the webhook instead of polling. |