Latest web development tutorials

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類