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.