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.
$ratio = 1;
$angleRadians = atan($ratio);
echo rad2deg($angleRadians); // 45
$opposite = 5;
$adjacent = 10;
$angle = atan($opposite / $adjacent); // Result in radians
$angle_in_degrees = rad2deg($angle);
echo $angle_in_degrees; // Output: 26.565 degrees
echo atan(0); // Output: 0
echo atan(-1); // Output: -0.785398163 (negative angle)
$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: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.