Law of Cosines Calculator

Law of Cosines Calculator

Use this calculator to find either a missing side or a missing angle of a triangle using the Law of Cosines. The Law of Cosines is a fundamental formula in trigonometry that relates the lengths of the sides of a triangle to the cosine of one of its angles. It is particularly useful for solving non-right triangles when you have specific combinations of known sides and angles.

Calculate a Missing Side (SAS – Side-Angle-Side)

Enter the lengths of two sides and the measure of the included angle (the angle between those two sides) to find the length of the third side.








Calculate a Missing Angle (SSS – Side-Side-Side)

Enter the lengths of all three sides of the triangle to find the measure of a missing angle (e.g., Angle 'C').







function calculateMissingSide() { var a = parseFloat(document.getElementById('sideA_side').value); var b = parseFloat(document.getElementById('sideB_side').value); var C_degrees = parseFloat(document.getElementById('angleC_side').value); var resultDiv = document.getElementById('resultSide'); resultDiv.innerHTML = "; // Clear previous results if (isNaN(a) || isNaN(b) || isNaN(C_degrees) || a <= 0 || b <= 0 || C_degrees = 180) { resultDiv.innerHTML = 'Please enter valid positive numbers for sides and an angle between 0 and 180 degrees (exclusive).'; return; } var C_radians = C_degrees * (Math.PI / 180); var c_squared = (a * a) + (b * b) – (2 * a * b * Math.cos(C_radians)); if (c_squared 0, 0 < C < 180) // but can occur due to floating point inaccuracies or extreme values close to 0/180. resultDiv.innerHTML = 'Cannot form a triangle with these inputs. Resulting side squared is negative.'; return; } var c = Math.sqrt(c_squared); resultDiv.innerHTML = 'The missing side \'c\' is approximately: ' + c.toFixed(4) + ' units.'; } function calculateMissingAngle() { var a = parseFloat(document.getElementById('sideA_angle').value); var b = parseFloat(document.getElementById('sideB_angle').value); var c = parseFloat(document.getElementById('sideC_angle').value); var resultDiv = document.getElementById('resultAngle'); resultDiv.innerHTML = "; // Clear previous results if (isNaN(a) || isNaN(b) || isNaN(c) || a <= 0 || b <= 0 || c c) && (a + c > b) && (b + c > a))) { resultDiv.innerHTML = 'These side lengths cannot form a valid triangle (Triangle Inequality Theorem).'; return; } var numerator = (a * a) + (b * b) – (c * c); var denominator = 2 * a * b; if (denominator === 0) { // Should not happen if a and b are positive resultDiv.innerHTML = 'Error: Denominator is zero. Please check side values.'; return; } var cosC = numerator / denominator; // Check if cosC is within the valid range [-1, 1] for Math.acos // Due to floating point arithmetic, cosC might be slightly outside this range (e.g., 1.0000000000000001 or -1.0000000000000001) // We clamp it to ensure Math.acos returns a valid number. if (cosC > 1) cosC = 1; if (cosC < -1) cosC = -1; var C_radians = Math.acos(cosC); var C_degrees = C_radians * (180 / Math.PI); resultDiv.innerHTML = 'The missing Angle \'C\' is approximately: ' + C_degrees.toFixed(4) + ' degrees.'; }

Understanding and Using the Law of Cosines

What is the Law of Cosines?

The Law of Cosines is a fundamental theorem in trigonometry that extends the Pythagorean theorem to all triangles, not just right-angled ones. It establishes a relationship between the lengths of the sides of a triangle and the cosine of one of its angles. It's particularly useful when you don't have a right angle in your triangle, or when the Law of Sines isn't directly applicable.

The Formulas

For a triangle with sides a, b, c and angles A, B, C opposite those sides respectively, the Law of Cosines can be stated in two primary forms:

1. To Find a Missing Side (SAS – Side-Angle-Side)

If you know two sides and the included angle (the angle between those two sides), you can find the length of the third side:

  • c² = a² + b² - 2ab cos(C)
  • a² = b² + c² - 2bc cos(A)
  • b² = a² + c² - 2ac cos(B)

In our calculator, we focus on finding side 'c' given sides 'a', 'b' and angle 'C'.

2. To Find a Missing Angle (SSS – Side-Side-Side)

If you know the lengths of all three sides of a triangle, you can find the measure of any of its angles by rearranging the formula:

  • cos(C) = (a² + b² - c²) / (2ab)
  • cos(A) = (b² + c² - a²) / (2bc)
  • cos(B) = (a² + c² - b²) / (2ac)

Our calculator helps you find angle 'C' given sides 'a', 'b', and 'c'.

When to Use the Law of Cosines

The Law of Cosines is your go-to tool in two main scenarios:

  1. SAS (Side-Angle-Side): You are given the lengths of two sides and the measure of the angle included between them. You want to find the length of the third side.

    Example: You know side 'a' = 10 units, side 'b' = 12 units, and the included angle 'C' = 60 degrees. You want to find side 'c'.

    Using the formula c² = a² + b² - 2ab cos(C):

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

    c² = 100 + 144 - 240 * 0.5

    c² = 244 - 120

    c² = 124

    c = √124 ≈ 11.1355 units

  2. SSS (Side-Side-Side): You are given the lengths of all three sides of the triangle. You want to find the measure of one of the angles.

    Example: You know side 'a' = 10 units, side 'b' = 12 units, and side 'c' = 11 units. You want to find Angle 'C'.

    Using the formula cos(C) = (a² + b² - c²) / (2ab):

    cos(C) = (10² + 12² - 11²) / (2 * 10 * 12)

    cos(C) = (100 + 144 - 121) / 240

    cos(C) = 123 / 240

    cos(C) = 0.5125

    C = arccos(0.5125) ≈ 59.179 degrees

Applications

The Law of Cosines is a powerful tool used in various fields, including:

  • Surveying: To calculate distances and angles in land measurement.
  • Navigation: For determining distances and bearings in air and sea travel.
  • Engineering: In structural design and mechanics to analyze forces and shapes.
  • Physics: To solve problems involving vectors and forces.
  • Astronomy: For calculating distances between celestial bodies.

By providing a way to solve for unknown sides or angles in any triangle, the Law of Cosines is an indispensable part of geometry and trigonometry.

Leave a Reply

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