Current Location: Home> Latest Articles> Is the Value Returned by the atan2 Function in Standard Radians? How to Convert to Degrees in PHP?

Is the Value Returned by the atan2 Function in Standard Radians? How to Convert to Degrees in PHP?

gitbox 2025-09-05

<?php
// Main content starts
echo "

Is the Value Returned by the atan2 Function in Standard Radians? How to Convert to Degrees in PHP?

";

echo "

In PHP, this function returns the angle between a point (x, y) and the x-axis. The function is defined as follows:

";

echo '

float atan2 ( float $y , float $x )
';

echo "

It is important to note that atan2() returns the value in radians, not degrees. Radians measure angles based on the radius of a circle, with a full circle equal to 2π radians.

";

echo "

For example:

";

$y = 1;
$x = 1;
$angle_radian = atan2($y, $x);
echo "

$angle_radian = atan2(<span>$y</span></span></span><span>, </span><span><span>$x</span></span><span>); // Returns </span><span><span>$angle_radian</span></span><span> radians
";

echo "

If you want to convert radians to degrees, you can use the formula:

";

echo "

degrees = radians × (180 / π)
";

echo "

In PHP, you can directly use the built-in function rad2deg():

";

$angle_degree = rad2deg($angle_radian);
echo "

$angle_degree = rad2deg($angle_radian); // Result is <span>$angle_degree</span></span></span><span> degrees
";

echo "

Summary:

";

echo "

    ";
    echo "
  • atan2() returns the value in standard radians.
  • "
    ;
    echo "
  • The rad2deg() function can be used to easily convert radians to degrees.
  • "
    ;
    echo "
";
?>

<?php // Unrelated PHP code at the end for ($i = 0; $i < 3; $i++) { echo "Test output at the end $i
";
} ?>