PHP atan() 和 atan2() 函数
定义和用法
函数 atan() 返回一个数值的反正切,返回值介于 -PI/2 与 PI/2 之间。
�数 atan2() 返回两个参数的反正切,返回值为弧度,其值在 -PI 和 PI 之间(包括 -PI 和 PI)。
语法
Syntaxx, atan(xatan2(y,
) | Parameter |
---|---|
x | Description |
y | Description |
Required. A number.
Description x The atan() function returns
The atan2() function calculates the arctangent value of two variables x and y The arctangent value. 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.
Example
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