Calculate the unknown angles of a right triangle using the lengths of two sides.
Side A
Side B
Hypotenuse
Degrees
Radians
Enter values to see results here.
Understanding Right Triangles and Angle Calculations
A right triangle is a fundamental geometric shape defined by having one angle that measures exactly 90 degrees (a right angle). The other two angles, by necessity, must be acute (less than 90 degrees) because the sum of all angles in any triangle is always 180 degrees. In a right triangle, the side opposite the right angle is called the hypotenuse, and it is always the longest side. The other two sides are referred to as legs.
The Pythagorean Theorem
The relationship between the sides of a right triangle is governed by the Pythagorean theorem: a² + b² = c², where a and b are the lengths of the legs, and c is the length of the hypotenuse.
Trigonometric Functions (SOH CAH TOA)
To find the angles (other than the right angle), we use trigonometric functions. These functions relate the ratios of the sides of a right triangle to its angles:
Sine (sin): sin(angle) = Opposite / Hypotenuse (SOH)
To find an angle when you know the ratio of sides, you use the inverse trigonometric functions:
Angle = arcsin(Opposite / Hypotenuse)
Angle = arccos(Adjacent / Hypotenuse)
Angle = arctan(Opposite / Adjacent)
How This Calculator Works
This calculator allows you to input the lengths of two sides of a right triangle and, optionally, the length of the third side. Based on the provided values, it calculates the two unknown acute angles. The calculator uses JavaScript's built-in `Math` object, specifically `Math.asin()`, `Math.acos()`, and `Math.atan()` for calculating angles from side ratios. The results can be displayed in either degrees or radians, as selected by the user.
Formulas Used:
If Side A and Side B are known:
Angle A = arctan(Side A / Side B)
Angle B = arctan(Side B / Side A)
If Side A and Hypotenuse (Side C) are known:
Angle A = arcsin(Side A / Side C)
Angle B = arccos(Side A / Side C) (or 90° – Angle A)
If Side B and Hypotenuse (Side C) are known:
Angle B = arcsin(Side B / Side C)
Angle A = arccos(Side B / Side C) (or 90° – Angle B)
If all three sides are provided, the calculator verifies if they form a valid right triangle using the Pythagorean theorem. If the provided side lengths do not form a valid right triangle, an appropriate message will be displayed. The calculator prioritizes using the two legs (Side A and Side B) if all sides are provided, as this is a common scenario.
Use Cases
This calculator is useful for:
Students learning trigonometry and geometry.
Engineers and surveyors working with right-angle measurements.
Builders and architects designing structures.
Anyone needing to determine unknown angles based on known side lengths in a right triangle.
function calculateAngles() {
var sideA = parseFloat(document.getElementById("sideA").value);
var sideB = parseFloat(document.getElementById("sideB").value);
var sideC = parseFloat(document.getElementById("sideC").value);
var knownValueType = document.getElementById("knownValue").value;
var angleUnit = document.getElementById("knownAngleUnit").value;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = ""; // Clear previous results
var angleA_rad, angleB_rad;
var angleA_deg, angleB_deg;
var error = false;
var errorMessage = "";
// — Input Validation —
var inputs = [sideA, sideB, sideC];
var validInputsCount = 0;
for (var i = 0; i 0) {
validInputsCount++;
}
}
if (validInputsCount 0) {
// Allow for small floating point inaccuracies
if (Math.abs(sideA * sideA + sideB * sideB – sideC * sideC) > 0.01) {
errorMessage = "The provided side lengths do not form a valid right triangle (Pythagorean theorem violated).";
error = true;
}
}
}
if (error) {
resultDiv.innerHTML = "" + errorMessage + "";
return;
}
// — Calculation Logic —
// Prioritize using two legs if available and valid
if (!isNaN(sideA) && sideA > 0 && !isNaN(sideB) && sideB > 0) {
angleA_rad = Math.atan(sideA / sideB);
angleB_rad = Math.atan(sideB / sideA);
// If hypotenuse is also provided and valid, use it for consistency check/fallback
if (!isNaN(sideC) && sideC > 0) {
// Double check if calculated hypotenuse matches provided one
var calculatedHypotenuse = Math.sqrt(sideA * sideA + sideB * sideB);
if (Math.abs(calculatedHypotenuse – sideC) > 0.01) {
// This case should be caught by initial validation, but as a safeguard
errorMessage = "Inconsistent side lengths provided. Please recheck values.";
error = true;
}
}
} else if (!isNaN(sideA) && sideA > 0 && !isNaN(sideC) && sideC > 0) {
// Side A and Hypotenuse known
if (sideA >= sideC) {
errorMessage = "Side A (leg) cannot be greater than or equal to the Hypotenuse.";
error = true;
} else {
angleA_rad = Math.asin(sideA / sideC);
// Calculate side B using Pythagorean theorem to find angle B
var calculatedSideB = Math.sqrt(sideC * sideC – sideA * sideA);
if (isNaN(calculatedSideB) || calculatedSideB 0 && !isNaN(sideC) && sideC > 0) {
// Side B and Hypotenuse known
if (sideB >= sideC) {
errorMessage = "Side B (leg) cannot be greater than or equal to the Hypotenuse.";
error = true;
} else {
angleB_rad = Math.asin(sideB / sideC);
// Calculate side A using Pythagorean theorem to find angle A
var calculatedSideA = Math.sqrt(sideC * sideC – sideB * sideB);
if (isNaN(calculatedSideA) || calculatedSideA 0.01) {
// Recalculate one angle to ensure sum is exactly 180
angleB_deg = 180 – 90 – angleA_deg;
}
resultDiv.innerHTML = "Angle A: " + angleA_deg.toFixed(2) + "°" +
"Angle B: " + angleB_deg.toFixed(2) + "°" +
"Angle C (Right Angle): 90°";
} else { // Radians
var angleC_rad = Math.PI / 2;
var calculatedSum = angleA_rad + angleB_rad + angleC_rad;
if (Math.abs(calculatedSum – Math.PI) > 0.001) {
// Recalculate one angle to ensure sum is exactly PI
angleB_rad = Math.PI – (Math.PI / 2) – angleA_rad;
}
resultDiv.innerHTML = "Angle A: " + angleA_rad.toFixed(4) + " rad" +
"Angle B: " + angleB_rad.toFixed(4) + " rad" +
"Angle C (Right Angle): " + (Math.PI / 2).toFixed(4) + " rad";
}
}