Enter two known values to solve for the remaining sides and angles.
Understanding the Right Triangle Calculator
A right triangle is a fundamental geometric shape characterized by one angle measuring exactly 90 degrees (a right angle). The sides opposite to the acute angles are called 'legs' (or sometimes 'catheti'), and the side opposite the right angle is called the 'hypotenuse'. The hypotenuse is always the longest side of the triangle.
Key Concepts and Formulas:
Pythagorean Theorem: This is the cornerstone for calculating sides. It states that the square of the hypotenuse (c) is equal to the sum of the squares of the other two sides (a and b): a² + b² = c². From this, we can derive:
c = √(a² + b²) (to find the hypotenuse)
a = √(c² - b²) (to find side a)
b = √(c² - a²) (to find side b)
Trigonometric Functions (SOH CAH TOA): These relate the angles of a right triangle to the ratios of its sides.
Sine (sin):sin(angle) = Opposite / Hypotenuse
Cosine (cos):cos(angle) = Adjacent / Hypotenuse
Tangent (tan):tan(angle) = Opposite / Adjacent
These can be rearranged to find sides or angles:
Opposite = Hypotenuse * sin(angle)
Adjacent = Hypotenuse * cos(angle)
Hypotenuse = Opposite / sin(angle)
Hypotenuse = Adjacent / cos(angle)
Opposite = Adjacent * tan(angle)
Adjacent = Opposite / tan(angle)
angle = arcsin(Opposite / Hypotenuse)
angle = arccos(Adjacent / Hypotenuse)
angle = arctan(Opposite / Adjacent)
Sum of Angles: The sum of all angles in any triangle is 180 degrees. In a right triangle, since one angle is 90 degrees, the sum of the two acute angles is always 90 degrees: Angle A + Angle B = 90°.
How to Use the Calculator:
This calculator requires you to input at least two known values from a right triangle. You can input:
Two sides (e.g., Side A and Side B)
One side and one acute angle (e.g., Side A and Angle B)
Hypotenuse and one side (e.g., Hypotenuse and Side A)
Hypotenuse and one acute angle (e.g., Hypotenuse and Angle A)
Leave the fields blank for the values you want the calculator to solve for. The calculator will then apply the appropriate Pythagorean theorem or trigonometric formulas to find the missing information.
Use Cases:
Right triangles are fundamental in many fields:
Construction & Engineering: Calculating roof pitches, diagonal braces, distances, and ensuring square corners.
Navigation: Determining distances and bearings using trigonometry.
Physics: Analyzing vectors, forces, and motion.
Surveying: Measuring distances and heights indirectly.
Computer Graphics & Game Development: Calculating positions, rotations, and distances in 2D and 3D space.
Everyday Life: Estimating the height of objects or the length of materials needed for diagonal applications.
function calculateRightTriangle() {
var sideA = parseFloat(document.getElementById("sideA").value);
var sideB = parseFloat(document.getElementById("sideB").value);
var hypotenuse = parseFloat(document.getElementById("hypotenuse").value);
var angleA = parseFloat(document.getElementById("angleA").value);
var angleB = parseFloat(document.getElementById("angleB").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "; // Clear previous results
var knownValues = 0;
if (!isNaN(sideA)) knownValues++;
if (!isNaN(sideB)) knownValues++;
if (!isNaN(hypotenuse)) knownValues++;
if (!isNaN(angleA)) knownValues++;
if (!isNaN(angleB)) knownValues++;
if (knownValues < 2) {
resultDiv.innerHTML = 'Please enter at least two known values.';
return;
}
// — Calculations —
// Calculate missing side A
if (isNaN(sideA)) {
if (!isNaN(sideB) && !isNaN(hypotenuse)) {
if (hypotenuse <= sideB) {
resultDiv.innerHTML = 'Error: Hypotenuse must be greater than Side B.';
return;
}
sideA = Math.sqrt(Math.pow(hypotenuse, 2) – Math.pow(sideB, 2));
document.getElementById("sideA").value = sideA.toFixed(4);
} else if (!isNaN(sideB) && !isNaN(angleA)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
sideA = sideB / Math.tan(angleA);
document.getElementById("sideA").value = sideA.toFixed(4);
} else if (!isNaN(sideB) && !isNaN(angleB)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
sideA = sideB * Math.tan(angleB);
document.getElementById("sideA").value = sideA.toFixed(4);
} else if (!isNaN(hypotenuse) && !isNaN(angleA)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
sideA = hypotenuse * Math.cos(angleA);
document.getElementById("sideA").value = sideA.toFixed(4);
} else if (!isNaN(hypotenuse) && !isNaN(angleB)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
sideA = hypotenuse * Math.sin(angleB);
document.getElementById("sideA").value = sideA.toFixed(4);
}
}
// Calculate missing side B
if (isNaN(sideB)) {
if (!isNaN(sideA) && !isNaN(hypotenuse)) {
if (hypotenuse <= sideA) {
resultDiv.innerHTML = 'Error: Hypotenuse must be greater than Side A.';
return;
}
sideB = Math.sqrt(Math.pow(hypotenuse, 2) – Math.pow(sideA, 2));
document.getElementById("sideB").value = sideB.toFixed(4);
} else if (!isNaN(sideA) && !isNaN(angleA)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
sideB = sideA / Math.tan(angleA); // This calculates the adjacent side if angleA is opposite sideB
document.getElementById("sideB").value = sideB.toFixed(4);
} else if (!isNaN(sideA) && !isNaN(angleB)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
sideB = sideA * Math.tan(angleB); // This calculates the adjacent side if angleB is opposite sideA
document.getElementById("sideB").value = sideB.toFixed(4);
} else if (!isNaN(hypotenuse) && !isNaN(angleA)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
sideB = hypotenuse * Math.sin(angleA);
document.getElementById("sideB").value = sideB.toFixed(4);
} else if (!isNaN(hypotenuse) && !isNaN(angleB)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
sideB = hypotenuse * Math.cos(angleB);
document.getElementById("sideB").value = sideB.toFixed(4);
}
}
// Calculate missing hypotenuse
if (isNaN(hypotenuse)) {
if (!isNaN(sideA) && !isNaN(sideB)) {
hypotenuse = Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2));
document.getElementById("hypotenuse").value = hypotenuse.toFixed(4);
} else if (!isNaN(sideA) && !isNaN(angleA)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
hypotenuse = sideA / Math.cos(angleA);
document.getElementById("hypotenuse").value = hypotenuse.toFixed(4);
} else if (!isNaN(sideA) && !isNaN(angleB)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
hypotenuse = sideA / Math.sin(angleB);
document.getElementById("hypotenuse").value = hypotenuse.toFixed(4);
} else if (!isNaN(sideB) && !isNaN(angleA)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
hypotenuse = sideB / Math.sin(angleA);
document.getElementById("hypotenuse").value = hypotenuse.toFixed(4);
} else if (!isNaN(sideB) && !isNaN(angleB)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
hypotenuse = sideB / Math.cos(angleB);
document.getElementById("hypotenuse").value = hypotenuse.toFixed(4);
}
}
// Re-calculate sides if hypotenuse was just calculated
if (!isNaN(sideA) && !isNaN(sideB) && isNaN(hypotenuse)) {
hypotenuse = Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2));
document.getElementById("hypotenuse").value = hypotenuse.toFixed(4);
}
if (!isNaN(sideA) && !isNaN(hypotenuse) && isNaN(sideB)) {
if (hypotenuse <= sideA) {
resultDiv.innerHTML = 'Error: Hypotenuse must be greater than Side A.';
return;
}
sideB = Math.sqrt(Math.pow(hypotenuse, 2) – Math.pow(sideA, 2));
document.getElementById("sideB").value = sideB.toFixed(4);
}
if (!isNaN(sideB) && !isNaN(hypotenuse) && isNaN(sideA)) {
if (hypotenuse 0 && sideB > 0 && hypotenuse > 0) {
if (isNaN(angleA)) {
calculatedAngleA = Math.atan(sideA / sideB) * (180 / Math.PI);
document.getElementById("angleA").value = calculatedAngleA.toFixed(4);
}
if (isNaN(angleB)) {
calculatedAngleB = Math.atan(sideB / sideA) * (180 / Math.PI);
document.getElementById("angleB").value = calculatedAngleB.toFixed(4);
}
} else if (hypotenuse > 0 && !isNaN(angleA) && isNaN(angleB)) {
angleA = angleA * (Math.PI / 180); // Convert to radians
calculatedAngleB = 90 – (angleA * (180 / Math.PI));
document.getElementById("angleB").value = calculatedAngleB.toFixed(4);
} else if (hypotenuse > 0 && !isNaN(angleB) && isNaN(angleA)) {
angleB = angleB * (Math.PI / 180); // Convert to radians
calculatedAngleA = 90 – (angleB * (180 / Math.PI));
document.getElementById("angleA").value = calculatedAngleA.toFixed(4);
}
// Final check and display
sideA = parseFloat(document.getElementById("sideA").value);
sideB = parseFloat(document.getElementById("sideB").value);
hypotenuse = parseFloat(document.getElementById("hypotenuse").value);
angleA = parseFloat(document.getElementById("angleA").value);
angleB = parseFloat(document.getElementById("angleB").value);
var results = [];
if (!isNaN(sideA)) results.push("Side A: " + sideA.toFixed(4) + "");
if (!isNaN(sideB)) results.push("Side B: " + sideB.toFixed(4) + "");
if (!isNaN(hypotenuse)) results.push("Hypotenuse: " + hypotenuse.toFixed(4) + "");
if (!isNaN(angleA)) results.push("Angle A: " + angleA.toFixed(4) + "°");
if (!isNaN(angleB)) results.push("Angle B: " + angleB.toFixed(4) + "°");
if (results.length > 0) {
resultDiv.innerHTML = results.join(");
} else {
resultDiv.innerHTML = 'Calculation error. Please check your inputs.';
}
// Validate angles sum to 90 (or close due to floating point) if both are calculated
if (!isNaN(angleA) && !isNaN(angleB)) {
if (Math.abs(angleA + angleB – 90) > 0.01) {
resultDiv.innerHTML += 'Warning: Acute angles do not sum to 90°.';
}
}
// Validate Pythagorean theorem (or close due to floating point) if all sides are calculated
if (!isNaN(sideA) && !isNaN(sideB) && !isNaN(hypotenuse)) {
if (Math.abs(Math.pow(sideA, 2) + Math.pow(sideB, 2) – Math.pow(hypotenuse, 2)) > 0.01) {
resultDiv.innerHTML += 'Warning: Sides do not satisfy Pythagorean theorem.';
}
}
}