English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
Java Math Mathematical Methods
Java Math atan2O método converte as coordenadas cartesianas (x, y) em coordenadas polares (r, θ) e retorna o ângulo theta (θ).
: The coordinates x and y represent a point in the two-dimensional plane.2A sintaxe do método é:
Math.atan2(double y, double x)
Right-angled coordinates x and yatan2O método estático. Portanto, podemos chamar diretamente o método usando o nome da classe Math.
x / y-直角坐标x和y
Right-angled coordinates x and yNote
By returning the value of coordinates(x,y)Convert to coordinates(r, θ)Return angle θ
class Main { public static void main(String[] args) { //two coordinates x and y double x = 3.7; double y = 6.45; //Get angle θ double theta = Math.atan2(y, x); System.out.println(theta); // 1.0499821573815171 //Convert to degrees System.out.println(Math.toDegrees(theta)); // 60.15954618200191 } }
Here, atan2The () method converts coordinates(x,y) conversionFor coordinates(r, θ)and return the angle theta (θ).
We have usedMath.toDegrees()The method converts an angle to angle θ.