atan2()
方法的语法是
Math.atan2(double y, double x)
这里,atan2()
是一个静态方法。因此,我们使用类名 Math
来访问该方法。
atan2() 参数
atan2()
方法接受两个参数。
- x/y - 笛卡尔坐标 x 和 y
注意:坐标 x 和 y 表示二维平面中的一个点。
atan2() 返回值
- 通过将坐标 (x, y) 转换为坐标 (r, θ) 来返回角度 θ
示例:Java Math.atan2()
class Main {
public static void main(String[] args) {
// two coordinates x and y
double x = 3.7;
double y = 6.45;
// get angle θ
double theta = Math.atan2(y, x);
System.out.println(theta); // 1.0499821573815171
// convert into the degree
System.out.println(Math.toDegrees(theta)); // 60.15954618200191
}
}
这里,atan2()
方法将坐标 (x, y) 转换为坐标 (r, θ) 并返回角度 theta (θ)。
我们使用了 Math.toDegrees() 方法将角度 θ
转换为度数。
另请阅读