Solve for Hypotenuse, Legs, or any side using Law of Cosines
1. Right Triangle (Pythagorean Theorem)
Enter any two sides to find the third. (a² + b² = c²)
2. General Triangle (SAS Method)
Find the third side using two sides and the angle between them.
Understanding How to Find the Missing Side of a Triangle
Calculating the length of a triangle's side depends on the information you have available. There are two primary methods used in geometry: the Pythagorean Theorem for right-angled triangles and the Law of Cosines for all other triangles.
1. Using the Pythagorean Theorem
If you are working with a right triangle (a triangle where one angle is exactly 90 degrees), you can use the famous formula:
a² + b² = c²
c is the hypotenuse (the longest side opposite the right angle).
a and b are the other two legs.
To find the hypotenuse, calculate the square root of (a² + b²). To find a leg, calculate the square root of (c² – other leg²).
2. Using the Law of Cosines
If the triangle is not a right triangle, or if you only know two sides and the angle between them (Side-Angle-Side or SAS), the Law of Cosines is the tool to use:
c² = a² + b² – 2ab cos(γ)
This formula allows you to find the third side (c) when you know sides a and b and the angle γ (gamma) located between them.
Practical Example: Building a Ramp
Imagine you are building a wooden ramp. You know the height of the step is 3 feet (Side A) and the distance along the ground is 4 feet (Side B). Since the ground and the step meet at a 90-degree angle, we can find the ramp surface length (Side C):
3² + 4² = c²
9 + 16 = 25
√25 = 5 feet
function calculatePythagorean() {
var a = parseFloat(document.getElementById('sideA').value);
var b = parseFloat(document.getElementById('sideB').value);
var c = parseFloat(document.getElementById('sideC').value);
var resDiv = document.getElementById('pythagResult');
resDiv.style.display = 'block';
resDiv.style.color = '#2c3e50';
if (!isNaN(a) && !isNaN(b) && isNaN(c)) {
// Find C
var result = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2));
resDiv.innerHTML = 'Hypotenuse (c) = ' + result.toFixed(4);
} else if (!isNaN(a) && !isNaN(c) && isNaN(b)) {
// Find B
if (c <= a) {
resDiv.innerHTML = 'Error: Hypotenuse must be longer than Side A';
resDiv.style.color = 'red';
} else {
var result = Math.sqrt(Math.pow(c, 2) – Math.pow(a, 2));
resDiv.innerHTML = 'Side (b) = ' + result.toFixed(4);
}
} else if (!isNaN(b) && !isNaN(c) && isNaN(a)) {
// Find A
if (c <= b) {
resDiv.innerHTML = 'Error: Hypotenuse must be longer than Side B';
resDiv.style.color = 'red';
} else {
var result = Math.sqrt(Math.pow(c, 2) – Math.pow(b, 2));
resDiv.innerHTML = 'Side (a) = ' + result.toFixed(4);
}
} else {
resDiv.innerHTML = 'Please enter exactly two values to find the third.';
resDiv.style.color = 'red';
}
}
function calculateSAS() {
var a = parseFloat(document.getElementById('sasA').value);
var b = parseFloat(document.getElementById('sasB').value);
var angleDeg = parseFloat(document.getElementById('sasAngle').value);
var resDiv = document.getElementById('sasResult');
resDiv.style.display = 'block';
resDiv.style.color = '#2c3e50';
if (isNaN(a) || isNaN(b) || isNaN(angleDeg)) {
resDiv.innerHTML = 'Please enter both sides and the angle.';
resDiv.style.color = 'red';
return;
}
if (angleDeg = 180) {
resDiv.innerHTML = 'Angle must be between 0 and 180 degrees.';
resDiv.style.color = 'red';
return;
}
// Convert degrees to radians
var angleRad = angleDeg * (Math.PI / 180);
// c^2 = a^2 + b^2 – 2ab * cos(angle)
var cSquared = Math.pow(a, 2) + Math.pow(b, 2) – (2 * a * b * Math.cos(angleRad));
var result = Math.sqrt(cSquared);
resDiv.innerHTML = 'Missing Side (c) = ' + result.toFixed(4);
}