當前位置: 首頁>>編程示例 >>用法及示例精選 >>正文


Java java.lang.Math.atan2()用法及代碼示例


atan2()是Java中的內置方法,用於從極坐標返回theta分量。 atan2()方法返回介於–\pi\pi代表角度\theta(x,y)點和正x軸的角度。它是X軸正方向與點(x,y)之間的逆時針角度(以弧度為單位)。

用法:

Math.atan2(double y, double x)
where, x and y are X and Y coordinates in double data type.

返回值:
它返回一個雙精度值。雙精度值是\theta來自極坐標(r,theta)。


例:程序演示atan2()方法

// Java program for implementation of 
// atan2() method 
import java.util.*; 
class GFG { 
  
    // Driver Code 
    public static void main(String args[]) 
    { 
  
        // X and Y coordinates 
        double x = 90.0; 
        double y = 15.0; 
  
        // theta value from polar coordinate (r, theta) 
        double theta = Math.atan2(x, y); 
  
        System.out.println(theta); 
    } 
}

輸出:

1.4056476493802699


相關用法


注:本文由純淨天空篩選整理自Striver大神的英文原創作品 java.lang.Math.atan2() in Java。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。