Trigonometry is a fundamental branch of mathematics that studies the relationships between angles and sides of triangles. The three primary trigonometric functions – sine (sin), cosine (cos), and tangent (tan) – are essential tools for analyzing these relationships, particularly in right-angled triangles, and have widespread applications in physics, engineering, computer graphics, and many other fields.
Sine (sin)
In a right-angled triangle, the sine of an angle is defined as the ratio of the length of the side opposite the angle to the length of the hypotenuse (the longest side). Mathematically:
sin(θ) = Opposite / Hypotenuse
On the unit circle, the sine of an angle represents the y-coordinate of the point where the terminal side of the angle intersects the circle.
Cosine (cos)
The cosine of an angle in a right-angled triangle is defined as the ratio of the length of the adjacent side (the side next to the angle, not the hypotenuse) to the length of the hypotenuse.
cos(θ) = Adjacent / Hypotenuse
On the unit circle, the cosine of an angle represents the x-coordinate of the point where the terminal side of the angle intersects the circle.
Tangent (tan)
The tangent of an angle in a right-angled triangle is defined as the ratio of the length of the opposite side to the length of the adjacent side.
tan(θ) = Opposite / Adjacent
It can also be expressed as the ratio of sine to cosine: tan(θ) = sin(θ) / cos(θ). The tangent function is undefined when the cosine is zero (e.g., at 90° or π/2 radians).
Units: Degrees vs. Radians
Trigonometric functions can accept angles measured in either degrees or radians.
Degrees (°): A full circle is 360°.
Radians: A full circle is 2π radians. One radian is the angle subtended at the center of a circle by an arc whose length is equal to the radius. The conversion is: 180° = π radians.
This calculator allows you to specify the unit of your input angle. Ensure you select the correct unit for accurate results. Remember that JavaScript's built-in Math.sin(), Math.cos(), and Math.tan() functions expect angles in radians. The calculator handles the conversion if you input degrees.
Common Use Cases
Physics: Analyzing projectile motion, wave phenomena (sound, light), oscillations, and AC circuits.
Engineering: Calculating forces in structures, designing bridges and buildings, signal processing.
Navigation: Determining positions and bearings using celestial bodies or GPS.
Computer Graphics: Rotating objects, creating animations, and rendering 3D environments.
Surveying: Measuring distances and heights indirectly.
How to Use This Calculator
Enter the numerical value of the angle in the Angle Value field.
Select the correct unit (Degrees or Radians) from the dropdown menu.
Click the Calculate button.
The results for sine, cosine, and tangent will be displayed below.
Use the Clear button to reset the fields.
function calculateTrig() {
var angleValue = document.getElementById("angleValue").value;
var angleUnit = document.getElementById("angleUnit").value;
var resultDiv = document.getElementById("result");
resultDiv.innerHTML = "; // Clear previous results
// Validate input
if (angleValue === "" || isNaN(angleValue)) {
resultDiv.innerHTML = "Please enter a valid number for the angle.";
return;
}
var angle = parseFloat(angleValue);
var sinValue, cosValue, tanValue;
// Convert to radians if input is in degrees
if (angleUnit === "degrees") {
angle = angle * (Math.PI / 180);
}
// Calculate trigonometric values
sinValue = Math.sin(angle);
cosValue = Math.cos(angle);
tanValue = Math.tan(angle);
// Handle potential -0 values
if (sinValue === -0) sinValue = 0;
if (cosValue === -0) cosValue = 0;
if (tanValue === -0) tanValue = 0;
// Check for undefined tangent (e.g., at 90 degrees, 270 degrees, etc.)
// cosValue will be very close to 0 for these angles
var epsilon = 1e-10; // A small tolerance for floating point comparisons
if (Math.abs(cosValue) < epsilon) {
tanValue = "Undefined (approaches infinity)";
} else {
tanValue = Math.tan(angle); // Recalculate for precision if not undefined
if (tanValue === -0) tanValue = 0;
}
// Format results to a reasonable number of decimal places
var formattedSin = sinValue.toFixed(6);
var formattedCos = cosValue.toFixed(6);
var formattedTan = typeof tanValue === 'number' ? tanValue.toFixed(6) : tanValue;
// Display results
resultDiv.innerHTML =
`Sine (sin): ${formattedSin}
Cosine (cos): ${formattedCos}
Tangent (tan): ${formattedTan}`;
}
function clearFields() {
document.getElementById("angleValue").value = "";
document.getElementById("angleUnit").value = "degrees";
document.getElementById("result").innerHTML = "";
}