This calculator helps you find unknown sides of a triangle using the Pythagorean theorem (for right-angled triangles) or the Law of Cosines (for general triangles).
Inputs
(Provide at least two sides and one angle, or three sides if the angle is not needed/known.)
Enter values to see the results here.
Understanding Triangle Side Calculations
Triangles are fundamental geometric shapes with three sides and three angles. Calculating unknown sides often requires knowing some existing sides and angles, and applying specific trigonometric laws.
1. Pythagorean Theorem (Right-Angled Triangles)
For a right-angled triangle (where one angle is exactly 90 degrees), the relationship between the sides is defined by the Pythagorean theorem: a² + b² = c², where:
a and b are the lengths of the two shorter sides (legs) adjacent to the right angle.
c is the length of the longest side (hypotenuse), opposite the right angle.
If you know two sides of a right triangle, you can find the third:
To find the hypotenuse (c): c = sqrt(a² + b²)
To find a leg (a or b): a = sqrt(c² - b²) or b = sqrt(c² - a²)
This calculator will automatically apply this theorem if Angle C is input as 90 degrees and two sides are provided.
2. Law of Cosines (General Triangles)
For any triangle (not just right-angled), the Law of Cosines relates the lengths of the sides to the cosine of one of its angles. It's a powerful tool when you have certain combinations of knowns:
Known: Two sides and the included angle (SAS – Side-Angle-Side).
Known: Three sides (SSS – Side-Side-Side).
The formulas are:
To find side c (opposite angle C): c² = a² + b² - 2ab * cos(C)
To find side a (opposite angle A): a² = b² + c² - 2bc * cos(A)
To find side b (opposite angle B): b² = a² + c² - 2ac * cos(B)
To use the Law of Cosines for finding an unknown side when you know two sides and the *included* angle (like Side A, Side B, and Angle C in this calculator), the formula is:
Side C = sqrt( (Side A)² + (Side B)² - 2 * (Side A) * (Side B) * cos(Angle C in radians) )
Important Note: Trigonometric functions in JavaScript (like Math.cos) expect angles in radians, not degrees. The calculator converts your degree input to radians.
Use Cases
Calculating triangle sides is essential in various fields:
Art & Design: Creating geometric patterns and structures.
Physics: Solving problems involving vectors and forces.
function calculateTriangleSides() {
var sideA = parseFloat(document.getElementById("sideA").value);
var sideB = parseFloat(document.getElementById("sideB").value);
var angleC_deg = parseFloat(document.getElementById("angleC_deg").value);
var resultDiv = document.getElementById("result");
var resultHTML = "";
// Input validation
var inputsProvided = 0;
if (!isNaN(sideA) && sideA > 0) inputsProvided++;
if (!isNaN(sideB) && sideB > 0) inputsProvided++;
if (!isNaN(angleC_deg) && angleC_deg >= 0 && angleC_deg <= 180) inputsProvided++;
// We need at least two sides and one angle, or potentially just three sides (though this calculator is set up for SAS/Pythagorean)
// For simplicity, this calculator focuses on cases where Angle C is involved.
if (inputsProvided < 2 || isNaN(sideA) || isNaN(sideB) || isNaN(angleC_deg)) {
resultHTML = "Please enter at least two valid side lengths and one angle.";
} else {
var sideC = 0;
var calculationType = "";
// Check for Pythagorean Theorem case (Right Triangle)
if (Math.abs(angleC_deg – 90) 0) {
resultHTML = "Calculated using: " + calculationType + ""
+ "Side C: " + sideC.toFixed(4) + " units";
}
}
resultDiv.innerHTML = resultHTML;
}