atan() : the arc tangent (inverse tangent) of a given number

Calculate inverse tangent

atan() returns the arc tangent of a number in radians. Use atan2() when you have separate x and y components and need correct quadrant handling.

$angle = atan(1);
echo rad2deg($angle); // 45

The examples below build from the basic call to practical variations and edge cases.

<?Php
echo atan(0); // Output is 0
echo "<br>";
echo atan(1); // Output  0.78539816339745
echo "<br>";
echo atan(-1); // -0.78539816339745
echo "<br>";
echo atan(4); // Output is 1.325817663668
echo "<br>";
echo atan(2); // Output is 1.1071487177941
echo "<br>";
echo atan(90); // Output is 1.5596856728973
?>
atan(float $num): float;
The argument is a numeric ratio. atan() returns the corresponding angle in radians. Use rad2deg() when you need degrees.

Convert the returned angle to degrees

$ratio = 1;
$angleRadians = atan($ratio);
echo rad2deg($angleRadians); // 45

Example: Calculating Angle in a Triangle

$opposite = 5;
$adjacent = 10;
$angle = atan($opposite / $adjacent);  // Result in radians
$angle_in_degrees = rad2deg($angle);
echo $angle_in_degrees;  // Output: 26.565 degrees

Example: Handling Edge Cases

echo atan(0);  // Output: 0
echo atan(-1);  // Output: -0.785398163 (negative angle)

Example: Comparing atan() and atan2()

$y = 5;
$x = 10;
echo atan($y / $x);  // Output: 0.463 radians

// Using atan2 to handle full quadrant angles
echo atan2($y, $x);  // Output: 0.463 radians (same, but handles quadrant correctly)
Explanation:
Triangle Calculation: Demonstrates a practical application for calculating angles from side lengths.
Edge Case Handling: Explains what happens when input values are zero or negative.
Comparison: Clarifies when `atan()` or `atan2()` should be used for handling angles in different quadrants.

Questions

ATAN2() function
Math Functions


Subscribe to our YouTube Channel here



plus2net.com











PHP video Tutorials
✖
We use cookies to improve your browsing experience. . Learn more
HTML MySQL PHP JavaScript ASP Photoshop Articles Contact us
© 2000-2026 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer