Pythagoras Theorem Calculator

Pythagoras Theorem Calculator

Enter two values above to calculate the third.
function calculatePythagoras() { var sideA_str = document.getElementById('sideA').value; var sideB_str = document.getElementById('sideB').value; var hypotenuseC_str = document.getElementById('hypotenuseC').value; var a = parseFloat(sideA_str); var b = parseFloat(sideB_str); var c = parseFloat(hypotenuseC_str); var resultDiv = document.getElementById('pythagorasResult'); resultDiv.style.color = '#333'; // Reset color for new calculations var numInputs = 0; if (!isNaN(a) && a > 0) numInputs++; if (!isNaN(b) && b > 0) numInputs++; if (!isNaN(c) && c > 0) numInputs++; if (numInputs < 2) { resultDiv.innerHTML = "Error: Please enter at least two positive values."; resultDiv.style.color = 'red'; return; } if (numInputs === 3) { resultDiv.innerHTML = "Error: Please leave one field blank to calculate the unknown side."; resultDiv.style.color = 'red'; return; } var calculatedValue; var calculatedSide = ''; if (isNaN(c) || c <= 0) { // Calculate Hypotenuse C if (isNaN(a) || a <= 0 || isNaN(b) || b <= 0) { resultDiv.innerHTML = "Error: Both Side A and Side B must be positive to calculate Hypotenuse C."; resultDiv.style.color = 'red'; return; } calculatedValue = Math.sqrt(a * a + b * b); calculatedSide = 'Hypotenuse C'; } else if (isNaN(a) || a <= 0) { // Calculate Side A if (isNaN(b) || b <= 0 || isNaN(c) || c <= 0) { resultDiv.innerHTML = "Error: Both Side B and Hypotenuse C must be positive to calculate Side A."; resultDiv.style.color = 'red'; return; } if (c <= b) { resultDiv.innerHTML = "Error: Hypotenuse C must be greater than Side B."; resultDiv.style.color = 'red'; return; } calculatedValue = Math.sqrt(c * c – b * b); calculatedSide = 'Side A'; } else if (isNaN(b) || b <= 0) { // Calculate Side B if (isNaN(a) || a <= 0 || isNaN(c) || c <= 0) { resultDiv.innerHTML = "Error: Both Side A and Hypotenuse C must be positive to calculate Side B."; resultDiv.style.color = 'red'; return; } if (c 0) { resultDiv.innerHTML = calculatedSide + ": " + calculatedValue.toFixed(4); } else { resultDiv.innerHTML = "Error: Calculation resulted in an invalid number. Check your inputs."; resultDiv.style.color = 'red'; } }

Understanding the Pythagoras Theorem

The Pythagoras Theorem is a fundamental principle in geometry that describes the relationship between the three sides of a right-angled triangle. A right-angled triangle is a triangle in which one of the angles is exactly 90 degrees.

The Formula

The theorem states that the square of the length of the hypotenuse (the side opposite the right angle) is equal to the sum of the squares of the lengths of the other two sides. This can be expressed with the following formula:

a² + b² = c²

Where:

  • a and b are the lengths of the two shorter sides (legs) of the right-angled triangle.
  • c is the length of the hypotenuse, which is always the longest side.

How to Use This Calculator

This calculator allows you to find the length of any unknown side of a right-angled triangle, provided you know the lengths of the other two sides. Simply enter the values for the two known sides into their respective fields, and leave the field for the unknown side blank. Click "Calculate Unknown Side" to get your result.

Examples:

Example 1: Finding the Hypotenuse

Imagine you have a right-angled triangle where Side A is 3 units long and Side B is 4 units long. You want to find the length of the Hypotenuse C.

  • Enter '3' in the "Side A" field.
  • Enter '4' in the "Side B" field.
  • Leave "Hypotenuse C" blank.
  • Click "Calculate Unknown Side".

The calculator will show: Hypotenuse C: 5.0000 (since 3² + 4² = 9 + 16 = 25, and √25 = 5).

Example 2: Finding a Shorter Side

Suppose you know the Hypotenuse C is 13 units long and Side A is 5 units long. You need to find the length of Side B.

  • Enter '5' in the "Side A" field.
  • Leave "Side B" blank.
  • Enter '13' in the "Hypotenuse C" field.
  • Click "Calculate Unknown Side".

The calculator will show: Side B: 12.0000 (since 5² + B² = 13², which means 25 + B² = 169, so B² = 144, and √144 = 12).

Example 3: Another Shorter Side Calculation

If Hypotenuse C is 10 units and Side B is 8 units, let's find Side A.

  • Leave "Side A" blank.
  • Enter '8' in the "Side B" field.
  • Enter '10' in the "Hypotenuse C" field.
  • Click "Calculate Unknown Side".

The calculator will show: Side A: 6.0000 (since A² + 8² = 10², which means A² + 64 = 100, so A² = 36, and √36 = 6).

The Pythagoras Theorem is widely used in various fields, including construction, navigation, engineering, and even in computer graphics, to calculate distances and dimensions in two-dimensional space.

Leave a Reply

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