Solution (SSS):
"; var s = (sideA + sideB + sideC) / 2; var area = Math.sqrt(s * (s – sideA) * (s – sideB) * (s – sideC)); // Heron's Formula var angleARad = Math.acos((sideB * sideB + sideC * sideC – sideA * sideA) / (2 * sideB * sideC)); var angleBRad = Math.acos((sideA * sideA + sideC * sideC – sideB * sideB) / (2 * sideA * sideC)); var angleCRad = Math.PI – angleARad – angleBRad; resultHTML += "Side A: " + sideA.toFixed(2) + ""; resultHTML += "Side B: " + sideB.toFixed(2) + ""; resultHTML += "Side C: " + sideC.toFixed(2) + ""; resultHTML += "Angle A: " + (angleARad * 180 / Math.PI).toFixed(2) + "°"; resultHTML += "Angle B: " + (angleBRad * 180 / Math.PI).toFixed(2) + "°"; resultHTML += "Angle C: " + (angleCRad * 180 / Math.PI).toFixed(2) + "°"; resultHTML += "Area: " + area.toFixed(2) + ""; } // Case 2: SAS (Side-Angle-Side) else if (knownSides === 2 && knownAngles === 1) { var angleToFind = ""; if (isNaN(angleA) || angleA <= 0) { angleToFind = "A"; angleA = angleA * Math.PI / 180; } else if (isNaN(angleB) || angleB <= 0) { angleToFind = "B"; angleB = angleB * Math.PI / 180; } else { angleToFind = "C"; angleC = angleC * Math.PI / 180; } var s1, s2, angleOpposite; if (angleToFind === "A") { s1 = sideB; s2 = sideC; angleOpposite = angleA; } else if (angleToFind === "B") { s1 = sideA; s2 = sideC; angleOpposite = angleB; } else { s1 = sideA; s2 = sideB; angleOpposite = angleC; } resultHTML += "Solution (SAS):
"; // Find the third side using the Law of Cosines var thirdSideSquared = s1 * s1 + s2 * s2 – 2 * s1 * s2 * Math.cos(angleOpposite); var thirdSide = Math.sqrt(thirdSideSquared); // Assign the calculated side if (angleToFind === "A") sideA = thirdSide; else if (angleToFind === "B") sideB = thirdSide; else sideC = thirdSide; // Find the remaining angles using the Law of Sines var angle1Rad, angle2Rad, angle3Rad; var finalSide1, finalSide2, finalSide3; if (angleToFind === "A") { finalSide1 = sideA; finalSide2 = sideB; finalSide3 = sideC; angle1Rad = angleA; angle2Rad = Math.asin((finalSide2 * Math.sin(angle1Rad)) / finalSide1); angle3Rad = Math.PI – angle1Rad – angle2Rad; } else if (angleToFind === "B") { finalSide1 = sideA; finalSide2 = sideB; finalSide3 = sideC; angle1Rad = angleB; angle2Rad = Math.asin((finalSide2 * Math.sin(angle1Rad)) / finalSide1); angle3Rad = Math.PI – angle1Rad – angle2Rad; } else { // Finding angle C finalSide1 = sideA; finalSide2 = sideB; finalSide3 = sideC; angle1Rad = angleC; angle2Rad = Math.asin((finalSide2 * Math.sin(angle1Rad)) / finalSide1); angle3Rad = Math.PI – angle1Rad – angle2Rad; } resultHTML += "Side A: " + sideA.toFixed(2) + ""; resultHTML += "Side B: " + sideB.toFixed(2) + ""; resultHTML += "Side C: " + sideC.toFixed(2) + ""; resultHTML += "Angle A: " + (angleA * 180 / Math.PI).toFixed(2) + "°"; resultHTML += "Angle B: " + (angleB * 180 / Math.PI).toFixed(2) + "°"; resultHTML += "Angle C: " + (angleC * 180 / Math.PI).toFixed(2) + "°"; var area = 0.5 * sideA * sideB * Math.sin(angleC); resultHTML += "Area: " + area.toFixed(2) + ""; } // Case 3: ASA (Angle-Side-Angle) or AAS (Angle-Angle-Side) else if (knownAngles >= 2 && knownSides === 1) { var knownSideValue = 0; var knownSideName = ""; if (!isNaN(sideA) && sideA > 0) { knownSideValue = sideA; knownSideName = "a"; } else if (!isNaN(sideB) && sideB > 0) { knownSideValue = sideB; knownSideName = "b"; } else if (!isNaN(sideC) && sideC > 0) { knownSideValue = sideC; knownSideName = "c"; } var angleSumKnown = 0; var angleList = []; if (!isNaN(angleA) && angleA > 0) { angleSumKnown += angleA; angleList.push({val: angleA, name: 'A'}); } if (!isNaN(angleB) && angleB > 0) { angleSumKnown += angleB; angleList.push({val: angleB, name: 'B'}); } if (!isNaN(angleC) && angleC > 0) { angleSumKnown += angleC; angleList.push({val: angleC, name: 'C'}); } var missingAngleRad = (180 – angleSumKnown) * Math.PI / 180; var missingAngleName = ""; if (angleList.length < 3) { if (isNaN(angleA) || angleA <= 0) { missingAngleName = "A"; } else if (isNaN(angleB) || angleB <= 0) { missingAngleName = "B"; } else { missingAngleName = "C"; } } // Assign calculated angles if (missingAngleName === "A") angleA = missingAngleRad * 180 / Math.PI; else if (missingAngleName === "B") angleB = missingAngleRad * 180 / Math.PI; else if (missingAngleName === "C") angleC = missingAngleRad * 180 / Math.PI; resultHTML += "Solution (ASA/AAS):
"; var angle1Rad = angleList[0].val * Math.PI / 180; var angle2Rad = angleList[1].val * Math.PI / 180; var angle3Rad = missingAngleRad; var sideCalculated = 0; var sideCalculatedName = ""; if (knownSideName === 'a') { sideA = knownSideValue; sideB = (sideA / Math.sin(angle1Rad)) * Math.sin(angle2Rad); sideC = (sideA / Math.sin(angle1Rad)) * Math.sin(angle3Rad); } else if (knownSideName === 'b') { sideB = knownSideValue; sideA = (sideB / Math.sin(angle2Rad)) * Math.sin(angle1Rad); sideC = (sideB / Math.sin(angle2Rad)) * Math.sin(angle3Rad); } else { // knownSideName === 'c' sideC = knownSideValue; sideA = (sideC / Math.sin(angle3Rad)) * Math.sin(angle1Rad); sideB = (sideC / Math.sin(angle3Rad)) * Math.sin(angle2Rad); } resultHTML += "Side A: " + sideA.toFixed(2) + ""; resultHTML += "Side B: " + sideB.toFixed(2) + ""; resultHTML += "Side C: " + sideC.toFixed(2) + ""; resultHTML += "Angle A: " + (angleA).toFixed(2) + "°"; resultHTML += "Angle B: " + (angleB).toFixed(2) + "°"; resultHTML += "Angle C: " + (angleC).toFixed(2) + "°"; var area = 0.5 * sideA * sideB * Math.sin(angleC * Math.PI / 180); resultHTML += "Area: " + area.toFixed(2) + ""; } // Case 4: SSA (Side-Side-Angle) – Ambiguous case, requires more complex handling or simplification else if (knownSides === 2 && knownAngles === 1 && resultHTML === "") { // This is the ambiguous case, where two solutions might exist. // For simplicity, we will attempt to find one solution if possible. // A full implementation would require checking the discriminant. var angleKnownRad, sideOpposite, sideAdjacent; var angleOppositeName = ""; if (!isNaN(angleA) && angleA > 0) { angleKnownRad = angleA * Math.PI / 180; angleOppositeName = 'A'; sideOpposite = sideA; sideAdjacent = sideB; } else if (!isNaN(angleB) && angleB > 0) { angleKnownRad = angleB * Math.PI / 180; angleOppositeName = 'B'; sideOpposite = sideB; sideAdjacent = sideA; } else { angleKnownRad = angleC * Math.PI / 180; angleOppositeName = 'C'; sideOpposite = sideC; sideAdjacent = sideA; } var sinAngleOther = (sideOpposite * Math.sin(angleKnownRad)) / sideAdjacent; if (sinAngleOther > 1) { resultHTML = "Error: No triangle can be formed with these values (sin value > 1)."; } else { var angleOtherRad = Math.asin(sinAngleOther); var angleOtherDeg = angleOtherRad * 180 / Math.PI; var angleThirdRad = Math.PI – angleKnownRad – angleOtherRad; var angleThirdDeg = angleThirdRad * 180 / Math.PI; var sideThird = (sideAdjacent * Math.sin(angleThirdRad)) / Math.sin(angleOtherRad); var area = 0.5 * sideAdjacent * sideThird * Math.sin(angleKnownRad); resultHTML += "Solution (SSA – One Possibility):
"; if (angleOppositeName === 'A') { sideA = sideOpposite; sideB = sideAdjacent; sideC = sideThird; angleA = angleKnownRad * 180 / Math.PI; angleB = angleOtherDeg; angleC = angleThirdDeg; } else if (angleOppositeName === 'B') { sideB = sideOpposite; sideA = sideAdjacent; sideC = sideThird; angleB = angleKnownRad * 180 / Math.PI; angleA = angleOtherDeg; angleC = angleThirdDeg; } else { // angleOppositeName === 'C' sideC = sideOpposite; sideA = sideAdjacent; sideB = sideThird; angleC = angleKnownRad * 180 / Math.PI; angleA = angleOtherDeg; angleB = angleThirdDeg; } resultHTML += "Side A: " + sideA.toFixed(2) + ""; resultHTML += "Side B: " + sideB.toFixed(2) + ""; resultHTML += "Side C: " + sideC.toFixed(2) + ""; resultHTML += "Angle A: " + angleA.toFixed(2) + "°"; resultHTML += "Angle B: " + angleB.toFixed(2) + "°"; resultHTML += "Angle C: " + angleC.toFixed(2) + "°"; resultHTML += "Area: " + area.toFixed(2) + ""; // Note: A full SSA solver would check if 180 – angleOtherDeg is also a valid angle // and calculate a second triangle if possible. if (Math.abs(angleThirdDeg – (180 – angleOtherDeg)) < 1e-6 && knownSides === 2 && knownAngles === 1) { resultHTML += "Note: The ambiguous case (SSA) may allow for a second possible triangle."; } } } } else if (resultHTML === "") { // No valid calculation scenario met resultHTML = "Please provide at least 3 distinct values (e.g., 3 sides, or 2 sides and 1 angle, or 1 side and 2 angles) to solve the triangle."; } document.getElementById("result").innerHTML = resultHTML; }Triangle Solver Calculator
Enter Known Values
Provide at least three pieces of information. If a value is unknown, leave the field blank.
Results will appear here.
Understanding the Triangle Solver Calculator
This Triangle Solver Calculator is a powerful tool designed to help you determine the unknown sides and angles of a triangle when you have partial information. Triangles are fundamental geometric shapes with numerous applications in mathematics, physics, engineering, architecture, and design. Knowing how to solve for unknown properties of a triangle is a key skill in many fields.
To uniquely define a triangle, you need at least three pieces of information. This calculator supports solving for triangles based on the following common scenarios:
- SSS (Side-Side-Side): You know the lengths of all three sides.
- SAS (Side-Angle-Side): You know the lengths of two sides and the measure of the angle between them.
- ASA (Angle-Side-Angle): You know the measures of two angles and the length of the side between them.
- AAS (Angle-Angle-Side): You know the measures of two angles and the length of a non-included side.
- SSA (Side-Side-Angle): You know the lengths of two sides and the measure of a non-included angle. This is known as the "ambiguous case" because it can sometimes lead to zero, one, or two possible triangles. This calculator provides one possible solution if it exists.
The Mathematics Behind the Solver
The calculator uses fundamental trigonometric laws to perform its calculations:
1. Law of Sines
The Law of Sines relates the lengths of the sides of a triangle to the sines of its opposite angles. For a triangle with sides a, b, c and opposite angles A, B, C respectively:
a / sin(A) = b / sin(B) = c / sin(C)
This law is particularly useful for solving ASA and AAS cases, and one part of the SSA ambiguous case.
2. Law of Cosines
The Law of Cosines relates the lengths of the sides of a triangle to the cosine of one of its angles. It can be seen as a generalization of the Pythagorean theorem.
a² = b² + c² - 2bc * cos(A)
b² = a² + c² - 2ac * cos(B)
c² = a² + b² - 2ab * cos(C)
This law is crucial for solving the SAS case (to find the third side) and can also be used in the SSS case (to find the angles).
3. Area Formulas
The calculator also provides the area of the triangle. Common formulas used include:
- Heron's Formula (for SSS): Given semi-perimeter
s = (a+b+c)/2, Area =sqrt(s(s-a)(s-b)(s-c)) - Standard Formula (for SAS): Area =
(1/2) * base * height, which can be expressed using two sides and the included angle:(1/2)ab * sin(C)
4. Triangle Inequality Theorem
A fundamental geometric principle stating that the sum of the lengths of any two sides of a triangle must be greater than the length of the third side. The calculator checks this for SSS inputs.
5. Angle Sum Property
The sum of the interior angles of any Euclidean triangle is always 180 degrees. The calculator verifies this when three angles are provided.
How to Use the Calculator
- Identify the known sides and angles of your triangle.
- Enter the known values into the corresponding input fields. Leave fields blank for unknown values.
- Ensure you provide at least three distinct pieces of information (sides or angles).
- Click the "Solve Triangle" button.
- The calculator will display the calculated lengths of the sides and measures of the angles, along with the area, or an error message if the provided values do not form a valid triangle.
Example Scenarios
Example 1: SSS Case
If you input sides: a=3, b=4, c=5. The calculator will output angles approximately A=36.87°, B=53.13°, C=90.00°, and Area=6.00.
Example 2: SAS Case
If you input sides a=10, c=7, and angle B=45°. The calculator will solve for side b, and angles A and C, and the area.
Example 3: ASA Case
If you input angles A=60°, C=80°, and side b=12. The calculator will find angle B and the lengths of sides a and c, plus the area.