Law of Cosines Calculator

Law of Cosines Calculator – Solve Triangle Sides and Angles * { margin: 0; padding: 0; box-sizing: border-box; } body { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); padding: 20px; line-height: 1.6; } .container { max-width: 1000px; margin: 0 auto; background: white; border-radius: 20px; box-shadow: 0 20px 60px rgba(0,0,0,0.3); overflow: hidden; } .header { background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; padding: 40px; text-align: center; } .header h1 { font-size: 2.5em; margin-bottom: 10px; text-shadow: 2px 2px 4px rgba(0,0,0,0.2); } .header p { font-size: 1.2em; opacity: 0.95; } .content { padding: 40px; } .calculator-section { background: #f8f9ff; padding: 30px; border-radius: 15px; margin-bottom: 30px; box-shadow: 0 5px 15px rgba(0,0,0,0.08); } .mode-selector { margin-bottom: 25px; text-align: center; } .mode-selector label { font-weight: 600; font-size: 1.1em; color: #333; margin-right: 15px; } .mode-selector select { padding: 10px 20px; border: 2px solid #667eea; border-radius: 8px; font-size: 1em; background: white; cursor: pointer; min-width: 250px; } .input-group { margin-bottom: 25px; } .input-group label { display: block; margin-bottom: 8px; color: #333; font-weight: 600; font-size: 1.05em; } .input-group input { width: 100%; padding: 15px; border: 2px solid #e0e0e0; border-radius: 10px; font-size: 1.1em; transition: all 0.3s ease; } .input-group input:focus { outline: none; border-color: #667eea; box-shadow: 0 0 0 3px rgba(102,126,234,0.1); } .input-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 20px; } .calculate-btn { width: 100%; padding: 18px; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); color: white; border: none; border-radius: 10px; font-size: 1.2em; font-weight: 600; cursor: pointer; transition: transform 0.2s, box-shadow 0.2s; margin-top: 10px; } .calculate-btn:hover { transform: translateY(-2px); box-shadow: 0 10px 25px rgba(102,126,234,0.4); } .calculate-btn:active { transform: translateY(0); } .result { margin-top: 30px; padding: 25px; background: white; border-radius: 12px; border-left: 5px solid #667eea; display: none; } .result.show { display: block; animation: slideIn 0.4s ease; } @keyframes slideIn { from { opacity: 0; transform: translateY(-20px); } to { opacity: 1; transform: translateY(0); } } .result h3 { color: #667eea; margin-bottom: 15px; font-size: 1.5em; } .result-value { font-size: 2em; color: #333; font-weight: 700; margin: 15px 0; } .result-details { background: #f8f9ff; padding: 15px; border-radius: 8px; margin-top: 15px; } .result-details p { margin: 8px 0; color: #555; font-size: 1.05em; } .article-section { margin-top: 40px; } .article-section h2 { color: #333; margin: 30px 0 15px 0; font-size: 2em; border-bottom: 3px solid #667eea; padding-bottom: 10px; } .article-section h3 { color: #444; margin: 25px 0 12px 0; font-size: 1.5em; } .article-section p { color: #555; margin-bottom: 15px; font-size: 1.05em; text-align: justify; } .article-section ul, .article-section ol { margin: 15px 0 15px 30px; color: #555; } .article-section li { margin: 8px 0; font-size: 1.05em; } .formula-box { background: #f8f9ff; border-left: 4px solid #667eea; padding: 20px; margin: 20px 0; border-radius: 8px; font-family: 'Courier New', monospace; font-size: 1.1em; } .example-box { background: #fff9e6; border-left: 4px solid #ffd700; padding: 20px; margin: 20px 0; border-radius: 8px; } .note-box { background: #e8f5e9; border-left: 4px solid #4caf50; padding: 15px; margin: 20px 0; border-radius: 8px; } .hidden { display: none; }

⚡ Law of Cosines Calculator

Calculate triangle sides and angles using the Law of Cosines

Find Side (when 2 sides and included angle known) Find Angle (when 3 sides known)

Result

Understanding the Law of Cosines

The Law of Cosines is a fundamental theorem in trigonometry that relates the lengths of the sides of a triangle to the cosine of one of its angles. This powerful mathematical tool extends the Pythagorean theorem to work with any triangle, not just right triangles, making it essential for solving a wide range of geometric and real-world problems.

What is the Law of Cosines?

The Law of Cosines states that for any triangle with sides a, b, and c, and angles A, B, and C opposite to these sides respectively, the following relationships hold true:

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

These formulas can be rearranged to solve for angles when all three sides are known:

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

When to Use the Law of Cosines

The Law of Cosines is particularly useful in two specific scenarios:

  • SAS Case (Side-Angle-Side): When you know two sides of a triangle and the angle between them, you can find the third side.
  • SSS Case (Side-Side-Side): When you know all three sides of a triangle, you can find any of the angles.

Real-World Applications

The Law of Cosines has numerous practical applications across various fields:

  • Navigation and Surveying: Determining distances and positions in land surveying, marine navigation, and GPS calculations
  • Architecture and Engineering: Calculating structural angles and distances in building design and construction
  • Astronomy: Measuring distances between celestial objects and calculating orbital parameters
  • Physics: Analyzing vector components and solving problems involving force triangles
  • Computer Graphics: Rendering 3D objects and calculating angles in animation
  • Sports Analytics: Analyzing player positions and optimal angles in games

Step-by-Step Calculation Examples

Example 1: Finding a Side (SAS Case)

Problem: A triangle has sides a = 8 units and b = 12 units, with an included angle C = 60 degrees. Find side c.

Solution:

  1. Identify the formula: c² = a² + b² – 2ab·cos(C)
  2. Substitute values: c² = 8² + 12² – 2(8)(12)·cos(60°)
  3. Calculate: c² = 64 + 144 – 192(0.5)
  4. Simplify: c² = 208 – 96 = 112
  5. Take square root: c = √112 ≈ 10.58 units

Example 2: Finding an Angle (SSS Case)

Problem: A triangle has sides a = 7 units, b = 10 units, and c = 5 units. Find angle C.

Solution:

  1. Use the formula: cos(C) = (a² + b² – c²) / (2ab)
  2. Substitute values: cos(C) = (7² + 10² – 5²) / (2·7·10)
  3. Calculate: cos(C) = (49 + 100 – 25) / 140
  4. Simplify: cos(C) = 124 / 140 ≈ 0.8857
  5. Find angle: C = arccos(0.8857) ≈ 27.66 degrees

Relationship to the Pythagorean Theorem

The Law of Cosines actually generalizes the Pythagorean theorem. When angle C equals 90 degrees (a right angle), cos(90°) = 0, and the formula c² = a² + b² – 2ab·cos(C) reduces to c² = a² + b², which is the familiar Pythagorean theorem. This demonstrates that the Pythagorean theorem is a special case of the Law of Cosines.

Important Considerations and Triangle Inequality

When using the Law of Cosines, keep these important points in mind:

  • The sum of any two sides of a triangle must be greater than the third side (Triangle Inequality Theorem)
  • All angles in a triangle must sum to 180 degrees
  • When calculating angles, ensure your calculator is in the correct mode (degrees or radians)
  • Negative values under the square root indicate that the given measurements cannot form a valid triangle
  • Very small or very large angles may lead to computational errors; verify your results make geometric sense

Common Mistakes to Avoid

  • Angle Units: Mixing degrees and radians in calculations. Always verify your calculator mode matches your input.
  • Incorrect Side-Angle Pairing: Make sure the angle you're using is actually between the two sides in the SAS case.
  • Sign Errors: Pay careful attention to the minus sign in the formula: -2ab·cos(C).
  • Invalid Triangles: Not checking if the given measurements can actually form a triangle before calculating.
  • Rounding Too Early: Rounding intermediate results can lead to significant errors in final answers.

Advanced Applications

Beyond basic triangle solving, the Law of Cosines is essential for:

  • Vector Analysis: Finding the magnitude of the resultant when two vectors are added at an angle
  • Spherical Trigonometry: A modified version applies to triangles on the surface of a sphere, crucial in navigation
  • Signal Processing: Analyzing phase differences and interference patterns
  • Machine Learning: Calculating distances in high-dimensional spaces using cosine similarity
  • Robotics: Determining joint angles and end-effector positions in robotic arms

Calculating All Triangle Properties

Once you've used the Law of Cosines to find one unknown side or angle, you can find the remaining elements of the triangle using:

  • The Law of Cosines again for additional sides or angles
  • The Law of Sines for easier calculations once you know one complete side-angle pair
  • The angle sum property (A + B + C = 180°) to find the last angle
  • Heron's formula to calculate the area when all three sides are known

Numerical Precision and Accuracy

When performing calculations with the Law of Cosines, especially in practical applications:

  • Maintain at least 4-6 decimal places in intermediate calculations
  • Be aware that inverse cosine (arccos) can be sensitive to rounding errors when the cosine value is close to ±1
  • Use appropriate significant figures based on the precision of your input measurements
  • Consider using computational tools for complex calculations involving multiple triangles

Historical Context

The Law of Cosines has been known since ancient times, with early versions appearing in Euclid's Elements (circa 300 BCE) as geometric propositions. The algebraic formulation we use today was developed during the development of trigonometry in medieval Islamic mathematics and later refined by European mathematicians. This law, along with the Law of Sines, forms the foundation of modern trigonometry and remains essential for solving triangles in all fields of science and engineering.

Quick Reference Guide

Use Law of Cosines when you have:

  • Two sides and the included angle (SAS) → Find the third side
  • Three sides (SSS) → Find any angle

Formula Selection:

  • To find side c: c² = a² + b² – 2ab·cos(C)
  • To find angle C: cos(C) = (a² + b² – c²) / (2ab)
function changeMode() { var mode = document.getElementById('calculationMode').value; var sideInputs = document.getElementById('sideModeInputs'); var angleInputs = document.getElementById('angleModeInputs'); var resultDiv = document.getElementById('result'); if (mode === 'sideSSS') { sideInputs.classList.remove('hidden'); angleInputs.classList.add('hidden'); } else { sideInputs.classList.add('hidden'); angleInputs.classList.remove('hidden'); } resultDiv.classList.remove('show'); } function calculateResult() { var mode = document.getElementById('calculationMode').value; var resultDiv = document.getElementById('result'); var resultContent = document.getElementById('resultContent'); if (mode === 'sideSSS') { calculateSide(); } else { calculateAngle(); } } function calculateSide() { var sideAInput = document.getElementById('sideA').value; var sideBInput = document.getElementById('sideB').value; var angleCInput = document.getElementById('angleC').value; if (sideAInput === " || sideBInput === " || angleCInput === ") { alert('Please fill in all fields'); return; } var a = parseFloat(sideAInput); var b = parseFloat(sideBInput); var angleC = parseFloat(angleCInput); if (isNaN(a) || isNaN(b) || isNaN(angleC) || a <= 0 || b <= 0 || angleC = 180) { alert('Please enter valid positive numbers. Angle must be between 0 and 180 degrees.'); return; } var angleCRadians = angleC * (Math.PI / 180); var cSquared = (a * a) + (b * b) – (2 * a * b * Math.cos(angleCRadians)); if (cSquared < 0) { alert('The given measurements cannot form a valid triangle.'); return; } var c = Math.sqrt(cSquared); var cosA = (b * b + c * c – a * a) / (2 * b * c); var cosB = (a * a + c * c – b * b) / (2 * a * c); var angleA = Math.acos(cosA) * (180 / Math.PI); var angleB = Math.acos(cosB) * (180 / Math.PI); var resultContent = document.getElementById('resultContent'); resultContent.innerHTML = `
Side c = ${c.toFixed(4)} units
Complete Triangle Solution: Side a = ${a.toFixed(4)} units Side b = ${b.toFixed(4)} units Side c = ${c.toFixed(4)} units All Angles: Angle A = ${angleA.toFixed(4)}° Angle B = ${angleB.toFixed(4)}° Angle C = ${angleC.toFixed(4)}° Verification: Sum of angles = ${(angleA + angleB + angleC).toFixed(4)}° (should be 180°) Formula Used: c² = a² + b² – 2ab·cos(C) c² = ${a}² + ${b}² – 2(${a})(${b})·cos(${angleC}°) c² = ${cSquared.toFixed(4)} c = ${c.toFixed(4)} units
`; var resultDiv = document.getElementById('result'); resultDiv.classList.add('show'); } function calculateAngle() { var sideAInput = document.getElementById('sideAForAngle').value; var sideBInput = document.getElementById('sideBForAngle').value; var sideCInput = document.getElementById('sideCForAngle').value; if (sideAInput === " || sideBInput === " || sideCInput === ") { alert('Please fill in all three sides'); return; } var a = parseFloat(sideAInput); var b = parseFloat(sideBInput); var c = parseFloat(sideCInput); if (isNaN(a) || isNaN(b) || isNaN(c) || a <= 0 || b <= 0 || c <= 0) { alert('Please enter valid positive numbers for all sides.'); return; } if ((a + b <= c) || (a + c <= b) || (b + c <= a)) { alert('These sides cannot form a valid triangle. The sum of any two sides must be greater than the third side.'); return; } var cosC = (a * a + b * b – c * c) / (2 * a * b); var cosA = (b * b + c * c – a * a) / (2 * b * c); var cosB = (a * a + c * c – b * b) / (2 * a * c); if (cosC 1 || cosA 1 || cosB 1) { alert('Invalid triangle. Please check your measurements.'); return; } var angleC = Math.acos(cosC) * (180 / Math.PI); var angleA = Math.acos(cosA) * (180 / Math.PI); var angleB = Math.acos(cosB) * (180 / Math.PI); var perimeter = a + b + c; var s = perimeter / 2; var area = Math.sqrt(s * (s – a) * (s – b) * (s – c)); var resultContent = document.getElementById('resultContent'); resultContent.innerHTML = `
All Angles Calculated
Given Sides: Side a = ${a.toFixed(4)} units Side b = ${b.toFixed(4)} units Side c = ${c.toFixed(4)} units Calculated Angles: Angle A (opposite side a) = ${angleA.toFixed(4)}° Angle B (opposite side b) = ${angleB.toFixed(4)}° Angle C (opposite side c) = ${angleC.toFixed(4)}° Triangle Properties: Perimeter = ${perimeter.toFixed(4)} units Area = ${area.toFixed(4)} square units Verification: Sum of angles = ${(angleA + angleB + angleC).toFixed(4)}° (should be 180°) Formulas Used: cos(A) = (b² + c² – a²) / (2bc) cos(B) = (a² + c² – b²) / (2ac) cos(C) = (a² + b² – c²) / (2ab)
`; var resultDiv = document.getElementById('result'); resultDiv.classList.add('show'); }

Leave a Comment