PHP | atan2( ) Function
The atan2() function is a builtin function in PHP and is used to calculate the arc tangent of two variables x and y passed to it as arguments.
The function returns the result in radians, which is between -Pi and Pi (inclusive).
Syntax:
float atan2($y, $x)
Parameters: This function accepts two parameters and are described below:
- $y: This parameter specifies the dividend.
- $x: This parameter specifies the divisor.
Return Value: It returns a float value which is the arc tangent of y/x in radians.
Examples:
Input : atan2(0.50, 0.50) Output : 0.78539816339745 Input : atan2(-0.50, -0.50) Output : -2.3561944901923 Input : atan2(5, 5) Output : 0.78539816339745 Input : atan2(10, 20) Output : 0.46364760900081
Below programs, taking different values of the parameters are used to illustrate the atan2() function in PHP:
- When (0.50, 0.50) is passed as a parameter:
<?php
echo
(
atan2
(0.50, 0.50));
?>
Output:
0.78539816339745
-
When (-0.50, -0.50) is passed as a parameter:
<?php
echo
(
atan2
(-0.50, -0.50));
?>
Output:
-2.3561944901923
- When (5, 5) is passed as a parameter:
<?php
echo
(
atan2
(5, 5));
?>
Output:
0.78539816339745
- When (10, 20) is passed as a parameter:
<?php
echo
(
atan2
(10, 20));
?>
Output:
0.46364760900081
Reference:
http://php.net/manual/en/function.atan2.php
Please Login to comment...