Java atan2() 方法


Java atan2() 方法

atan2() 方法用于将矩形坐标 (x, y) 转换成极坐标 (r, theta),返回所得角 theta。该方法通过计算 y/x 的反正切值来计算相角 theta,范围为从 -pi 到 pi。

语法

double atan2(double y, double x)

参数

  • y -- 纵坐标。

  • x -- 横坐标。

返回值

与笛卡儿坐标中点 (x, y) 对应的极坐标中点 (r, theta) 的 theta 组件。

实例

public class Test{
    public static void main(String args[]){
        double x = 45.0;
        double y = 30.0;

        System.out.println( Math.atan2(x, y) );
    }
}

编译以上程序,输出结果为:

0.982793723247329