The tangent function, often denoted as tan(θ), is a fundamental trigonometric function that relates an angle in a right-angled triangle to the ratio of the lengths of its sides. Specifically, in a right-angled triangle, the tangent of an angle is defined as the length of the side opposite the angle divided by the length of the adjacent side.
tan(θ) = Opposite / Adjacent
Beyond right-angled triangles, the tangent function is defined for all angles using the unit circle. For an angle θ in standard position, if the terminal side intersects the unit circle at point (x, y), then tan(θ) = y / x, provided x ≠ 0. This means the tangent function is undefined at angles where the terminal side lies on the y-axis (e.g., 90°, 270°, -90°, etc., or π/2, 3π/2, -π/2 radians).
Key Properties and Uses:
Periodicity: The tangent function has a period of π radians (or 180°). This means tan(θ + nπ) = tan(θ) for any integer n.
Symmetry: The tangent function is an odd function, meaning tan(-θ) = -tan(θ).
Asymptotes: The graph of y = tan(x) has vertical asymptotes at x = π/2 + nπ (or x = 90° + n*180°) for any integer n, where the function approaches positive or negative infinity.
Applications: Tangent calculations are crucial in various fields:
Navigation: Determining distances and bearings.
Surveying: Calculating heights of objects and distances across inaccessible terrain.
Physics: Analyzing projectile motion, wave phenomena, and electrical circuits.
Engineering: Designing structures, slopes, and analyzing forces.
Computer Graphics: Projecting 3D objects onto a 2D screen.
How this Calculator Works:
This calculator takes an angle input and its unit (degrees or radians). It then computes the tangent of that angle.
If the unit is degrees, the input angle is first converted to radians using the formula: radians = degrees * (π / 180).
If the unit is radians, the input is used directly.
The JavaScript's built-in Math.tan() function is then used to find the tangent value of the angle in radians. The result is displayed. Be aware that for angles where the tangent is mathematically undefined (like 90° or 270°), the calculator might return a very large number or an error due to floating-point limitations, reflecting the asymptotic behavior.
function calculateTangent() {
var angleValue = parseFloat(document.getElementById("angleValue").value);
var angleUnit = document.getElementById("angleUnit").value;
var resultElement = document.getElementById("result").querySelector("span");
if (isNaN(angleValue)) {
resultElement.textContent = "Invalid input";
return;
}
var angleInRadians;
if (angleUnit === "degrees") {
// Convert degrees to radians
angleInRadians = angleValue * (Math.PI / 180);
} else {
// Angle is already in radians
angleInRadians = angleValue;
}
// Handle specific undefined points for better display if possible
// Due to floating point precision, exact checks can be tricky.
// We check if the angle is very close to k*PI + PI/2 for integers k.
var PI_OVER_2 = Math.PI / 2;
var tolerance = 1e-9; // Small tolerance for floating point comparisons
// Check if angleInRadians is close to PI/2, 3PI/2, -PI/2, etc.
// Normalize angle to be within [0, 2*PI) or similar range for easier checking
var normalizedAngle = angleInRadians % (2 * Math.PI);
if (normalizedAngle < 0) {
normalizedAngle += 2 * Math.PI;
}
var isUndefined = false;
if (Math.abs(normalizedAngle – PI_OVER_2) < tolerance ||
Math.abs(normalizedAngle – (3 * PI_OVER_2)) < tolerance) {
isUndefined = true;
}
// Also check negative counterparts or angles outside [0, 2*PI) if they weren't normalized perfectly
// Example: -PI/2, -3PI/2 etc. The % operator can behave differently with negative numbers in some languages,
// but here, the normalization above should handle it. Double-checking general form k*PI + PI/2
var checkVal = angleInRadians / Math.PI;
if (Math.abs((checkVal – 0.5) % 2) < tolerance || Math.abs((checkVal + 0.5) % 2) < tolerance) {
isUndefined = true;
}
if (isUndefined) {
resultElement.textContent = "Undefined";
} else {
var tangentValue = Math.tan(angleInRadians);
resultElement.textContent = tangentValue.toFixed(10); // Display with reasonable precision
}
}