How to Calculate the Area of a Triangle
The area of a triangle is the total space enclosed within its three sides. Depending on the information you have available (base and height vs. all three sides), there are different formulas you can use to find the result.
1. Using Base and Height
This is the most common method. If you know the length of one side (the base) and the perpendicular distance from that side to the opposite vertex (the height), use this formula:
Area = 0.5 × Base × Height
Example: If a triangle has a base of 10 cm and a height of 5 cm, the area is 0.5 × 10 × 5 = 25 cm².
2. Using Heron's Formula (Three Sides)
If you know the lengths of all three sides (a, b, and c) but not the height, you use Heron's Formula. First, calculate the semi-perimeter (s):
s = (a + b + c) / 2
Then, calculate the area:
Area = √[ s(s – a)(s – b)(s – c) ]
Example: For a triangle with sides 3, 4, and 5:
s = (3 + 4 + 5) / 2 = 6
Area = √[ 6(6-3)(6-4)(6-5) ] = √[ 6 × 3 × 2 × 1 ] = √36 = 6.
Important Note: Triangle Inequality
For a triangle to exist, the sum of any two sides must be greater than the third side. If your side measurements do not satisfy this (e.g., sides of 1, 2, and 10), it is mathematically impossible to form a triangle.
function switchMethod() {
var method = document.getElementById("calcMethod").value;
var baseHeightDiv = document.getElementById("baseHeightInputs");
var threeSidesDiv = document.getElementById("threeSidesInputs");
var resultDiv = document.getElementById("resultArea");
resultDiv.style.display = "none";
if (method === "baseHeight") {
baseHeightDiv.style.display = "block";
threeSidesDiv.style.display = "none";
} else {
baseHeightDiv.style.display = "none";
threeSidesDiv.style.display = "block";
}
}
function calculateTriangleArea() {
var method = document.getElementById("calcMethod").value;
var resultDiv = document.getElementById("resultArea");
var areaOutput = document.getElementById("areaOutput");
var explanationOutput = document.getElementById("explanationOutput");
var area = 0;
if (method === "baseHeight") {
var b = parseFloat(document.getElementById("base").value);
var h = parseFloat(document.getElementById("height").value);
if (isNaN(b) || isNaN(h) || b <= 0 || h <= 0) {
alert("Please enter valid positive numbers for base and height.");
return;
}
area = 0.5 * b * h;
areaOutput.innerHTML = area.toFixed(2) + " units²";
explanationOutput.innerHTML = "Calculated using Area = 0.5 × " + b + " × " + h;
} else {
var a = parseFloat(document.getElementById("sideA").value);
var b = parseFloat(document.getElementById("sideB").value);
var c = parseFloat(document.getElementById("sideC").value);
if (isNaN(a) || isNaN(b) || isNaN(c) || a <= 0 || b <= 0 || c <= 0) {
alert("Please enter valid positive numbers for all three sides.");
return;
}
// Check Triangle Inequality
if ((a + b <= c) || (a + c <= b) || (b + c <= a)) {
alert("Invalid Triangle: The sum of any two sides must be greater than the third side.");
return;
}
var s = (a + b + c) / 2;
area = Math.sqrt(s * (s – a) * (s – b) * (s – c));
areaOutput.innerHTML = area.toFixed(2) + " units²";
explanationOutput.innerHTML = "Calculated using Heron's Formula (Semi-perimeter: " + s.toFixed(2) + ")";
}
resultDiv.style.display = "block";
resultDiv.scrollIntoView({ behavior: 'smooth', block: 'nearest' });
}