In trigonometry, the tangent of an angle in a right-angled triangle is the ratio of the length of the side opposite the angle to the length of the adjacent side. It is one of the three fundamental trigonometric functions, along with sine and cosine.
The Tangent Formula
tan(θ) = Opposite / Adjacent
Alternatively, in terms of sine and cosine, the formula is:
tan(θ) = sin(θ) / cos(θ)
How to Use the Tangent Calculator
Enter the Angle: Type the numerical value of the angle you wish to calculate.
Select the Unit: Choose whether your input is in Degrees or Radians. Note: 180° is equal to π radians.
Calculate: Press the button to view the result.
Important Values to Know
Angle (Degrees)
Angle (Radians)
tan(θ)
0°
0
0
30°
π/6
0.577
45°
π/4
1
60°
π/3
1.732
90°
π/2
Undefined
Real-World Applications
The tangent function is widely used in various fields including:
Architecture & Engineering: Calculating the slope (grade) of a roof or a road. Slope is effectively the tangent of the angle of inclination.
Navigation: Determining distances to landmarks by measuring angles from a known position.
Physics: Analyzing forces on inclined planes and resolving vectors into components.
Example Calculation
Suppose you are standing 10 meters away from a tree, and the angle of elevation to the top of the tree is 35°. How tall is the tree?
Using the tangent formula: tan(35°) = height / 10m. Therefore, height = 10 * tan(35°). Since tan(35°) ≈ 0.7002, the height is approximately 7.002 meters.
function calculateTangent() {
var angleVal = document.getElementById("angleInput").value;
var unit = document.getElementById("unitType").value;
var resultDiv = document.getElementById("resultDisplay");
var valDisplay = document.getElementById("tanValue");
var formulaDisplay = document.getElementById("tanFormula");
if (angleVal === "") {
alert("Please enter a valid angle.");
return;
}
var angle = parseFloat(angleVal);
var radians;
if (unit === "degrees") {
// Check for undefined cases (90, 270, etc)
// Using modulo to handle angles > 360
var normalizedAngle = Math.abs(angle % 180);
if (normalizedAngle === 90) {
valDisplay.innerText = "tan(" + angle + "°) = Undefined";
formulaDisplay.innerText = "The tangent function is undefined at 90°, 270°, and every 180° interval thereafter.";
resultDiv.style.display = "block";
return;
}
radians = angle * (Math.PI / 180);
} else {
// For radians, tangent is undefined at PI/2 + n*PI
var normalizedRad = Math.abs(angle % Math.PI);
if (Math.abs(normalizedRad – (Math.PI / 2)) < 0.0000000001) {
valDisplay.innerText = "tan(" + angle + " rad) = Undefined";
formulaDisplay.innerText = "The tangent function is undefined at π/2, 3π/2, etc.";
resultDiv.style.display = "block";
return;
}
radians = angle;
}
var tanResult = Math.tan(radians);
// Cleanup floating point errors for clean numbers
if (Math.abs(tanResult) < 1e-10) tanResult = 0;
var displayResult = Number.isInteger(tanResult) ? tanResult : tanResult.toFixed(6);
valDisplay.innerText = "tan(" + angle + (unit === "degrees" ? "°" : " rad") + ") = " + displayResult;
if (unit === "degrees") {
formulaDisplay.innerText = "Calculation: tan(" + angle + " * π / 180)";
} else {
formulaDisplay.innerText = "Calculation: tan(" + angle + " radians)";
}
resultDiv.style.display = "block";
}