Java atan2() 方法

Java Number類Java Number類


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

Java Number類Java Number類