Calculate the length of the unknown side of a triangle using the Pythagorean theorem (for right triangles) or the Law of Cosines (for any triangle).
Your missing side length will appear here.
Understanding the Missing Side of a Triangle Calculator
Triangles are fundamental geometric shapes with three sides and three angles. In many mathematical, engineering, and real-world applications, you might know some dimensions of a triangle but need to find others. This calculator helps you find the length of an unknown side when enough information is provided.
When Can You Find a Missing Side?
To uniquely determine a triangle, you generally need at least three pieces of information, with at least one being a side length. This calculator supports finding a missing side under the following common scenarios:
Two sides and the included angle (SAS): If you know the lengths of two sides and the angle between them, you can find the third side using the Law of Cosines.
Three sides (SSS): If you know all three side lengths, you can verify if it forms a valid triangle and calculate its angles. While this calculator focuses on finding sides, the Law of Cosines (used below) is also the basis for angle calculations.
Two angles and an adjacent side (ASA or AAS): If you know two angles and one side, you can find the other two sides using the Law of Sines. (Note: This calculator currently prioritizes SAS and Pythagorean theorem).
Right Triangles (Pythagorean Theorem): If you know it's a right triangle and you have two sides (the two legs, or one leg and the hypotenuse), you can easily find the third side.
The Mathematics Behind the Calculation
1. Pythagorean Theorem (For Right Triangles Only)
If you know that the triangle is a right triangle (one angle is 90 degrees) and you have the lengths of two sides, you can find the third using the Pythagorean theorem:
a² + b² = c²
Where:
'a' and 'b' are the lengths of the two legs (the sides forming the right angle).
'c' is the length of the hypotenuse (the side opposite the right angle, always the longest side).
To find a missing leg (e.g., 'a'): a = sqrt(c² - b²)
To find the hypotenuse ('c'): c = sqrt(a² + b²)
Note: This calculator will primarily use the Pythagorean theorem if sideC is known and angleC is 90 degrees, or if sides A and B are known and a right angle is implied.
2. Law of Cosines (For Any Triangle)
The Law of Cosines is a generalization of the Pythagorean theorem and works for any triangle. It relates the lengths of the sides of a triangle to the cosine of one of its angles.
c² = a² + b² – 2ab * cos(γ)
Where:
'a', 'b', and 'c' are the lengths of the sides.
'γ' (gamma) is the angle opposite side 'c'.
This formula is used when you know two sides and the included angle (SAS). To find the missing side 'c':
c = sqrt(a² + b² – 2ab * cos(γ))
Similarly, you can find other sides if you know the other two sides and their respective opposite angles:
Important: Ensure your calculator's angle inputs are in degrees, but the `Math.cos()` function in JavaScript expects radians. The conversion is necessary.
How to Use This Calculator
Identify the known values: side lengths (A, B, C) and angles (α, β, γ). Remember that angles are typically opposite their corresponding sides (α opposite A, β opposite B, γ opposite C).
Input the known values into the corresponding fields. Leave the field for the side you want to calculate blank.
If you are dealing with a right triangle where Side C is the hypotenuse and Angle C is 90 degrees, the Pythagorean theorem will be prioritized for calculating Side C if Sides A and B are known.
Click "Calculate Missing Side". The result will be displayed below.
Disclaimer: This calculator is for educational and informational purposes. Ensure your inputs are accurate and understand the trigonometric principles involved for correct application.
function calculateMissingSide() {
var sideA = parseFloat(document.getElementById("sideA").value);
var sideB = parseFloat(document.getElementById("sideB").value);
var sideC = parseFloat(document.getElementById("sideC").value);
var angleA_deg = parseFloat(document.getElementById("angleA").value);
var angleB_deg = parseFloat(document.getElementById("angleB").value);
var angleC_deg = parseFloat(document.getElementById("angleC").value);
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "Your missing side length will appear here."; // Reset message
var missingSide = null;
var found = false;
// Helper function to convert degrees to radians
function degreesToRadians(degrees) {
return degrees * Math.PI / 180;
}
// — Logic to find the missing side —
// Case 1: Find Side C (SAS – Law of Cosines)
if (isNaN(sideC) && !isNaN(sideA) && !isNaN(sideB) && !isNaN(angleC_deg)) {
if (angleC_deg > 0 && angleC_deg 0 && angleB_deg 0 && angleA_deg sideB) { // Hypotenuse check
missingSide = Math.sqrt(Math.pow(sideC, 2) – Math.pow(sideB, 2));
found = true;
} else {
resultDiv.innerHTML = "Error: Hypotenuse (Side A) cannot be shorter than or equal to a leg (Side B).";
return;
}
}
// Case 6: Find Side B (Right Triangle – Pythagorean Theorem)
// Assume angleB is 90 degrees (less common, but possible if A and C are legs)
if (isNaN(sideB) && !isNaN(sideA) && !isNaN(sideC) && angleB_deg === 90) {
if (sideC > sideA) { // Hypotenuse check
missingSide = Math.sqrt(Math.pow(sideC, 2) – Math.pow(sideA, 2));
found = true;
} else {
resultDiv.innerHTML = "Error: Hypotenuse (Side B) cannot be shorter than or equal to a leg (Side A).";
return;
}
}
// Case 7: Find Side C (Right Triangle – Pythagorean Theorem if angleC is NOT given but angleA or B is 90)
// If sideA and sideB are given, and we know it's a right triangle (angle A or B is 90)
if (isNaN(sideC) && !isNaN(sideA) && !isNaN(sideB)) {
if (angleA_deg === 90 || angleB_deg === 90) {
// If angleA is 90, side A is hypotenuse. If angle B is 90, side B is hypotenuse.
// This case implies sideC is a leg, which contradicts standard notation.
// Let's assume standard notation: if angle C = 90, side C is hypotenuse.
// If only sideA and sideB are provided, and no angle, we assume a right triangle
// where sideA and sideB are legs and we calculate hypotenuse C.
if (!isNaN(angleC_deg) && angleC_deg !== 90){
// If angle C is given and not 90, use Law of Cosines (handled above)
} else {
missingSide = Math.sqrt(Math.pow(sideA, 2) + Math.pow(sideB, 2));
found = true;
}
}
}
// — Display Result —
if (found && missingSide !== null && !isNaN(missingSide)) {
// Check triangle inequality if possible
var sides = [sideA, sideB, sideC, missingSide].filter(s => !isNaN(s));
if (sides.length === 3) {
sides.sort(function(a, b){return a-b;});
if (sides[0] + sides[1] <= sides[2]) {
resultDiv.innerHTML = "Error: The provided side lengths do not form a valid triangle.";
return;
}
}
resultDiv.innerHTML = "The missing side length is: " + missingSide.toFixed(4) + "";
} else {
var missingCount = (isNaN(sideA) ? 1 : 0) + (isNaN(sideB) ? 1 : 0) + (isNaN(sideC) ? 1 : 0);
var angleCount = (isNaN(angleA_deg) ? 1 : 0) + (isNaN(angleB_deg) ? 1 : 0) + (isNaN(angleC_deg) ? 1 : 0);
if (missingCount !== 1) {
resultDiv.innerHTML = "Error: Please provide exactly one unknown side and sufficient other information.";
} else if (missingCount === 1 && angleCount > 1 && (!isNaN(sideA) || !isNaN(sideB) || !isNaN(sideC))) {
// This case might indicate SSS, which is not for finding a side.
resultDiv.innerHTML = "Error: Too much information provided or insufficient information for side calculation (e.g., only angles given).";
}
else {
resultDiv.innerHTML = "Error: Please check your inputs. Ensure you have enough valid data (e.g., two sides and an angle, or two sides of a right triangle).";
}
}
}