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 的负值,因此可以返回超出 -PI/2 到 PI/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 方法