Triangle Side Calculator

Triangle Side Calculator (Law of Cosines)

Use this calculator to find the length of the third side of a triangle when you know the lengths of two sides and the measure of the included angle (the angle between those two sides).

Result:

function calculateSideC() { var sideA = parseFloat(document.getElementById('sideA').value); var sideB = parseFloat(document.getElementById('sideB').value); var angleC = parseFloat(document.getElementById('angleC').value); // Input validation if (isNaN(sideA) || isNaN(sideB) || isNaN(angleC) || sideA <= 0 || sideB <= 0 || angleC = 180) { document.getElementById('result').innerHTML = 'Please enter valid positive numbers for sides and an angle between 0 and 180 degrees.'; return; } // Convert angle from degrees to radians var angleCRadians = angleC * (Math.PI / 180); // Apply the Law of Cosines: c^2 = a^2 + b^2 – 2ab * cos(C) var sideCSquared = (sideA * sideA) + (sideB * sideB) – (2 * sideA * sideB * Math.cos(angleCRadians)); // Handle potential floating point inaccuracies that might result in a tiny negative number if (sideCSquared < 0) { sideCSquared = 0; } var sideC = Math.sqrt(sideCSquared); document.getElementById('result').innerHTML = 'The length of Side \'c\' is approximately: ' + sideC.toFixed(4) + ' units.'; }

Understanding the Triangle Side Calculator

Triangles are fundamental shapes in geometry, and often, you need to determine the length of one of their sides. This calculator specifically uses the Law of Cosines to find the length of an unknown side when you have two known sides and the angle included between them (SAS – Side-Angle-Side).

What is the Law of Cosines?

The Law of Cosines is a generalization of the Pythagorean theorem that can be used for any triangle, not just right-angled ones. It relates the lengths of the sides of a triangle to the cosine of one of its angles. The formula used in this calculator is:

c² = a² + b² - 2ab cos(C)

Where:

  • a and b are the lengths of two known sides of the triangle.
  • C is the angle included between sides a and b (opposite to side c).
  • c is the length of the unknown side you want to calculate.

If the angle C is 90 degrees (a right angle), then cos(90°) = 0, and the formula simplifies to c² = a² + b², which is the Pythagorean theorem. This demonstrates how the Law of Cosines extends the Pythagorean theorem to all triangles.

How to Use This Calculator

  1. Enter Side 'a' Length: Input the length of the first known side of your triangle.
  2. Enter Side 'b' Length: Input the length of the second known side of your triangle.
  3. Enter Included Angle 'C' (degrees): Input the measure of the angle that is *between* Side 'a' and Side 'b'. Ensure this angle is in degrees.
  4. Click "Calculate Side 'c'": The calculator will then apply the Law of Cosines and display the length of the third side, 'c'.

Examples

Example 1: Finding the Third Side of an Obtuse Triangle

Imagine you have a triangle where:

  • Side 'a' = 10 units
  • Side 'b' = 12 units
  • Included Angle 'C' = 120 degrees

Using the Law of Cosines:

c² = 10² + 12² - 2 * 10 * 12 * cos(120°)

c² = 100 + 144 - 240 * (-0.5)

c² = 244 + 120

c² = 364

c = √364 ≈ 19.0788

The calculator would output: 19.0788 units.

Example 2: Finding the Hypotenuse of a Right Triangle

Although this calculator is for general triangles, it can also solve right triangles. Consider a right triangle with legs:

  • Side 'a' = 3 units
  • Side 'b' = 4 units
  • Included Angle 'C' = 90 degrees

Using the Law of Cosines:

c² = 3² + 4² - 2 * 3 * 4 * cos(90°)

c² = 9 + 16 - 24 * 0

c² = 25

c = √25 = 5

The calculator would output: 5.0000 units, which is the expected hypotenuse.

Other Methods for Finding Triangle Sides

While the Law of Cosines is powerful, other methods are used depending on the known information:

  • Pythagorean Theorem: Used exclusively for right-angled triangles (a² + b² = c²) when two sides are known.
  • Law of Sines: Used when you know two angles and one side (AAS or ASA), or two sides and a non-included angle (SSA – ambiguous case). The formula is a/sin(A) = b/sin(B) = c/sin(C).

This calculator focuses on the Law of Cosines (SAS) to provide a precise solution for a common triangle problem.

.calculator-container { background-color: #f9f9f9; border: 1px solid #ddd; padding: 20px; border-radius: 8px; max-width: 600px; margin: 20px auto; font-family: Arial, sans-serif; } .calculator-container h2 { color: #333; text-align: center; margin-bottom: 20px; } .calculator-container p { color: #555; line-height: 1.6; } .form-group { margin-bottom: 15px; } .form-group label { display: block; margin-bottom: 5px; font-weight: bold; color: #444; } .form-group input[type="number"] { width: calc(100% – 22px); padding: 10px; border: 1px solid #ccc; border-radius: 4px; box-sizing: border-box; } .calculator-container button { background-color: #007bff; color: white; padding: 12px 20px; border: none; border-radius: 4px; cursor: pointer; font-size: 16px; width: 100%; box-sizing: border-box; transition: background-color 0.3s ease; } .calculator-container button:hover { background-color: #0056b3; } .result-container { margin-top: 20px; padding: 15px; background-color: #e9ecef; border: 1px solid #ced4da; border-radius: 4px; text-align: center; } .result-container h3 { color: #333; margin-top: 0; margin-bottom: 10px; } .result-container p { font-size: 1.1em; font-weight: bold; color: #007bff; } .article-content { max-width: 600px; margin: 40px auto; font-family: Arial, sans-serif; line-height: 1.7; color: #333; } .article-content h2, .article-content h3 { color: #2c3e50; margin-top: 30px; margin-bottom: 15px; } .article-content ul { list-style-type: disc; margin-left: 20px; margin-bottom: 15px; } .article-content ol { list-style-type: decimal; margin-left: 20px; margin-bottom: 15px; } .article-content li { margin-bottom: 5px; } .article-content code { background-color: #eef; padding: 2px 4px; border-radius: 3px; font-family: 'Courier New', Courier, monospace; }

Leave a Reply

Your email address will not be published. Required fields are marked *