Skip to content
Related Articles
Get the best out of our app
GFG App
Open App
geeksforgeeks
Browser
Continue

Related Articles

PHP | atan2( ) Function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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:

  1. $y: This parameter specifies the dividend.
  2. $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


    My Personal Notes arrow_drop_up
Last Updated : 09 Mar, 2018
Like Article
Save Article
Similar Reads
Related Tutorials