Enter any two known values (sides must be positive, acute angles between 0 and 90 degrees) to solve for the remaining sides and angles of a right-angled triangle.
.trig-calculator-container {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
background-color: #f9f9f9;
padding: 25px;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
max-width: 600px;
margin: 30px auto;
border: 1px solid #e0e0e0;
}
.trig-calculator-container h2 {
color: #333;
text-align: center;
margin-bottom: 20px;
font-size: 1.8em;
}
.trig-calculator-container p {
color: #555;
margin-bottom: 20px;
line-height: 1.6;
}
.trig-input-group {
margin-bottom: 15px;
display: flex;
flex-direction: column;
}
.trig-input-group label {
margin-bottom: 8px;
color: #333;
font-weight: bold;
font-size: 0.95em;
}
.trig-input-group input[type="number"] {
padding: 12px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 1em;
width: 100%;
box-sizing: border-box;
transition: border-color 0.3s ease;
}
.trig-input-group input[type="number"]:focus {
border-color: #007bff;
outline: none;
box-shadow: 0 0 5px rgba(0, 123, 255, 0.2);
}
.trig-calculate-button {
background-color: #007bff;
color: white;
padding: 12px 25px;
border: none;
border-radius: 5px;
font-size: 1.1em;
cursor: pointer;
transition: background-color 0.3s ease, transform 0.2s ease;
width: 100%;
box-sizing: border-box;
margin-top: 10px;
}
.trig-calculate-button:hover {
background-color: #0056b3;
transform: translateY(-2px);
}
#trigResult h3 {
color: #333;
margin-bottom: 15px;
font-size: 1.5em;
}
#trigResult p {
margin-bottom: 8px;
color: #444;
font-size: 1em;
}
#trigResult p strong {
color: #000;
}
#trigError {
font-weight: bold;
font-size: 0.95em;
}
function calculateTrig() {
var sideA_str = document.getElementById('sideA').value;
var sideB_str = document.getElementById('sideB').value;
var hypotenuseC_str = document.getElementById('hypotenuseC').value;
var angleA_str = document.getElementById('angleA').value;
var angleB_str = document.getElementById('angleB').value;
var sideA = parseFloat(sideA_str);
var sideB = parseFloat(sideB_str);
var hypotenuseC = parseFloat(hypotenuseC_str);
var angleA_deg = parseFloat(angleA_str);
var angleB_deg = parseFloat(angleB_str);
var inputs = [];
if (!isNaN(sideA) && sideA > 0) inputs.push({ type: 'sideA', value: sideA });
if (!isNaN(sideB) && sideB > 0) inputs.push({ type: 'sideB', value: sideB });
if (!isNaN(hypotenuseC) && hypotenuseC > 0) inputs.push({ type: 'hypotenuseC', value: hypotenuseC });
if (!isNaN(angleA_deg) && angleA_deg > 0 && angleA_deg 0 && angleB_deg < 90) inputs.push({ type: 'angleB', value: angleB_deg });
var resultDiv = document.getElementById('trigResult');
var errorDiv = document.getElementById('trigError');
resultDiv.innerHTML = '';
errorDiv.innerHTML = '';
if (inputs.length 2) {
errorDiv.innerHTML = 'Please enter exactly two values to solve the triangle.';
return;
}
var val1 = inputs[0].value;
var type1 = inputs[0].type;
var val2 = inputs[1].value;
var type2 = inputs[1].type;
var a, b, c, alpha_deg, beta_deg; // a=sideA, b=sideB, c=hypotenuseC, alpha_deg=angleA, beta_deg=angleB
// Helper function for degrees to radians
function toRadians(degrees) {
return degrees * (Math.PI / 180);
}
// Helper function for radians to degrees
function toDegrees(radians) {
return radians * (180 / Math.PI);
}
var solved = false;
// Case 1: Two Sides
if ((type1 === 'sideA' && type2 === 'sideB') || (type1 === 'sideB' && type2 === 'sideA')) {
a = (type1 === 'sideA') ? val1 : val2;
b = (type1 === 'sideB') ? val1 : val2;
c = Math.sqrt(a * a + b * b);
alpha_deg = toDegrees(Math.atan(a / b));
beta_deg = 90 – alpha_deg;
solved = true;
} else if ((type1 === 'sideA' && type2 === 'hypotenuseC') || (type1 === 'hypotenuseC' && type2 === 'sideA')) {
a = (type1 === 'sideA') ? val1 : val2;
c = (type1 === 'hypotenuseC') ? val1 : val2;
if (a >= c) {
errorDiv.innerHTML = 'Side A cannot be greater than or equal to the hypotenuse.';
return;
}
b = Math.sqrt(c * c – a * a);
alpha_deg = toDegrees(Math.asin(a / c));
beta_deg = 90 – alpha_deg;
solved = true;
} else if ((type1 === 'sideB' && type2 === 'hypotenuseC') || (type1 === 'hypotenuseC' && type2 === 'sideB')) {
b = (type1 === 'sideB') ? val1 : val2;
c = (type1 === 'hypotenuseC') ? val1 : val2;
if (b >= c) {
errorDiv.innerHTML = 'Side B cannot be greater than or equal to the hypotenuse.';
return;
}
a = Math.sqrt(c * c – b * b);
beta_deg = toDegrees(Math.asin(b / c));
alpha_deg = 90 – beta_deg;
solved = true;
}
// Case 2: One Side and One Angle
else if ((type1 === 'sideA' && type2 === 'angleA') || (type1 === 'angleA' && type2 === 'sideA')) {
a = (type1 === 'sideA') ? val1 : val2;
alpha_deg = (type1 === 'angleA') ? val1 : val2;
beta_deg = 90 – alpha_deg;
c = a / Math.sin(toRadians(alpha_deg));
b = c * Math.cos(toRadians(alpha_deg));
solved = true;
} else if ((type1 === 'sideA' && type2 === 'angleB') || (type1 === 'angleB' && type2 === 'sideA')) {
a = (type1 === 'sideA') ? val1 : val2;
beta_deg = (type1 === 'angleB') ? val1 : val2;
alpha_deg = 90 – beta_deg;
c = a / Math.cos(toRadians(beta_deg));
b = c * Math.sin(toRadians(beta_deg));
solved = true;
} else if ((type1 === 'sideB' && type2 === 'angleA') || (type1 === 'angleA' && type2 === 'sideB')) {
b = (type1 === 'sideB') ? val1 : val2;
alpha_deg = (type1 === 'angleA') ? val1 : val2;
beta_deg = 90 – alpha_deg;
c = b / Math.cos(toRadians(alpha_deg));
a = c * Math.sin(toRadians(alpha_deg));
solved = true;
} else if ((type1 === 'sideB' && type2 === 'angleB') || (type1 === 'angleB' && type2 === 'sideB')) {
b = (type1 === 'sideB') ? val1 : val2;
beta_deg = (type1 === 'angleB') ? val1 : val2;
alpha_deg = 90 – beta_deg;
c = b / Math.sin(toRadians(beta_deg));
a = c * Math.cos(toRadians(beta_deg));
solved = true;
} else if ((type1 === 'hypotenuseC' && type2 === 'angleA') || (type1 === 'angleA' && type2 === 'hypotenuseC')) {
c = (type1 === 'hypotenuseC') ? val1 : val2;
alpha_deg = (type1 === 'angleA') ? val1 : val2;
beta_deg = 90 – alpha_deg;
a = c * Math.sin(toRadians(alpha_deg));
b = c * Math.cos(toRadians(alpha_deg));
solved = true;
} else if ((type1 === 'hypotenuseC' && type2 === 'angleB') || (type1 === 'angleB' && type2 === 'hypotenuseC')) {
c = (type1 === 'hypotenuseC') ? val1 : val2;
beta_deg = (type1 === 'angleB') ? val1 : val2;
alpha_deg = 90 – beta_deg;
a = c * Math.cos(toRadians(beta_deg));
b = c * Math.sin(toRadians(beta_deg));
solved = true;
}
if (!solved) {
errorDiv.innerHTML = 'Invalid combination of inputs. Please provide two values that allow solving a right triangle (e.g., two sides, or one side and one acute angle).';
return;
}
// Check for impossible triangles after calculation (e.g., due to floating point errors or edge cases not caught earlier)
if (a <= 0 || b <= 0 || c <= 0 || alpha_deg <= 0 || beta_deg = 90 || beta_deg >= 90) {
errorDiv.innerHTML = 'Calculated values resulted in an impossible triangle. Please check your inputs.';
return;
}
resultDiv.innerHTML =
'
Understanding the Right-Angled Triangle Calculator
Trigonometry is a branch of mathematics that studies relationships between side lengths and angles of triangles. It's a fundamental tool in fields like engineering, physics, architecture, and even video game development. Our Right-Angled Triangle Calculator simplifies the process of solving for unknown sides and angles in these specific types of triangles.
What is a Right-Angled Triangle?
A right-angled triangle (or right triangle) is a triangle in which one angle is exactly 90 degrees (a right angle). The side opposite the right angle is called the hypotenuse, which is always the longest side. The other two sides are called legs or cathetus. When referring to an acute angle (an angle less than 90 degrees) within the triangle, the legs are further defined as:
Opposite Side: The leg across from the angle.
Adjacent Side: The leg next to the angle (not the hypotenuse).
Key Trigonometric Ratios (SOH CAH TOA)
The relationships between the angles and sides of a right triangle are defined by three primary trigonometric ratios:
These are often remembered by the mnemonic "SOH CAH TOA".
The Pythagorean Theorem
For any right-angled triangle, the square of the hypotenuse (c) is equal to the sum of the squares of the other two sides (a and b). This is known as the Pythagorean Theorem:
a² + b² = c²
This theorem is crucial for finding an unknown side when two sides are known.
How to Use the Calculator
Our calculator is designed to be intuitive. To solve a right-angled triangle, you typically need to know at least two pieces of information (excluding the 90-degree angle itself). Here's how to use it:
Identify Known Values: Look at your triangle problem and determine which sides or acute angles you already know.
Enter Two Values: Input your two known values into the corresponding fields (Side A, Side B, Hypotenuse C, Angle A, or Angle B). For example, if you know Side A and Angle A, enter those.
Click "Calculate Triangle": The calculator will then use trigonometric functions and the Pythagorean theorem to determine all the remaining unknown sides and angles.
Review Results: The results section will display the calculated values for all sides and angles, rounded to four decimal places.
Example Scenario
Imagine you have a ladder leaning against a wall. The ladder is 10 units long (this is your Hypotenuse C). The angle the ladder makes with the ground (Angle A) is 60 degrees. You want to find out how high up the wall the ladder reaches (Side A) and how far the base of the ladder is from the wall (Side B).
Input: Hypotenuse C = 10, Angle A = 60
Calculation:
Angle B = 90 – 60 = 30 degrees
Side A (Opposite Angle A) = Hypotenuse C * sin(Angle A) = 10 * sin(60°) ≈ 8.6603
Side B (Adjacent to Angle A) = Hypotenuse C * cos(Angle A) = 10 * cos(60°) = 5.0000
Output: The calculator would show Side A ≈ 8.6603, Side B = 5.0000, Hypotenuse C = 10, Angle A = 60 degrees, Angle B = 30 degrees, Angle C = 90 degrees.
This calculator is a powerful tool for students, engineers, and anyone needing to quickly solve right-angled triangle problems without manual calculations.