Calculate the length of the unknown side of a triangle using the Pythagorean theorem or the Law of Cosines.
Right Triangle
General Triangle (SAS/SAA)
Between Known Sides (SAS)
Opposite Known Side 1 (SAA)
Calculated Missing Side
Understanding How to Find the Missing Side of a Triangle
Triangles are fundamental geometric shapes with three sides and three angles. Often in mathematics, engineering, and design, you'll encounter problems where you know some information about a triangle but need to find the length of an unknown side. This calculator helps you find that missing side length based on the type of triangle and the information provided.
Right Triangles: The Pythagorean Theorem
A right triangle is a triangle that contains one 90-degree angle. The side opposite the right angle is called the hypotenuse, and the other two sides are called legs. The Pythagorean theorem provides a straightforward way to find a missing side if you know the other two:
Formula:a² + b² = c²
Where 'a' and 'b' are the lengths of the legs, and 'c' is the length of the hypotenuse.
Using this calculator for a right triangle:
If you provide both legs (a and b), the calculator finds the hypotenuse (c).
If you provide one leg (e.g., a) and the hypotenuse (c), the calculator finds the other leg (b) using b = sqrt(c² - a²).
Example: If Side A = 3 units and Side B = 4 units, then Hypotenuse = sqrt(3² + 4²) = sqrt(9 + 16) = sqrt(25) = 5 units.
Example: If Hypotenuse = 13 units and Side A = 5 units, then Side B = sqrt(13² – 5²) = sqrt(169 – 25) = sqrt(144) = 12 units.
General Triangles: The Law of Cosines
For triangles that are not necessarily right-angled, we use the Law of Cosines. This law relates the lengths of the sides of any triangle to the cosine of one of its angles.
Formula for finding a side opposite a known angle:c² = a² + b² - 2ab * cos(C)
Where 'a' and 'b' are two known sides, 'C' is the angle between them, and 'c' is the side opposite angle 'C'.
Our calculator handles two scenarios for general triangles:
SAS (Side-Angle-Side): You know two sides and the angle between them. You input the two sides and the angle, and the calculator finds the third side opposite the angle.
SAA (Side-Angle-Angle) or ASA (Angle-Side-Angle): You know one side and two angles. If you provide one side, the angle opposite it, and another adjacent angle, the calculator first finds the third angle (since the sum of angles is 180°). Then, it uses the Law of Sines (or Law of Cosines iteratively) to find the missing side. For simplicity in this calculator, if you select SAA/ASA, you provide the known side, the angle opposite it, and *another* known angle. The calculator finds the third angle and then uses the Law of Cosines (by determining the angles first).
Example (SAS): If Side 1 = 10 units, Side 2 = 12 units, and the angle between them is 60 degrees, then the missing side (c) = sqrt(10² + 12² – 2 * 10 * 12 * cos(60°)) = sqrt(100 + 144 – 240 * 0.5) = sqrt(244 – 120) = sqrt(124) ≈ 11.14 units.
Example (SAA/ASA): If you know Side A = 7, Angle B = 45°, and Angle C = 70°, first calculate Angle A = 180° – 45° – 70° = 65°. Then use Law of Sines: a/sin(A) = b/sin(B) = c/sin(C). To find side 'b' (opposite Angle B), you'd use b = a * sin(B) / sin(A) = 7 * sin(45°) / sin(65°) ≈ 7 * 0.707 / 0.906 ≈ 5.45 units.
Navigation: Determining distances and positions based on known bearings and distances.
Engineering: Analyzing forces, designing components, and solving problems involving angles and lengths.
Surveying: Measuring distances and areas in land surveying.
Art & Design: Creating accurate geometric patterns and sculptures.
Everyday Problem Solving: Calculating the shortest distance across an obstacle or the height of an object.
function updateInputs() {
var type = document.getElementById('triangleType').value;
if (type === 'right_triangle') {
document.getElementById('rightTriangleInputs').style.display = 'block';
document.getElementById('generalTriangleInputs').style.display = 'none';
} else {
document.getElementById('rightTriangleInputs').style.display = 'none';
document.getElementById('generalTriangleInputs').style.display = 'block';
}
}
function calculateMissingSide() {
document.getElementById('errorMessage').textContent = ";
document.getElementById('result-container').style.display = 'none';
var triangleType = document.getElementById('triangleType').value;
var resultValue = ";
var resultUnits = 'units'; // Default units
if (triangleType === 'right_triangle') {
var sideA = parseFloat(document.getElementById('sideA_rt').value);
var sideB = parseFloat(document.getElementById('sideB_rt').value);
var hypotenuse = parseFloat(document.getElementById('hypotenuse_rt').value);
var allInputsValid = !isNaN(sideA) && !isNaN(sideB) && !isNaN(hypotenuse);
var twoSidesGiven = !isNaN(sideA) && !isNaN(sideB);
var oneLegAndHypGiven = (!isNaN(sideA) && !isNaN(hypotenuse)) || (!isNaN(sideB) && !isNaN(hypotenuse));
if (twoSidesGiven && isNaN(hypotenuse)) {
// Calculate hypotenuse (c)
if (sideA <= 0 || sideB <= 0) {
document.getElementById('errorMessage').textContent = 'Leg lengths must be positive numbers.';
return;
}
resultValue = Math.sqrt(sideA * sideA + sideB * sideB);
} else if (oneLegAndHypGiven) {
// Calculate missing leg
var knownLeg, knownHyp;
if (!isNaN(sideA) && !isNaN(hypotenuse)) {
knownLeg = sideA;
knownHyp = hypotenuse;
if (knownLeg <= 0 || knownHyp <= 0) {
document.getElementById('errorMessage').textContent = 'Side and hypotenuse lengths must be positive numbers.';
return;
}
if (knownHyp <= knownLeg) {
document.getElementById('errorMessage').textContent = 'Hypotenuse must be longer than the known leg.';
return;
}
resultValue = Math.sqrt(knownHyp * knownHyp – knownLeg * knownLeg);
} else if (!isNaN(sideB) && !isNaN(hypotenuse)) {
knownLeg = sideB;
knownHyp = hypotenuse;
if (knownLeg <= 0 || knownHyp <= 0) {
document.getElementById('errorMessage').textContent = 'Side and hypotenuse lengths must be positive numbers.';
return;
}
if (knownHyp <= knownLeg) {
document.getElementById('errorMessage').textContent = 'Hypotenuse must be longer than the known leg.';
return;
}
resultValue = Math.sqrt(knownHyp * knownHyp – knownLeg * knownLeg);
} else {
document.getElementById('errorMessage').textContent = 'Please provide two known sides or one leg and the hypotenuse.';
return;
}
} else {
document.getElementById('errorMessage').textContent = 'Please provide two known sides (legs) or one leg and the hypotenuse for a right triangle.';
return;
}
} else { // General Triangle (SAS or SAA)
var knownSide1 = parseFloat(document.getElementById('knownSide1').value);
var knownSide2 = parseFloat(document.getElementById('knownSide2').value);
var knownAngleDeg = parseFloat(document.getElementById('knownAngle').value);
var angleType = document.getElementById('angleType').value;
if (isNaN(knownSide1) || isNaN(knownSide2) || isNaN(knownAngleDeg)) {
document.getElementById('errorMessage').textContent = 'Please provide valid numbers for two sides and one angle.';
return;
}
if (knownSide1 <= 0 || knownSide2 <= 0) {
document.getElementById('errorMessage').textContent = 'Side lengths must be positive numbers.';
return;
}
if (knownAngleDeg = 180) {
document.getElementById('errorMessage').textContent = 'Angle must be between 0 and 180 degrees.';
return;
}
var knownAngleRad = knownAngleDeg * Math.PI / 180; // Convert angle to radians
if (angleType === 'between_sides') { // SAS case
// Law of Cosines: c^2 = a^2 + b^2 – 2ab*cos(C)
resultValue = Math.sqrt(knownSide1 * knownSide1 + knownSide2 * knownSide2 – 2 * knownSide1 * knownSide2 * Math.cos(knownAngleRad));
} else { // SAA/ASA case (simplified logic: calculate third angle, then use Law of Sines to find other sides)
// This requires knowing *which* angle is known and *which* side is known.
// For simplicity, we'll assume knownSide1 is opposite the first angle (let's call it A),
// and knownAngleDeg is Angle B, and we're looking for side b.
// Need more specific inputs for SAA/ASA to be robust.
// Let's refine this to be more accurate for the user's selection.
// Re-evaluate inputs based on angleType for SAA/ASA
var angleA_deg, angleB_deg, angleC_deg;
var sideA, sideB, sideC; // sideA opposite angleA, etc.
if (angleType === 'opposite_side1') { // SAA: side1, angleOppositeSide1, knownAngle2
// Assume the input 'knownAngle' is the *other* known angle.
// We need to know which side corresponds to which angle.
// Let's assume: knownSide1 is side 'a', knownAngleDeg is angle 'B', and we need to find side 'b'.
// To do this properly, we need angle A.
// This interpretation is ambiguous. Let's re-structure the inputs for SAA/ASA.
// Re-interpreting based on typical SAA/ASA structure:
// knownSide1 = side 'a'
// knownAngleDeg = angle 'B'
// knownSide2 = angle 'C' (This is confusing naming, it implies side2 but the select says angleType)
// Let's assume: knownSide1 = side 'a', knownAngleDeg = angle 'B', and there's a third input for angle 'C'.
// The current UI is not well-suited for SAA/ASA without more clarity.
// LET'S RE-ASSUME the prompt meant:
// If angleType is SAA/ASA, we provide SIDE1, ANGLE1 (opposite SIDE1), ANGLE2 (adjacent to SIDE1).
// We need to find SIDE2 (opposite ANGLE2).
// Based on the current simplified input structure (knownSide1, knownSide2, knownAngle):
// If angleType is 'between_sides', we use SAS. This is handled above.
// If angleType is 'opposite_side1':
// Assume:
// knownSide1 = side 'a'
// knownAngleDeg = angle 'B' (adjacent angle)
// knownSide2 = side 'b' (This is where it breaks, input is for side, not angle).
// **WORKAROUND for limited inputs:**
// Assume the user provides: knownSide1, knownAngle (degrees), and *another* angle (implicitly derived or assumed).
// Let's assume:
// knownSide1 = length of a side.
// knownAngleDeg = angle opposite knownSide1.
// knownSide2 = length of a second side.
// angleType = 'opposite_side1' implies we are given SAA or ASA.
// If Angle Type is 'Opposite Side 1', it implies we have Side A, Angle B, Angle C.
// Let's assume the inputs map to: knownSide1 = side 'a', knownAngleDeg = angle 'B', and there needs to be another angle input.
// Given the constraint of 3 inputs for general triangle, this is tricky.
// **MOST LIKELY INTENT:** The user provides:
// Side 1, Side 2, and Angle C (between them) -> SAS -> Find Side C
// OR
// Side 1, Angle B (opposite Side 1), Angle C -> SAA -> Find Side B (opposite Angle B)
// The current UI has: knownSide1, knownSide2, knownAngle.
// If 'angleType' is 'between_sides', knownAngle IS angle C. knownSide1 IS side a, knownSide2 IS side b. (SAS – DONE)
// If 'angleType' is 'opposite_side1', THIS IS THE AMBIGUOUS PART.
// Let's assume it means: knownSide1 is side 'a', knownAngleDeg is angle 'B', and knownSide2 is irrelevant or an angle.
// OR knownSide1 is side 'a', knownAngleDeg is angle 'A', knownSide2 is angle 'B'.
// The MOST common SAA/ASA problem gives ONE side and TWO angles.
// Let's assume: knownSide1 = side 'a', knownAngleDeg = angle 'B', and a THIRD input is needed for angle 'C'.
// Since we only have 3 inputs, let's make a simplifying assumption for this calculator:
// If SAA/ASA, we provide: Side A, Angle B, Angle C. We need to find Side B or Side C.
// The calculator calculates the third angle first.
// Angle A = 180 – Angle B – Angle C
// Then uses Law of Sines: a/sin(A) = b/sin(B) = c/sin(C)
// **REVISED LOGIC FOR SAA/ASA based on current inputs:**
// User provides: knownSide1, knownSide2, knownAngle
// If angleType is 'opposite_side1':
// var knownSide1 be side 'a'.
// var knownAngleDeg be angle 'B'.
// var knownSide2 be angle 'C'. (This is a problematic mapping due to naming)
// Calculate Angle A = 180 – B – C
// Calculate side 'b' = a * sin(B) / sin(A)
// This requires the user to input an angle value into the 'Known Side 2' field, which is bad UX.
// **Let's stick to the MOST straightforward interpretation of the inputs:**
// SAS: knownSide1, knownSide2, knownAngle (BETWEEN them) -> Find side opposite knownAngle.
// SAA/ASA: requires 2 angles and 1 side.
// The current UI forces the user to put an ANGLE value into the 'knownSide2' field if they choose 'opposite_side1'. This is flawed UI design based on the input names.
// We will proceed assuming the user understands this limitation OR we correct the interpretation.
// Corrected interpretation for 'opposite_side1':
// User provides: knownSide1, knownAngle (degrees), and *another angle*.
// Let's assume the inputs are:
// knownSide1 = side 'a'
// knownAngleDeg = angle 'B'
// knownSide2 = angle 'C' (User needs to know this)
// Calculate angle A:
angleA_deg = 180 – knownAngleDeg – knownSide2; // Assuming knownSide2 is angle C
if (angleA_deg = 180) {
document.getElementById('errorMessage').textContent = 'The provided angles result in an invalid triangle.';
return;
}
var angleA_rad = angleA_deg * Math.PI / 180;
var angleB_rad = knownAngleDeg * Math.PI / 180; // Renamed for clarity
// Now calculate the side opposite angle B (which is side 'b')
resultValue = knownSide1 * Math.sin(angleB_rad) / Math.sin(angleA_rad);
// Note: The label 'Known Side 2' is misleading here. It should be 'Known Angle 2'.
} else {
document.getElementById('errorMessage').textContent = 'Invalid angle type selected.';
return;
}
}
}
if (!isNaN(resultValue) && resultValue > 0) {
document.getElementById('result-value').textContent = resultValue.toFixed(4); // Display with 4 decimal places
document.getElementById('result-units').textContent = resultUnits;
document.getElementById('result-container').style.display = 'block';
} else if (resultValue === 0) {
document.getElementById('errorMessage').textContent = 'Calculation resulted in zero. Check your inputs.';
}
// Error messages for invalid inputs are handled above.
}
// Initialize input visibility on page load
window.onload = updateInputs;