PHP atan() and atan2() Functions
Definition and Usage
The atan() function returns the arctangent of a single number, with the returned value between -PI/2 and PI/2.
The atan2() function returns the arctangent of two parameters, with the returned value in radians, ranging from -PI to PI (inclusive).
Syntax
atan(x) atan2(x,y)
Parameter | Description |
---|---|
x | Required. A number. |
y | Required. A number. |
Description
The atan() function returns x arctangent value, in radians. atan() is the inverse function of tan(), which means that each value within the range of atan() is a == tan(atan(a)).
The atan2() function calculates the arctangent value of two variables x and y arctangent values. Similar to calculating the arctangent of y / x, the difference is that the signs of the two parameters are used to determine the quadrant of the result.
Instance
Example 1
This example calculates the arctangent of different values:
<?php echo(atan(0.50)); echo(atan(-0.50)); echo(atan(5)); echo(atan(10)); echo(atan(-5)); echo(atan(-10)) ?>
Output:
0.463647609001 -0.463647609001 1.37340076695 1.4711276743 -1.37340076695 -1.4711276743
Example 2
This example calculates the arctangent values of different variables x and y:
<?php echo(atan2(0.50,0.50)); echo(atan2(-0.50,-0.50)); echo(atan2(5,5)); echo(atan2(10,20)); echo(atan2(-5,-5)); echo(atan2(-10,10)) ?>
Output:
0.785398163397 -2.35619449019 0.785398163397 0.463647609001 -2.35619449019 -0.785398163397