Triangle Side Calculator

Triangle Side Calculator

Right-Angled Triangle (Pythagorean) General Triangle (Side-Angle-Side)

Calculation Result

0

How to Calculate Triangle Sides

Whether you are working on a geometry assignment or a DIY home improvement project, finding the third side of a triangle is a common mathematical task. Our Triangle Side Calculator uses two primary mathematical principles depending on the information you have: the Pythagorean Theorem and the Law of Cosines.

1. Right-Angled Triangles (Pythagorean Theorem)

If you have a right triangle (where one angle is exactly 90 degrees), you can use the Pythagorean Theorem to find the hypotenuse (the side opposite the right angle). The formula is:

a² + b² = c²

Where a and b are the legs of the triangle and c is the longest side.

2. General Triangles (Law of Cosines)

If the triangle is not a right triangle, but you know two sides and the angle between them (SAS – Side-Angle-Side), you use the Law of Cosines:

c² = a² + b² – 2ab · cos(γ)

Where γ (gamma) is the angle between sides a and b.

Practical Examples

  • Construction: If you are building a rectangular deck and want to ensure it is square, you can measure side A (3 meters) and side B (4 meters). The diagonal (side C) should be exactly 5 meters if the corners are 90 degrees.
  • Roofing: To find the length of a rafter, you measure the horizontal run and the vertical rise. The rafter represents the hypotenuse of a right triangle.
  • Landscaping: If you have a triangular garden bed where two sides meet at a 60-degree angle, you can use the SAS method to determine the length of the third side for fencing.
function toggleInputs() { var mode = document.getElementById("calcMode").value; var angleDiv = document.getElementById("inputGroupAngle"); if (mode === "sas") { angleDiv.style.display = "block"; } else { angleDiv.style.display = "none"; } } function calculateTriangle() { var mode = document.getElementById("calcMode").value; var a = parseFloat(document.getElementById("sideA").value); var b = parseFloat(document.getElementById("sideB").value); var resultDiv = document.getElementById("resultDisplay"); var resultText = document.getElementById("finalResult"); var methodText = document.getElementById("methodUsed"); if (isNaN(a) || isNaN(b) || a <= 0 || b <= 0) { alert("Please enter valid positive numbers for side lengths."); return; } var c = 0; if (mode === "right") { // Pythagorean Theorem: c = sqrt(a^2 + b^2) c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2)); methodText.innerText = "Calculated using Pythagorean Theorem (a² + b² = c²)"; } else { // Law of Cosines: c = sqrt(a^2 + b^2 – 2ab*cos(angle)) var angleDeg = parseFloat(document.getElementById("angleC").value); if (isNaN(angleDeg) || angleDeg = 180) { alert("Please enter a valid angle between 0 and 180 degrees."); return; } var angleRad = angleDeg * (Math.PI / 180); c = Math.sqrt(Math.pow(a, 2) + Math.pow(b, 2) – (2 * a * b * Math.cos(angleRad))); methodText.innerText = "Calculated using Law of Cosines (Side-Angle-Side)"; } if (isNaN(c)) { resultText.innerText = "Invalid Triangle"; methodText.innerText = "The dimensions provided do not form a valid triangle."; } else { resultText.innerText = "Side C = " + c.toFixed(4); } resultDiv.style.display = "block"; }

Leave a Comment