tan() expects the angle in radians and returns its tangent. Values close to angles where tangent is undefined can become extremely large because of floating-point approximation.
$angle = deg2rad(45);
echo tan($angle); // approximately 1
float tan(float $num)
$num is the angle in radians. The return value is its tangent.
<?Php
echo tan(M_PI); // Output is 0
echo "<br>";
echo tan(M_PI / 2); // Very large finite value due to floating-point approximation
echo "<br>";
echo round(tan(M_PI / 3), 2); // Output is 1.73
echo "<br>";
echo tan(M_PI / 4); // Output is 1
?>
<?Php
echo tan(deg2rad(0)); // Output is 0
echo "<br>";
echo tan(deg2rad(90)); // Very large finite value because 90° is represented approximately
echo "<br>";
echo tan(deg2rad(180)); // Tiny floating-point approximation of 0
?>
$angle = 90;
echo tan(deg2rad($angle)); // Very large finite value; tangent is mathematically undefined at 90°
$angle = 45;
$adjacent = 10;
$opposite = $adjacent * tan(deg2rad($angle)); // Output: 10 (Height of the triangle)
echo $opposite;
$angle = 30;
echo tan(deg2rad($angle)); // Output: 0.57735026918963
$angle = -45;
echo tan(deg2rad($angle)); // Output: -1
$angle = 30; // Angle of elevation
$distance = 100; // Distance from object
$height = $distance * tan(deg2rad($angle)); // Calculate height
echo $height; // Output: 57.735026918963
Plotting sine curves by using PHP GD function with deg2rad()
Author & Instructor at plus2net
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery, and web development at plus2net. The tutorials focus on clear explanations, working examples, and code that readers can test and adapt while learning.