java.lang.StrictMath.atan2()方法實例
java.lang.StrictMath.atan2() 方法通過計算-pi的y/xin 範圍內的圓弧相切的圓周率計算theta。它返回從直角座標(x, y)爲極座標 (r, theta) 轉化率的角度2θ。
聲明
以下是**java.lang.StrictMath.atan2()**方法的聲明
public static double atan2(double y, double x)
參數
y -- 這是縱座標。
x -- 這是橫軸座標。
返回值
此方法返回對應於直角座標的點(x,y)到點(r, theta)在極座標系中的θ組成部分。
異常
- NA
例子
下面的例子顯示java.lang.StrictMath.atan2()方法的使用。
package com.yiibai; import java.lang.*; public class StrictMathDemo { public static void main(String[] args) { double d1 = 0.6 , d2 = 90.00; /* returns the theta component of the point (r, theta) in
polar coordinates that corresponds to the point (x, y)
in Cartesian coordinates */ double dAbsValue = StrictMath.atan2(d1, d2); System.out.println("arc tangent value after conversion = " + dAbsValue); dAbsValue = StrictMath.atan2(d2 , d1); System.out.println("arc tangent value after conversion = " + dAbsValue); } }
讓我們來編譯和運行上面的程序,這將產生以下結果:
arc tangent value after conversion = 0.0066665679038682285 arc tangent value after conversion = 1.5641297588910283