
- PHP 7 Tutorial
- PHP 7 - Home
- PHP 7 - Introduction
- PHP 7 - Performance
- PHP 7 - Environment Setup
- PHP 7 - Scalar Type Declarations
- PHP 7 - Return Type Declarations
- PHP 7 - Null Coalescing Operator
- PHP 7 - Spaceship Operator
- PHP 7 - Constant Arrays
- PHP 7 - Anonymous Classes
- PHP 7 - Closure::call()
- PHP 7 - Filtered unserialize()
- PHP 7 - IntlChar
- PHP 7 - CSPRNG
- PHP 7 - Expectations
- PHP 7 - use Statement
- PHP 7 - Error Handling
- PHP 7 - Integer Division
- PHP 7 - Session Options
- PHP 7 - Deprecated Features
- PHP 7 - Removed Extensions & SAPIs
- PHP 7 Useful Resources
- PHP 7 - Quick Guide
- PHP 7 - Useful Resources
- PHP 7 - Discussion
PHP atan2() Function
Definition and Usage
The atan2() function calculates arc tan of two variables
atan2(y,x) returns the arc tangent of the two numbers x and y. although it is similar to atan(y)/atan(x), the signs of both x and y are used to determine the quadrant of the result. Accordingly for values of x and y atan2() is
atan(y/x) if x>0
atan(y/x)+pi if x>0
atan(y/x)-pi if x<0 and y<0
pi/2 if x=0 and y>0
-pi/2 if x=0 and y<0
0 if x=0 and y=0
This function returns angle in radians which is a float value.
Syntax
atan2 ( float $y , float $x ) : float
Parameters
Sr.No | Parameter & Description |
---|---|
1 | y dividend |
2 | x divisor |
Return Values
PHP atan2() function returns angle in radian which is a float number.
PHP Version
This function is available in PHP versions 4.x, PHP 5.x as well as PHP 7.x.
Example
Following example calculates atan2(1,2) −
<?php $y=1; $x=2; $val=atan2($y, $x);; echo "atan2(" . $y ."," . $x .") = " . $val; ?>
Output
This will produce following result −
atan2(1,2) = 0.46364760900081
Example
Following example calculate atan2(5, -5) −
<?php $y=5; $x=-5; $val=atan2($y, $x);; echo "atan2(" . $y ."," . $x .") = " . $val; ?>
Output
This will produce following result −
atan2(5,-5) = 2.3561944901923
Example
Following program computes atan2(5,0) and returns 1.570796326795 (M_PI_2) −
<?php $y=5; $x=0; $val=atan2($y, $x);; echo "atan2(" . $y ."," . $x .") = " . $val; ?>
Output
This will produce following result −
atan2(5,0) = 1.5707963267949
Example
Following example computes atan2(0,0) and returns 0
<?php $y=0; $x=0; $val=atan2($y, $x);; echo "atan2(" . $y ."," . $x .") = " . $val; ?>
Output
This will produce following result −
atan2(0,0) = 0
- Related Articles
- atan2() function in PHP
- atan2() function in C++ STL
- PHP Function arguments
- PHP abs() Function
- PHP acos() Function
- PHP acosh() Function
- PHP asin() Function
- PHP asinh() Function
- PHP atan() Function
- PHP atanh() Function
- PHP base_convert() Function
- PHP bindec() Function
- PHP ceil() Function
- PHP cos() Function
- PHP cosh() Function
