Java Math atan2() 方法
示例
根据直角坐标,返回极坐标的角度(以弧度为单位):
System.out.println(Math.atan2(0.5, 0.5));
System.out.println(Math.atan2(-0.5, -0.5));
System.out.println(Math.atan2(5, 5));
System.out.println(Math.atan2(10, 20));
System.out.println(Math.atan2(-5, -5));
System.out.println(Math.atan2(-10, 10));
定义和用法
atan2() 方法返回由直角坐标 (x, y) 转换为极坐标 (r, theta) 得到的角度 theta(以弧度为单位)。
这与调用 atan(y/x) 相同,区别在于它考虑了 x 的负值,因此可以返回 -π/2 到 π/2 范围之外的角度。
注意: 在 atan2() 方法中,y 坐标在前,x 坐标在后。这是因为该方法执行的是 y / x 的除法运算。
语法
public static double atan2(double y, double x)
参数值
| 参数 | 描述 |
|---|---|
| y | 必需。要计算角度的点的 y 坐标。 |
| x | 必需。要计算角度的点的 x 坐标。 |
技术细节
| 返回值: | 一个 double 值,表示点 (x, y) 绕原点 (0, 0) 所成的角度(以弧度为单位)。 |
|---|---|
| Java 版本: | 任意 |
❮ Math 数学方法

