Groovy - atan2()



該方法將直角座標 (x, y) 轉換為極座標 (r, theta),並返回 theta。

語法

double atan2(double y, double x)

引數

  • X - 用 double 資料型別表示的 x 座標
  • Y - 用 double 資料型別表示的 y 座標

返回值

此方法返回極座標 (r, theta) 中的 theta。

示例

以下是此方法用法的一個示例 −

class Example {     
   static void main(String[] args){
      double x = 45.0;
      double y = 30.0;
		
      System.out.println( Math.atan2(x, y) );
   } 
}

執行上述程式後,我們將獲得以下結果 −

0.982793723247329
groovy_numbers.htm
廣告
© . All rights reserved.