Trigonometry is a branch of mathematics that studies relationships between side lengths and angles of triangles. The three primary functions—Sine (sin), Cosine (cos), and Tangent (tan)—are the fundamental building blocks of this field.
The Core Functions Defined
Sine (sin): In a right-angled triangle, the sine of an angle is the ratio of the length of the opposite side to the length of the hypotenuse.
Cosine (cos): The cosine of an angle is the ratio of the length of the adjacent side to the length of the hypotenuse.
Tangent (tan): The tangent is the ratio of the opposite side to the adjacent side (or simply sin/cos).
Degrees vs. Radians
While we often use degrees in daily life (where a full circle is 360°), mathematics and physics frequently use radians. One full circle is 2π radians. To convert degrees to radians, multiply the degree value by π/180.
Practical Examples
Angle (Deg)
Sin
Cos
Tan
0°
0
1
0
30°
0.5
0.866
0.577
45°
0.707
0.707
1
90°
1
0
Undefined
function calculateTrig(func) {
var val = document.getElementById('angleInput').value;
var unit = document.querySelector('input[name="unitType"]:checked').value;
var outputDiv = document.getElementById('trigOutput');
var formulaDiv = document.getElementById('trigFormula');
var resultBox = document.getElementById('resultBox');
if (val === "") {
alert("Please enter an angle value.");
return;
}
var angle = parseFloat(val);
var originalAngle = angle;
// Convert to Radians if necessary for JS Math functions
var rad;
if (unit === 'degrees') {
rad = angle * (Math.PI / 180);
} else {
rad = angle;
}
var result;
var label;
if (func === 'sin') {
result = Math.sin(rad);
label = "sin(" + originalAngle + (unit === 'degrees' ? "°" : " rad") + ")";
} else if (func === 'cos') {
result = Math.cos(rad);
label = "cos(" + originalAngle + (unit === 'degrees' ? "°" : " rad") + ")";
} else if (func === 'tan') {
// Handle tangent asymptotes
if (unit === 'degrees' && (Math.abs(angle % 180) === 90)) {
result = "Undefined";
} else if (unit === 'radians' && (Math.abs((angle / Math.PI) % 1) === 0.5)) {
result = "Undefined";
} else {
result = Math.tan(rad);
}
label = "tan(" + originalAngle + (unit === 'degrees' ? "°" : " rad") + ")";
}
resultBox.style.display = "block";
if (result === "Undefined") {
outputDiv.innerHTML = "Undefined";
formulaDiv.innerHTML = "The tangent function is undefined at vertical asymptotes.";
} else {
// Rounding to fix floating point precision (e.g., sin(180) should be 0)
var roundedResult = Number(result.toFixed(10));
outputDiv.innerHTML = roundedResult;
formulaDiv.innerHTML = "Calculation: " + label + " ≈ " + result.toFixed(6);
}
}