Three Sides (SSS)
Two Sides & Included Angle (SAS)
Two Angles & Included Side (ASA)
Two Angles & Non-Included Side (AAS)
Two Sides & Opposite Angle (SSA)
Triangle Solution
Side a:–
Side b:–
Side c:–
Angle A:–°
Angle B:–°
Angle C:–°
Area:–
Perimeter:–
function updateTriangleInputs() {
var method = document.getElementById("inputMethod").value;
var l1 = document.getElementById("label1");
var l2 = document.getElementById("label2");
var l3 = document.getElementById("label3");
document.getElementById("triResults").style.display = "none";
document.getElementById("triError").style.display = "none";
if (method === "SSS") {
l1.innerText = "Side a"; l2.innerText = "Side b"; l3.innerText = "Side c";
} else if (method === "SAS") {
l1.innerText = "Side a"; l2.innerText = "Angle C (°)"; l3.innerText = "Side b";
} else if (method === "ASA") {
l1.innerText = "Angle A (°)"; l2.innerText = "Side c"; l3.innerText = "Angle B (°)";
} else if (method === "AAS") {
l1.innerText = "Angle A (°)"; l2.innerText = "Angle B (°)"; l3.innerText = "Side a";
} else if (method === "SSA") {
l1.innerText = "Side a"; l2.innerText = "Side b"; l3.innerText = "Angle A (°)";
}
}
function toRad(deg) { return deg * (Math.PI / 180); }
function toDeg(rad) { return rad * (180 / Math.PI); }
function solveTriangle() {
var method = document.getElementById("inputMethod").value;
var v1 = parseFloat(document.getElementById("val1").value);
var v2 = parseFloat(document.getElementById("val2").value);
var v3 = parseFloat(document.getElementById("val3").value);
var errorDiv = document.getElementById("triError");
var resultsDiv = document.getElementById("triResults");
errorDiv.style.display = "none";
resultsDiv.style.display = "none";
if (isNaN(v1) || isNaN(v2) || isNaN(v3) || v1 <= 0 || v2 <= 0 || v3 <= 0) {
errorDiv.innerText = "Please enter valid positive numbers for all fields.";
errorDiv.style.display = "block";
return;
}
var a, b, c, A, B, C;
try {
if (method === "SSS") {
a = v1; b = v2; c = v3;
if (a + b <= c || a + c <= b || b + c = 180) throw "Angle must be less than 180 degrees.";
c = Math.sqrt(a*a + b*b – 2*a*b*Math.cos(toRad(C)));
A = toDeg(Math.asin(a * Math.sin(toRad(C)) / c));
B = 180 – A – C;
} else if (method === "ASA") {
A = v1; c = v2; B = v3;
if (A + B >= 180) throw "Sum of angles must be less than 180 degrees.";
C = 180 – A – B;
a = c * Math.sin(toRad(A)) / Math.sin(toRad(C));
b = c * Math.sin(toRad(B)) / Math.sin(toRad(C));
} else if (method === "AAS") {
A = v1; B = v2; a = v3;
if (A + B >= 180) throw "Sum of angles must be less than 180 degrees.";
C = 180 – A – B;
b = a * Math.sin(toRad(B)) / Math.sin(toRad(A));
c = a * Math.sin(toRad(C)) / Math.sin(toRad(A));
} else if (method === "SSA") {
a = v1; b = v2; A = v3;
if (A >= 180) throw "Angle must be less than 180 degrees.";
var sinB = b * Math.sin(toRad(A)) / a;
if (sinB > 1) throw "No such triangle exists with these dimensions.";
B = toDeg(Math.asin(sinB));
C = 180 – A – B;
c = a * Math.sin(toRad(C)) / Math.sin(toRad(A));
}
var s = (a + b + c) / 2;
var area = Math.sqrt(s * (s – a) * (s – b) * (s – c));
var perimeter = a + b + c;
document.getElementById("res_a").innerText = a.toFixed(4);
document.getElementById("res_b").innerText = b.toFixed(4);
document.getElementById("res_c").innerText = c.toFixed(4);
document.getElementById("res_A").innerText = A.toFixed(4);
document.getElementById("res_B").innerText = B.toFixed(4);
document.getElementById("res_C").innerText = C.toFixed(4);
document.getElementById("res_area").innerText = area.toFixed(4);
document.getElementById("res_peri").innerText = perimeter.toFixed(4);
resultsDiv.style.display = "block";
} catch (err) {
errorDiv.innerText = err;
errorDiv.style.display = "block";
}
}
Understanding Triangle Geometry
Solving a triangle means finding the lengths of all three sides and the measurements of all three angles. In geometry, you can completely determine a triangle's properties if you know at least three of its parts, provided at least one of those parts is a side length.
Common Triangle Cases
SSS (Side-Side-Side): You know the lengths of all three sides. We use the Law of Cosines to find the angles.
SAS (Side-Angle-Side): You know two sides and the angle between them. We find the third side using the Law of Cosines, then the remaining angles using the Law of Sines.
ASA (Angle-Side-Angle): You know two angles and the side connecting them. We find the third angle using the 180-degree rule and then the sides via the Law of Sines.
AAS (Angle-Angle-Side): You know two angles and a side that is not between them. Similar to ASA, we find the third angle first.
SSA (Side-Side-Angle): This is known as the "ambiguous case." Depending on the values, there could be no triangle, one triangle, or two different triangles. This calculator solves for the standard primary triangle.
The Mathematical Formulas Used
To solve these triangles, our calculator utilizes the following fundamental trigonometric laws:
1. Law of Sines: a / sin(A) = b / sin(B) = c / sin(C)
2. Law of Cosines: c² = a² + b² – 2ab · cos(C)
3. Heron's Formula (for Area): Area = √[s(s-a)(s-b)(s-c)], where s is the semi-perimeter (a+b+c)/2.
Practical Example
Suppose you have a triangular garden. You know that two sides are 10 meters and 12 meters long, and the angle between them is 45 degrees (SAS case).
Using the calculator, you would input Side a = 10, Angle C = 45, and Side b = 12.
The calculator will tell you that the third side (c) is approximately 8.57 meters, the area is 42.43 square meters, and the perimeter is 30.57 meters.
Triangle Inequality Theorem
It is important to remember that for any triangle, the sum of the lengths of any two sides must be strictly greater than the length of the third side. If you enter sides like 2, 2, and 10, the calculator will return an error because it is physically impossible to connect those lines into a triangle.