Trigonometry Triangle Calculator

Trigonometry Triangle Calculator

Enter any three known values (sides or angles) of a triangle to calculate the remaining values. Angles should be in degrees.

.calculator-container { font-family: Arial, sans-serif; max-width: 600px; margin: 20px auto; padding: 20px; border: 1px solid #ccc; border-radius: 8px; background-color: #f9f9f9; } .input-group { margin-bottom: 15px; } .input-group label { display: block; margin-bottom: 5px; font-weight: bold; } .input-group input[type="number"] { width: calc(100% – 22px); padding: 10px; border: 1px solid #ddd; border-radius: 4px; box-sizing: border-box; } button { padding: 10px 15px; background-color: #007bff; color: white; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; margin-right: 10px; } button:hover { background-color: #0056b3; } .calculator-result { margin-top: 20px; padding: 15px; border: 1px solid #e0e0e0; border-radius: 4px; background-color: #e9e9e9; min-height: 50px; } .calculator-result p { margin: 0 0 5px 0; } .error { color: red; font-weight: bold; } .solution-set { margin-top: 10px; border-top: 1px dashed #ccc; padding-top: 10px; } function toRadians(degrees) { return degrees * (Math.PI / 180); } function toDegrees(radians) { return radians * (180 / Math.PI); } function isValidNumber(value) { return typeof value === 'number' && !isNaN(value) && isFinite(value) && value > 0; } function calculateTriangle() { var a = parseFloat(document.getElementById('sideA').value); var b = parseFloat(document.getElementById('sideB').value); var c = parseFloat(document.getElementById('sideC').value); var A = parseFloat(document.getElementById('angleA').value); var B = parseFloat(document.getElementById('angleB').value); var C = parseFloat(document.getElementById('angleC').value); var inputs = [ { val: a, id: 'a', type: 'side' }, { val: b, id: 'b', type: 'side' }, { val: c, id: 'c', type: 'side' }, { val: A, id: 'A', type: 'angle' }, { val: B, id: 'B', type: 'angle' }, { val: C, id: 'C', type: 'angle' } ]; var knowns = inputs.filter(function(input) { return isValidNumber(input.val); }); var resultDiv = document.getElementById('result'); resultDiv.innerHTML = "; if (knowns.length 3) { resultDiv.innerHTML = 'Please enter exactly three values (sides or angles). If you enter more, the calculator might not know which values to prioritize.'; return; } // Check for invalid angle values (must be < 180) for (var i = 0; i = 180) { resultDiv.innerHTML = 'Angles must be less than 180 degrees.'; return; } } var numSides = knowns.filter(function(k) { return k.type === 'side'; }).length; var numAngles = knowns.filter(function(k) { return k.type === 'angle'; }).length; var solutionSets = []; function addSolution(solA, solB, solC, sola, solb, solc, solutionNumber) { var solutionHtml = '
'; if (solutionNumber) { solutionHtml += '

Solution ' + solutionNumber + ':

'; } solutionHtml += 'Side a: ' + sola.toFixed(4) + "; solutionHtml += 'Side b: ' + solb.toFixed(4) + "; solutionHtml += 'Side c: ' + solc.toFixed(4) + "; solutionHtml += 'Angle A: ' + solA.toFixed(4) + '°'; solutionHtml += 'Angle B: ' + solB.toFixed(4) + '°'; solutionHtml += 'Angle C: ' + solC.toFixed(4) + '°'; solutionHtml += '
'; solutionSets.push(solutionHtml); } // Convert angles to radians for Math functions var A_rad = isValidNumber(A) ? toRadians(A) : NaN; var B_rad = isValidNumber(B) ? toRadians(B) : NaN; var C_rad = isValidNumber(C) ? toRadians(C) : NaN; // — Solving Logic — // Case: 3 Angles (AAA) – Infinite solutions, need a side if (numAngles === 3) { if (Math.abs(A + B + C – 180) > 0.001) { resultDiv.innerHTML = 'The sum of the three angles must be 180 degrees.'; return; } resultDiv.innerHTML = 'With only three angles, there are infinite similar triangles. Please provide at least one side length.'; return; } // SSS Case (3 sides, 0 angles) if (numSides === 3 && numAngles === 0) { if (!(a + b > c && a + c > b && b + c > a)) { resultDiv.innerHTML = 'The given side lengths do not form a valid triangle (triangle inequality not met).'; return; } try { A_rad = Math.acos((b * b + c * c – a * a) / (2 * b * c)); B_rad = Math.acos((a * a + c * c – b * b) / (2 * a * c)); C_rad = Math.acos((a * a + b * b – c * c) / (2 * a * b)); addSolution(toDegrees(A_rad), toDegrees(B_rad), toDegrees(C_rad), a, b, c); } catch (e) { resultDiv.innerHTML = 'Error calculating angles for SSS case. Check side lengths.'; } } // SAS Case (2 sides, 1 included angle) else if (numSides === 2 && numAngles === 1 && ((isValidNumber(a) && isValidNumber(b) && isValidNumber(C)) || (isValidNumber(b) && isValidNumber(c) && isValidNumber(A)) || (isValidNumber(c) && isValidNumber(a) && isValidNumber(B)))) { try { if (isValidNumber(a) && isValidNumber(b) && isValidNumber(C)) { // a, b, C c = Math.sqrt(a * a + b * b – 2 * a * b * Math.cos(C_rad)); B_rad = Math.asin((b * Math.sin(C_rad)) / c); A_rad = Math.PI – C_rad – B_rad; addSolution(toDegrees(A_rad), toDegrees(B_rad), C, a, b, c); } else if (isValidNumber(b) && isValidNumber(c) && isValidNumber(A)) { // b, c, A a = Math.sqrt(b * b + c * c – 2 * b * c * Math.cos(A_rad)); C_rad = Math.asin((c * Math.sin(A_rad)) / a); B_rad = Math.PI – A_rad – C_rad; addSolution(A, toDegrees(B_rad), toDegrees(C_rad), a, b, c); } else if (isValidNumber(a) && isValidNumber(c) && isValidNumber(B)) { // a, c, B b = Math.sqrt(a * a + c * c – 2 * a * c * Math.cos(B_rad)); C_rad = Math.asin((c * Math.sin(B_rad)) / b); A_rad = Math.PI – B_rad – C_rad; addSolution(toDegrees(A_rad), B, toDegrees(C_rad), a, b, c); } } catch (e) { resultDiv.innerHTML = 'Error calculating for SAS case. Check inputs.'; } } // ASA/AAS Case (1 side, 2 angles) else if (numSides === 1 && numAngles === 2) { // Find the third angle first if (!isValidNumber(A)) { A = 180 – B – C; A_rad = toRadians(A); } else if (!isValidNumber(B)) { B = 180 – A – C; B_rad = toRadians(B); } else if (!isValidNumber(C)) { C = 180 – A – B; C_rad = toRadians(C); } if (A <= 0 || B <= 0 || C = 180 || B >= 180 || C >= 180) { resultDiv.innerHTML = 'The sum of the two given angles and the calculated third angle must be 180 degrees, and all angles must be positive and less than 180.'; return; } // Now we have all 3 angles and 1 side, use Law of Sines try { if (isValidNumber(a)) { // Given a, and now A, B, C b = (a * Math.sin(B_rad)) / Math.sin(A_rad); c = (a * Math.sin(C_rad)) / Math.sin(A_rad); addSolution(A, B, C, a, b, c); } else if (isValidNumber(b)) { // Given b, and now A, B, C a = (b * Math.sin(A_rad)) / Math.sin(B_rad); c = (b * Math.sin(C_rad)) / Math.sin(B_rad); addSolution(A, B, C, a, b, c); } else if (isValidNumber(c)) { // Given c, and now A, B, C a = (c * Math.sin(A_rad)) / Math.sin(C_rad); b = (c * Math.sin(B_rad)) / Math.sin(C_rad); addSolution(A, B, C, a, b, c); } } catch (e) { resultDiv.innerHTML = 'Error calculating for ASA/AAS case. Check inputs.'; } } // SSA Case (2 sides, 1 non-included angle) – Ambiguous Case else if (numSides === 2 && numAngles === 1) { var knownSide1, knownSide2, knownAngleOppositeSide1; var originalA, originalB, originalC, original_a, original_b, original_c; // Identify the specific SSA configuration if (isValidNumber(a) && isValidNumber(b) && isValidNumber(A)) { // a, b, A knownSide1 = a; knownSide2 = b; knownAngleOppositeSide1 = A; original_a = a; original_b = b; originalA = A; } else if (isValidNumber(b) && isValidNumber(c) && isValidNumber(B)) { // b, c, B knownSide1 = b; knownSide2 = c; knownAngleOppositeSide1 = B; original_b = b; original_c = c; originalB = B; } else if (isValidNumber(c) && isValidNumber(a) && isValidNumber(C)) { // c, a, C knownSide1 = c; knownSide2 = a; knownAngleOppositeSide1 = C; original_c = c; original_a = a; originalC = C; } else { resultDiv.innerHTML = 'Invalid combination for SSA. The angle must be opposite one of the known sides.'; return; } var angle1_rad = toRadians(knownAngleOppositeSide1); var sin_unknownAngleOppositeSide2 = (knownSide2 * Math.sin(angle1_rad)) / knownSide1; if (sin_unknownAngleOppositeSide2 > 1 || sin_unknownAngleOppositeSide2 0 && angle3_deg_1 0 && angle3_deg_2 0.001) { // Ensure it's a distinct valid triangle var angle3_rad_2 = toRadians(angle3_deg_2); var side3_2 = (knownSide1 * Math.sin(angle3_rad_2)) / Math.sin(angle1_rad); var solA2, solB2, solC2, sola2, solb2, solc2; if (isValidNumber(a) && isValidNumber(b) && isValidNumber(A)) { // a, b, A solA2 = originalA; solB2 = angle2_deg_2; solC2 = angle3_deg_2; sola2 = original_a; solb2 = original_b; solc2 = side3_2; } else if (isValidNumber(b) && isValidNumber(c) && isValidNumber(B)) { // b, c, B solA2 = angle3_deg_2; solB2 = originalB; solC2 = angle2_deg_2; sola2 = side3_2; solb2 = original_b; solc2 = original_c; } else { // c, a, C solA2 = angle2_deg_2; solB2 = angle3_deg_2; solC2 = originalC; sola2 = original_a; solb2 = side3_2; solc2 = original_c; } addSolution(solA2, solB2, solC2, sola2, solb2, solc2, 2); } if (solutionSets.length === 0) { resultDiv.innerHTML = 'No triangle can be formed with the given values.'; return; } } else { resultDiv.innerHTML = 'Invalid combination of inputs. Please provide a valid set of three values (e.g., SSS, SAS, ASA, AAS, SSA).'; return; } if (solutionSets.length > 0) { resultDiv.innerHTML = solutionSets.join("); } else { resultDiv.innerHTML = 'Could not solve the triangle with the given inputs. Please check your values.'; } } function clearInputs() { document.getElementById('sideA').value = "; document.getElementById('sideB').value = "; document.getElementById('sideC').value = "; document.getElementById('angleA').value = "; document.getElementById('angleB').value = "; document.getElementById('angleC').value = "; document.getElementById('result').innerHTML = "; }

Understanding the Trigonometry Triangle Calculator

A triangle is one of the most fundamental shapes in geometry, defined by three sides and three angles. The relationships between these sides and angles are governed by the principles of trigonometry. Our Trigonometry Triangle Calculator helps you solve for unknown sides and angles of any triangle, given a sufficient set of initial information.

How It Works: The Core Principles

This calculator uses two primary trigonometric laws to determine the missing values:

  1. Law of Sines: This law states that the ratio of the length of a side of a triangle to the sine of the angle opposite that side is the same for all three sides and angles in any triangle. Mathematically, it's expressed as:
    a / sin(A) = b / sin(B) = c / sin(C)
    Where 'a', 'b', 'c' are the side lengths and 'A', 'B', 'C' are the angles opposite those sides, respectively.
  2. Law of Cosines: This is a generalization of the Pythagorean theorem and relates the lengths of the sides of a triangle to the cosine of one of its angles. It's particularly useful when you don't have a side and its opposite angle. The formulas are:
    c² = a² + b² - 2ab cos(C)
    a² = b² + c² - 2bc cos(A)
    b² = a² + c² - 2ac cos(B)
  3. Sum of Angles: The sum of the interior angles of any triangle is always 180 degrees (A + B + C = 180°).

Solving Different Triangle Cases

To uniquely determine a triangle, you generally need to know at least three pieces of information, with at least one of them being a side length. The calculator identifies the case based on your inputs and applies the appropriate laws:

1. SSS (Side-Side-Side)

Given: All three side lengths (a, b, c).
Calculation: The calculator uses the Law of Cosines to find each of the three angles.
Example: If side a = 5, side b = 7, and side c = 10.
cos(A) = (7² + 10² - 5²) / (2 * 7 * 10) = (49 + 100 - 25) / 140 = 124 / 140 ≈ 0.8857
A = arccos(0.8857) ≈ 27.66°
Similarly, B and C are calculated.

2. SAS (Side-Angle-Side)

Given: Two side lengths and the included angle (e.g., a, C, b).
Calculation: The Law of Cosines is used to find the third side, then the Law of Sines (or Cosines) for the remaining angles.
Example: If side a = 8, side b = 12, and angle C = 60°.
c² = 8² + 12² - 2 * 8 * 12 * cos(60°)
c² = 64 + 144 - 192 * 0.5 = 208 - 96 = 112
c = √112 ≈ 10.58
Then, use Law of Sines to find A or B.

3. ASA (Angle-Side-Angle)

Given: Two angles and the included side (e.g., A, c, B).
Calculation: The third angle is found using the sum of angles (180° – A – B). Then, the Law of Sines is used to find the other two sides.
Example: If angle A = 45°, angle B = 75°, and side c = 15.
C = 180° - 45° - 75° = 60°
a / sin(45°) = 15 / sin(60°) => a = (15 * sin(45°)) / sin(60°) ≈ 12.25
b / sin(75°) = 15 / sin(60°) => b = (15 * sin(75°)) / sin(60°) ≈ 16.73

4. AAS (Angle-Angle-Side)

Given: Two angles and a non-included side (e.g., A, B, a).
Calculation: Similar to ASA, the third angle is found first (180° – A – B). Then, the Law of Sines is used to find the remaining sides.
Example: If angle A = 30°, angle B = 50°, and side a = 10.
C = 180° - 30° - 50° = 100°
b / sin(50°) = 10 / sin(30°) => b = (10 * sin(50°)) / sin(30°) ≈ 15.32
c / sin(100°) = 10 / sin(30°) => c = (10 * sin(100°)) / sin(30°) ≈ 19.70

5. SSA (Side-Side-Angle) – The Ambiguous Case

Given: Two side lengths and a non-included angle (e.g., a, b, A).
Calculation: This is the most complex case because it can result in zero, one, or two possible triangles. The calculator uses the Law of Sines to find the second angle.
sin(B) = (b * sin(A)) / a
Based on the value of sin(B) and the relationship between 'a' and 'b', the calculator determines the number of solutions:

  • If sin(B) > 1: No triangle exists.
  • If sin(B) = 1: One right-angled triangle exists.
  • If sin(B) < 1:
    • If a >= b: One triangle exists.
    • If a < b: Two possible triangles can exist (one acute, one obtuse for angle B), or one if the second solution is invalid. The calculator will display both valid solutions if they exist.

Example (Ambiguous): If side a = 6, side b = 10, and angle A = 30°.
sin(B) = (10 * sin(30°)) / 6 = (10 * 0.5) / 6 = 5 / 6 ≈ 0.8333
B1 = arcsin(0.8333) ≈ 56.44°
C1 = 180° - 30° - 56.44° = 93.56°
c1 = (6 * sin(93.56°)) / sin(30°) ≈ 11.97
Second Solution:
B2 = 180° - 56.44° = 123.56°
C2 = 180° - 30° - 123.56° = 26.44°
c2 = (6 * sin(26.44°)) / sin(30°) ≈ 5.33
In this case, two valid triangles are possible, and the calculator will show both sets of results.

How to Use the Calculator

Simply input any three known values into the corresponding fields. Ensure angles are in degrees. Click "Calculate Triangle" to see the results. If multiple solutions are possible (as in the ambiguous SSA case), all valid solutions will be displayed. Click "Clear" to reset the fields for a new calculation.

Leave a Comment