PHP Tutorial PHP Advanced PHP Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

PHP - Math atan2() Function



The PHP Math atan2() function returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta). The return value will be in the range -𝜋 through 𝜋.

Syntax

atan2(y, x)

Parameters

y Required. Specify the ordinate coordinate.
x Required. Specify the abscissa coordinate.

Return Value

Returns theta of the point (r, theta) in polar coordinates that corresponds to the point (x, y) in Cartesian coordinates.

Example:

In the example below, atan2() function is used to calculate the theta of a point.

<?php
echo atan2(10, 10)."\n";
echo atan2(20, 10)."\n";
echo atan2(-20, 10)."\n";  
?>

The output of the above code will be:

0.78539816339745
1.1071487177941
-1.1071487177941

❮ PHP Math Functions

5