Trigonometry is a branch of mathematics that studies the relationships between the sides and angles of triangles, particularly right-angled triangles. The core of trigonometry lies in its six fundamental functions: sine (sin), cosine (cos), tangent (tan), cosecant (csc), secant (sec), and cotangent (cot). These functions are defined based on the ratios of the sides of a right-angled triangle relative to one of its acute angles.
The Core Functions (for a right-angled triangle):
Sine (sin θ): The ratio of the length of the side opposite the angle to the length of the hypotenuse (Opposite / Hypotenuse).
Cosine (cos θ): The ratio of the length of the adjacent side to the angle to the length of the hypotenuse (Adjacent / Hypotenuse).
Tangent (tan θ): The ratio of the length of the side opposite the angle to the length of the adjacent side (Opposite / Adjacent). It can also be expressed as sin θ / cos θ.
Reciprocal Functions:
Cosecant (csc θ): The reciprocal of sine, 1 / sin θ.
Secant (sec θ): The reciprocal of cosine, 1 / cos θ.
Cotangent (cot θ): The reciprocal of tangent, 1 / tan θ. It can also be expressed as cos θ / sin θ.
Angles and Units:
Trigonometric functions take an angle as input. This angle can be measured in two primary units:
Degrees: A full circle is divided into 360 degrees (°).
Radians: A full circle is divided into 2π radians (rad). This unit is often preferred in calculus and higher mathematics because it simplifies many formulas. The conversion is 180° = π radians.
Use Cases of Trigonometry:
Trigonometric functions are fundamental in numerous fields, including:
Engineering: Designing structures, analyzing circuits, and in signal processing.
Navigation: Determining positions and directions using celestial bodies or GPS.
Astronomy: Calculating distances to stars and planets.
Computer Graphics: Creating animations, rendering 3D environments, and simulating movements.
Surveying: Measuring distances and elevations.
How this Calculator Works:
This calculator takes an angle value and its unit (degrees or radians) and computes the value of the selected trigonometric function (sine, cosine, tangent, cosecant, secant, or cotangent) for that angle. It handles the necessary unit conversions internally before applying the standard mathematical library functions.
Example Calculation:
Let's calculate the sine of 30 degrees.
Input Angle Value: 30
Input Angle Unit: Degrees
Select Function: Sine (sin)
The sine of 30 degrees is a well-known value, 0.5.
Another example: Calculate the tangent of π/4 radians.
function calculateTrig() {
var angleValueInput = document.getElementById("angleValue");
var angleUnitSelect = document.getElementById("angleUnit");
var functionTypeSelect = document.getElementById("functionType");
var resultDiv = document.getElementById("result");
var angleValue = parseFloat(angleValueInput.value);
var angleUnit = angleUnitSelect.value;
var functionType = functionTypeSelect.value;
// Clear previous result
resultDiv.innerHTML = "";
// Input validation
if (isNaN(angleValue)) {
resultDiv.innerHTML = "Error: Please enter a valid number for the angle value.";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
var angleInRadians = angleValue;
// Convert degrees to radians if necessary
if (angleUnit === "degrees") {
angleInRadians = angleValue * (Math.PI / 180);
}
var result = NaN;
var functionName = "";
// Calculate the trigonometric function
switch (functionType) {
case "sin":
result = Math.sin(angleInRadians);
functionName = "Sine";
break;
case "cos":
result = Math.cos(angleInRadians);
functionName = "Cosine";
break;
case "tan":
// Handle cases where tan is undefined (90 degrees, 270 degrees, etc. or pi/2, 3pi/2 radians)
// tan(pi/2 + n*pi) is undefined. Check if angleInRadians is close to these values.
var remainder = angleInRadians % Math.PI;
if (Math.abs(remainder – Math.PI / 2) < 1e-10 || Math.abs(remainder + Math.PI / 2) < 1e-10) {
resultDiv.innerHTML = "Error: Tangent is undefined for this angle.";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
result = Math.tan(angleInRadians);
functionName = "Tangent";
break;
case "csc":
var sinVal = Math.sin(angleInRadians);
if (Math.abs(sinVal) < 1e-10) { // Check if sin is close to zero
resultDiv.innerHTML = "Error: Cosecant is undefined (division by zero).";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
result = 1 / sinVal;
functionName = "Cosecant";
break;
case "sec":
var cosVal = Math.cos(angleInRadians);
if (Math.abs(cosVal) < 1e-10) { // Check if cos is close to zero
resultDiv.innerHTML = "Error: Secant is undefined (division by zero).";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
result = 1 / cosVal;
functionName = "Secant";
break;
case "cot":
var tanVal = Math.tan(angleInRadians);
// Also handle case where sin is zero (0 degrees, 180 degrees, etc.)
if (Math.abs(Math.sin(angleInRadians)) < 1e-10) {
resultDiv.innerHTML = "Error: Cotangent is undefined (division by zero).";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
if (Math.abs(tanVal) < 1e-10) { // Check if tan is close to zero
resultDiv.innerHTML = "Error: Cotangent is undefined (division by zero).";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
result = 1 / tanVal;
functionName = "Cotangent";
break;
default:
resultDiv.innerHTML = "Error: Unknown function type.";
resultDiv.style.backgroundColor = "#dc3545"; // Error red
return;
}
// Display the result
if (!isNaN(result)) {
// Format the result to a reasonable number of decimal places, or show exact for simple values
var formattedResult;
if (Math.abs(result) < 1e-10) { // Handle very small numbers close to zero
formattedResult = "0";
} else if (Math.abs(result – Math.round(result)) < 1e-10) { // Check if it's an integer
formattedResult = Math.round(result).toString();
} else {
formattedResult = result.toFixed(10); // Adjust decimal places as needed
}
resultDiv.innerHTML = "" + functionName + " (" + angleValue + " " + angleUnit + ") = " + formattedResult;
resultDiv.style.backgroundColor = "#28a745"; // Success Green
}
}