Tangent Calculator

Tangent Calculator

The tangent function, often abbreviated as tan, is one of the fundamental trigonometric functions. In a right-angled triangle, the tangent of an angle is defined as the ratio of the length of the side opposite the angle to the length of the side adjacent to the angle. This can be remembered as SOH CAH TOA, where TOA stands for Tangent = Opposite / Adjacent.

Mathematically, for an angle θ in a right triangle:

tan(θ) = Opposite / Adjacent

The tangent function is periodic with a period of π (180 degrees) and has vertical asymptotes where the cosine of the angle is zero (i.e., at ±π/2, ±3π/2, etc., or ±90°, ±270°, etc.). At these points, the tangent is undefined.

Beyond right triangles, the tangent function can be defined for any angle using the unit circle. If a point (x, y) is on the unit circle corresponding to an angle θ measured counterclockwise from the positive x-axis, then tan(θ) = y / x. This definition extends the tangent to all real numbers except for the angles where x (the cosine value) is zero.

This calculator allows you to find the tangent of an angle, whether you input it in degrees or radians.

Degrees Radians

Result:

Enter an angle and click 'Calculate'.

Examples of Tangent Values:

  • tan(0°) = 0
  • tan(30°) ≈ 0.577
  • tan(45°) = 1
  • tan(60°) ≈ 1.732
  • tan(90°) is undefined
  • tan(180°) = 0
  • tan(π/4 radians) = 1
  • tan(π/2 radians) is undefined
.tangent-calculator-container { font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif; max-width: 600px; margin: 20px auto; padding: 25px; border: 1px solid #e0e0e0; border-radius: 10px; background-color: #f9f9f9; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08); } .tangent-calculator-container h2, .tangent-calculator-container h3 { color: #333; text-align: center; margin-bottom: 20px; } .tangent-calculator-container p { color: #555; line-height: 1.6; margin-bottom: 15px; } .tangent-calculator-container code { background-color: #eef; padding: 2px 5px; border-radius: 4px; font-family: 'Courier New', Courier, monospace; color: #c7254e; } .calculator-form { background-color: #ffffff; padding: 20px; border-radius: 8px; border: 1px solid #e0e0e0; margin-top: 25px; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05); } .calculator-form label { display: block; margin-bottom: 8px; color: #333; font-weight: bold; } .calculator-form input[type="number"], .calculator-form select { width: calc(100% – 22px); padding: 10px; margin-bottom: 15px; border: 1px solid #ccc; border-radius: 5px; font-size: 16px; } .calculator-form button { background-color: #007bff; color: white; padding: 12px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 17px; width: 100%; transition: background-color 0.3s ease; } .calculator-form button:hover { background-color: #0056b3; } .result-area { margin-top: 20px; padding: 15px; background-color: #e9f7ef; border: 1px solid #d4edda; border-radius: 8px; text-align: center; } .result-area h3 { color: #28a745; margin-top: 0; margin-bottom: 10px; } .result-area p { font-size: 1.2em; color: #333; font-weight: bold; margin: 0; } .tangent-calculator-container ul { list-style-type: disc; margin-left: 20px; padding-left: 0; color: #555; } .tangent-calculator-container ul li { margin-bottom: 5px; } function calculateTangent() { var angleInput = document.getElementById("angleInput").value; var angleUnit = document.getElementById("angleUnit").value; var resultElement = document.getElementById("tangentResult"); var angle = parseFloat(angleInput); if (isNaN(angle)) { resultElement.innerHTML = "Please enter a valid number for the angle."; return; } var angleInRadians; if (angleUnit === "degrees") { // Convert degrees to radians angleInRadians = angle * (Math.PI / 180); } else { // Already in radians angleInRadians = angle; } // Check for angles where tangent is undefined (e.g., 90, 270 degrees or pi/2, 3pi/2 radians) // We need to be careful with floating point comparisons. // A common way to check for "close to" is to use a small epsilon. var normalizedAngle = angleInRadians % Math.PI; // Normalize to [0, PI) if (normalizedAngle < 0) { normalizedAngle += Math.PI; } var epsilon = 1e-9; // A small number for floating point comparison // Check if angle is close to pi/2 or 3pi/2 (or -pi/2, etc.) // These are angles where cos(angle) is 0, making tan undefined. // For example, pi/2, 3pi/2, 5pi/2, etc. // Or -pi/2, -3pi/2, etc. // This means angleInRadians / (Math.PI / 2) is an odd integer. var multipleOfHalfPi = angleInRadians / (Math.PI / 2); // Check if multipleOfHalfPi is an odd integer (e.g., 1, 3, 5, -1, -3, …) // We check if it's close to an odd integer. if (Math.abs(multipleOfHalfPi – Math.round(multipleOfHalfPi)) < epsilon && Math.round(multipleOfHalfPi) % 2 !== 0) { resultElement.innerHTML = "Tangent is undefined for " + angle + " " + angleUnit + "."; return; } var tangentValue = Math.tan(angleInRadians); // Handle very small numbers that might appear as -0 due to floating point arithmetic if (Math.abs(tangentValue) < epsilon) { tangentValue = 0; } resultElement.innerHTML = "tan(" + angle + " " + angleUnit + ") = " + tangentValue.toFixed(8); }

Leave a Reply

Your email address will not be published. Required fields are marked *